diff --git a/Grbl_Esp32/src/ProcessSettings.cpp b/Grbl_Esp32/src/ProcessSettings.cpp index 3a79ccc7..e63133bd 100644 --- a/Grbl_Esp32/src/ProcessSettings.cpp +++ b/Grbl_Esp32/src/ProcessSettings.cpp @@ -222,7 +222,7 @@ Error toggle_check_mode(const char* value, WebUI::AuthenticationLevel auth_level return Error::Ok; } Error disable_alarm_lock(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { - if (sys.state == State::Alarm) { + if (sys.state == State::Alarm || sys.state == State::ConfigAlarm) { // Block if safety door is ajar. if (config->_control->system_check_safety_door_ajar()) { return Error::CheckDoor; @@ -334,9 +334,15 @@ Error restore_settings(const char* value, WebUI::AuthenticationLevel auth_level, } Error showState(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { - grbl_sendf(out->client(), "State 0x%x\r\n", sys.state); + const char* name; + const State state = sys.state; + auto it = StateName.find(state); + name = it == StateName.end() ? "" : it->second; + + grbl_sendf(out->client(), "State %d (%s)\r\n", state, name); return Error::Ok; } + Error doJog(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { // For jogging, you must give gc_execute_line() a line that // begins with $J=. There are several ways we can get here, @@ -357,6 +363,9 @@ const char* alarmString(ExecAlarm alarmNumber) { } Error listAlarms(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { + if (sys_rt_exec_alarm != ExecAlarm::None) { + grbl_sendf(out->client(), "Active alarm: %d (%s)\r\n", int(sys_rt_exec_alarm), alarmString(sys_rt_exec_alarm)); + } if (value) { char* endptr = NULL; uint8_t alarmNumber = strtol(value, &endptr, 10); diff --git a/Grbl_Esp32/src/Protocol.cpp b/Grbl_Esp32/src/Protocol.cpp index 4a063d0c..96c44471 100644 --- a/Grbl_Esp32/src/Protocol.cpp +++ b/Grbl_Esp32/src/Protocol.cpp @@ -138,7 +138,7 @@ void protocol_main_loop() { // NOTE: Sleep mode disables the stepper drivers and position can't be guaranteed. // Re-initialize the sleep state as an ALARM mode to ensure user homes or acknowledges. if (sys.state == State::ConfigAlarm) { - report_feedback_message(Message::AlarmLock); + report_feedback_message(Message::ConfigAlarmLock); } else if (sys.state == State::Alarm || sys.state == State::Sleep) { report_feedback_message(Message::AlarmLock); sys.state = State::Alarm; // Ensure alarm state is set. diff --git a/Grbl_Esp32/src/Report.cpp b/Grbl_Esp32/src/Report.cpp index 2f882370..d8ecd100 100644 --- a/Grbl_Esp32/src/Report.cpp +++ b/Grbl_Esp32/src/Report.cpp @@ -283,6 +283,7 @@ std::map MessageText = { { Message::RestoreDefaults, "Restoring defaults" }, { Message::SpindleRestore, "Restoring spindle" }, { Message::SleepMode, "Sleeping" }, + { Message::ConfigAlarmLock, "Configuration error - '$X' to unlock" }, // Handled separately due to numeric argument // { Message::SdFileQuit, "Reset during SD file at line: %d" }, }; @@ -297,8 +298,7 @@ void report_feedback_message(Message message) { // ok to send to all clients grbl_notifyf("SD print canceled", "Reset during SD file at line: %d", config->_sdCard->get_current_line_number()); info_serial("Reset during SD file at line: %d", config->_sdCard->get_current_line_number()); - } else - { + } else { auto it = MessageText.find(message); if (it != MessageText.end()) { info_serial(it->second); diff --git a/Grbl_Esp32/src/Report.h b/Grbl_Esp32/src/Report.h index b1f26d06..feae8000 100644 --- a/Grbl_Esp32/src/Report.h +++ b/Grbl_Esp32/src/Report.h @@ -47,6 +47,7 @@ enum class Message : uint8_t { RestoreDefaults = 9, SpindleRestore = 10, SleepMode = 11, + ConfigAlarmLock = 12, SdFileQuit = 60, // mc_reset was called during an SD job }; diff --git a/Grbl_Esp32/src/Settings.cpp b/Grbl_Esp32/src/Settings.cpp index ca5cdd79..acf38e45 100644 --- a/Grbl_Esp32/src/Settings.cpp +++ b/Grbl_Esp32/src/Settings.cpp @@ -10,7 +10,7 @@ bool idleOrJog() { return sys.state != State::Idle && sys.state != State::Jog; } bool idleOrAlarm() { - return sys.state != State::Idle && sys.state != State::Alarm; + return sys.state != State::Idle && sys.state != State::Alarm && sys.state != State::ConfigAlarm; } bool notCycleOrHold() { return sys.state == State::Cycle && sys.state == State::Hold; diff --git a/Grbl_Esp32/src/System.cpp b/Grbl_Esp32/src/System.cpp index f15f589c..8045e546 100644 --- a/Grbl_Esp32/src/System.cpp +++ b/Grbl_Esp32/src/System.cpp @@ -214,3 +214,16 @@ void __attribute__((weak)) user_defined_macro(uint8_t index) { strcat(line, "\r"); WebUI::inputBuffer.push(line); } + +std::map StateName = { + { State::Idle, "Idle" }, + { State::Alarm, "Alarm" }, + { State::CheckMode, "CheckMode" }, + { State::Homing, "Homing" }, + { State::Cycle, "Cycle" }, + { State::Hold, "Hold" }, + { State::Jog, "Jog" }, + { State::SafetyDoor, "SafetyDoor" }, + { State::Sleep, "Sleep" }, + { State::ConfigAlarm, "ConfigAlarm" }, +}; diff --git a/Grbl_Esp32/src/System.h b/Grbl_Esp32/src/System.h index c66c31b3..0130fcfe 100644 --- a/Grbl_Esp32/src/System.h +++ b/Grbl_Esp32/src/System.h @@ -31,18 +31,20 @@ // of Grbl to manage each without overlapping. It is also used as a messaging flag for // critical events. enum class State : uint8_t { - Idle = 0, // Must be zero. - Alarm, // In alarm state. Locks out all g-code processes. Allows settings access. - CheckMode, // G-code check mode. Locks out planner and motion only. - Homing, // Performing homing cycle - Cycle, // Cycle is running or motions are being executed. - Hold, // Active feed hold - Jog, // Jogging mode. - SafetyDoor, // Safety door is ajar. Feed holds and de-energizes system. - Sleep, // Sleep state. - ConfigAlarm, // You can't do anything but fix your config file. + Idle = 0, // Must be zero. + Alarm, // In alarm state. Locks out all g-code processes. Allows settings access. + CheckMode, // G-code check mode. Locks out planner and motion only. + Homing, // Performing homing cycle + Cycle, // Cycle is running or motions are being executed. + Hold, // Active feed hold + Jog, // Jogging mode. + SafetyDoor, // Safety door is ajar. Feed holds and de-energizes system. + Sleep, // Sleep state. + ConfigAlarm, // You can't do anything but fix your config file. }; +extern std::map StateName; + // Step segment generator state flags. struct StepControl { uint8_t endMotion : 1;