Skip to content

Commit

Permalink
Add GCode prefix handling in Emscripten communication
Browse files Browse the repository at this point in the history
NP-351
  • Loading branch information
saumyaj3 committed Aug 21, 2024
1 parent 6697713 commit 18cf586
Show file tree
Hide file tree
Showing 3 changed files with 15 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
8 changes: 8 additions & 0 deletions src/communication/EmscriptenCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ 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 18cf586

Please sign in to comment.