Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Np 351 adding gcode header to emscription #2136

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading