Add a global machine state

This commit is contained in:
Scott Lahteine 2020-03-14 18:47:44 -05:00
parent 41ffe9851d
commit 095a1123c1
4 changed files with 21 additions and 9 deletions

View file

@ -202,7 +202,7 @@ const char NUL_STR[] PROGMEM = "",
SP_Z_LBL[] PROGMEM = " Z:",
SP_E_LBL[] PROGMEM = " E:";
bool Running = true;
MarlinState marlin_state = MF_INITIALIZING;
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
bool wait_for_heatup = true;
@ -839,7 +839,7 @@ void stop() {
SERIAL_ERROR_MSG(STR_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
safe_delay(350); // allow enough time for messages to get out before stopping
Running = false;
marlin_state = MF_STOPPED;
}
}
@ -1183,6 +1183,8 @@ void setup() {
SETUP_RUN(max7219.init());
#endif
marlin_state = MF_RUNNING;
SETUP_LOG("setup() completed.");
}

View file

@ -76,9 +76,19 @@ void minkill(const bool steppers_off=false);
void quickstop_stepper();
extern bool Running;
inline bool IsRunning() { return Running; }
inline bool IsStopped() { return !Running; }
// Global State of the firmware
enum MarlinState : uint8_t {
MF_INITIALIZING = 0,
MF_RUNNING = _BV(0),
MF_PAUSED = _BV(1),
MF_WAITING = _BV(2),
MF_STOPPED = _BV(3),
MF_KILLED = _BV(7)
};
extern MarlinState marlin_state;
inline bool IsRunning() { return marlin_state == MF_RUNNING; }
inline bool IsStopped() { return marlin_state != MF_RUNNING; }
bool printingIsActive();
bool printingIsPaused();

View file

@ -23,7 +23,7 @@
#include "../gcode.h"
#include "../../lcd/ultralcd.h" // for lcd_reset_alert_level
#include "../../MarlinCore.h" // for Running
#include "../../MarlinCore.h" // for marlin_state
#include "../queue.h" // for flush_and_request_resend
/**
@ -37,7 +37,7 @@
*
*/
void GcodeSuite::M999() {
Running = true;
marlin_state = MF_RUNNING;
ui.reset_alert_level();
if (parser.boolval('S')) return;

View file

@ -765,7 +765,7 @@ int16_t Temperature::getHeaterPower(const heater_ind_t heater_id) {
//
inline void loud_kill(PGM_P const lcd_msg, const heater_ind_t heater) {
Running = false;
marlin_state = MF_KILLED;
#if USE_BEEPER
for (uint8_t i = 20; i--;) {
WRITE(BEEPER_PIN, HIGH); delay(25);
@ -2003,7 +2003,7 @@ void Temperature::init() {
/**
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
SERIAL_ECHOPGM("Thermal Runaway Running. Heater ID: ");
if (heater_id == H_CHAMBER) SERIAL_ECHOPGM("chamber");
if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
SERIAL_ECHOPAIR(" ; State:", sm.state, " ; Timer:", sm.timer, " ; Temperature:", current, " ; Target Temp:", target);