diff --git a/grbl_machine.cpp b/grbl_machine.cpp index 36cc674..4c39677 100644 --- a/grbl_machine.cpp +++ b/grbl_machine.cpp @@ -155,6 +155,85 @@ std::string grbl::alarm_to_string(int alarm) { } } +std::string grbl::error_to_string(size_t error) { + switch (error) { + case 1: + return "G-code words consist of a letter and a value. Letter was not found."; + case 2: + return "Missing the expected G-code word value or numeric value format is not valid."; + case 3: + return "Grbl '$' system command was not recognized or supported."; + case 4: + return "Negative value received for an expected positive value."; + case 5: + return "Homing cycle failure. Homing is not enabled via settings."; + case 6: + return "Minimum step pulse time must be greater than 3usec."; + case 7: + return "An EEPROM read failed. Auto-restoring affected EEPROM to default values."; + case 8: + return "Grbl '$' command cannot be used unless Grbl is IDLE. Ensures smooth operation during a job."; + case 9: + return "G-code commands are locked out during alarm or jog state."; + case 10: + return "Soft limits cannot be enabled without homing also enabled."; + case 11: + return "Max characters per line exceeded. Received command line was not executed."; + case 12: + return "Grbl '$' setting value cause the step rate to exceed the maximum supported."; + case 13: + return "Safety door detected as opened and door state initiated."; + case 14: + return "Build info or startup line exceeded EEPROM line length limit. Line not stored."; + case 15: + return "Jog target exceeds machine travel. Jog command has been ignored."; + case 16: + return "Jog command has no '=' or contains prohibited g-code."; + case 17: + return "Laser mode requires PWM output."; + case 20: + return "Unsupported or invalid g-code command found in block."; + case 21: + return "More than one g-code command from same modal group found in block."; + case 22: + return "Feed rate has not yet been set or is undefined."; + case 23: + return "G-code command in block requires an integer value."; + case 24: + return "More than one g-code command that requires axis words found in block."; + case 25: + return "Repeated g-code word found in block."; + case 26: + return "No axis words found in block for g-code command or current modal state which requires them."; + case 27: + return "Line number value is invalid."; + case 28: + return "G-code command is missing a required value word."; + case 29: + return "G59.x work coordinate systems are not supported."; + case 30: + return "G53 only allowed with G0 and G1 motion modes."; + case 31: + return "Axis words found in block when no command or current modal state uses them."; + case 32: + return "G2 and G3 arcs require at least one in-plane axis word."; + case 33: + return "Motion command target is invalid."; + case 34: + return "Arc radius value is invalid."; + case 35: + return "G2 and G3 arcs require at least one in-plane offset word."; + case 36: + return "Unused value words found in block."; + case 37: + return "G43.1 dynamic tool length offset is not assigned to configured tool length axis."; + case 38: + return "Tool number greater than max supported value."; + default: + return "unknown error"; + } +} + void grbl::machine::on_line_received(std::string line, grbl::transport *transport) { if (line.at(0) != '<') std::cout << ">> " << line << std::endl; @@ -275,8 +354,8 @@ void grbl::machine::cancel_jog() const { pipe->send_single_char_command(0x85); } -void grbl::machine::set_listener(grbl::machine_listener *listener) { - machine::listener = listener; +void grbl::machine::set_listener(grbl::machine_listener *l) { + listener = l; } void grbl::machine::request_unlock() { diff --git a/grbl_machine.h b/grbl_machine.h index 9480e72..d7bf766 100644 --- a/grbl_machine.h +++ b/grbl_machine.h @@ -22,6 +22,7 @@ enum class machine_status { machine_status status_from_string(const std::string& status); std::string status_to_string(const machine_status& status); std::string alarm_to_string(int alarm); +std::string error_to_string(size_t error); struct realtime_status_report { machine_status status; @@ -104,8 +105,8 @@ struct machine_listener { virtual void on_banner(std::string line) = 0; virtual void on_message(std::string message) = 0; virtual void on_alarm(int alarm) = 0; - virtual void on_run_completed(bool success, size_t failed_index, int error) = 0; - virtual void on_check_completed(bool success, size_t failed_index, int error) = 0; + virtual void on_run_completed(bool success, size_t failed_index, size_t error) = 0; + virtual void on_check_completed(bool success, size_t failed_index, size_t error) = 0; }; struct machine : public transport_callbacks { @@ -119,7 +120,7 @@ struct machine : public transport_callbacks { void request_jog(jog_state jog) const; void cancel_jog() const; - realtime_status_report get_status() const { return last_report; }; + [[nodiscard]] realtime_status_report get_status() const { return last_report; }; void request_unlock(); void request_home(); diff --git a/main.cpp b/main.cpp index e354b65..3356985 100644 --- a/main.cpp +++ b/main.cpp @@ -360,7 +360,7 @@ public: last_alarm = alarm; } - void on_check_completed(bool success, size_t failed_index, int error) override { + void on_check_completed(bool success, size_t failed_index, size_t error) override { btnCheckProgram->set_background_color(success ? colGreen : colRed); if (success) { btnRunProgram->set_enabled(true); @@ -369,19 +369,21 @@ public: btnRunProgram->set_enabled(false); std::stringstream ss; auto i = pgm.instruction_at(failed_index); - ss << "Program check failed at line " << i.line << " (" << i.command << "). Error: " << error; + ss << "Program check failed at line " << i.line << " (" << i.command << "). Error: " << error << ", " + << grbl::error_to_string(error); new MessageDialog(this, MessageDialog::Type::Warning, "Check result", ss.str()); } } - void on_run_completed(bool success, size_t failed_index, int error) override { + void on_run_completed(bool success, size_t failed_index, size_t error) override { btnRunProgram->set_background_color(success ? colGreen : colRed); if (success) { new MessageDialog(this, MessageDialog::Type::Information, "Run result", "Program executed successfully"); } else { std::stringstream ss; auto i = pgm.instruction_at(failed_index); - ss << "Program execution failed at line " << i.line << " (" << i.command << "). Error: " << error; + ss << "Program execution failed at line " << i.line << " (" << i.command << "). Error: " << error << ", " + << grbl::error_to_string(error); new MessageDialog(this, MessageDialog::Type::Warning, "Run result", ss.str()); } }