From 18cf5865400198006a6650d2f6d9f3fbb56f865f Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 21 Aug 2024 14:30:01 +0200 Subject: [PATCH] Add GCode prefix handling in Emscripten communication NP-351 --- include/communication/EmscriptenCommunication.h | 6 ++++++ src/communication/CommandLine.cpp | 2 +- src/communication/EmscriptenCommunication.cpp | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/communication/EmscriptenCommunication.h b/include/communication/EmscriptenCommunication.h index fc2a6897df..b93dafb50d 100644 --- a/include/communication/EmscriptenCommunication.h +++ b/include/communication/EmscriptenCommunication.h @@ -21,6 +21,7 @@ class EmscriptenCommunication : public CommandLine { private: std::string progress_handler_; ///< Handler for progress messages. + std::string gcode_prefix_handler_; /// & { 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