Skip to content

Commit

Permalink
Np 351 adding gcode header to emscription (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jellespijker authored Aug 21, 2024
2 parents 6697713 + 77db867 commit 2a6b939
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/communication/EmscriptenCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EmscriptenCommunication : public CommandLine
{
private:
std::string progress_handler_; ///< Handler for progress messages.
std::string gcode_prefix_handler_; /// <Handler for getting gcode_prefix.
std::string slice_info_handler_; ///< Handler for slice information messages.

/**
Expand All @@ -42,6 +43,11 @@ class EmscriptenCommunication : public CommandLine
*/
void sendProgress(double progress) const override;

/**
* \brief Sends GcodeHeader
*/
void sendGCodePrefix(const std::string& prefix) const override;

/**
* \brief Initiates the slicing of the next item.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/communication/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void CommandLine::sliceNext()
force_read_nondefault = false;
}
#ifdef __EMSCRIPTEN__
else if (argument.starts_with("--progress_cb") || argument.starts_with("--slice_info_cb"))
else if (argument.starts_with("--progress_cb") || argument.starts_with("--slice_info_cb") || argument.starts_with("--gcode_prefix_cb"))
{
argument_index++;
argument = arguments_[argument_index];
Expand Down
9 changes: 9 additions & 0 deletions src/communication/EmscriptenCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ EmscriptenCommunication::EmscriptenCommunication(const std::vector<std::string>&
{
slice_info_handler_ = *ranges::next(slice_info_flag);
}
if (auto gcode_prefix_flag = ranges::find(arguments_, "--gcode_prefix_cb"); gcode_prefix_flag != arguments_.end())
{
gcode_prefix_handler_ = *ranges::next(gcode_prefix_flag);
}
}

void EmscriptenCommunication::sendGCodePrefix(const std::string& prefix) const
{
emscripten_run_script(fmt::format("globalThis[\"{}\"]({})", gcode_prefix_handler_, prefix).c_str());
}

void EmscriptenCommunication::sendProgress(double progress) const
Expand Down

0 comments on commit 2a6b939

Please sign in to comment.