Browse Source

Add a global machine state

Scott Lahteine 4 years ago
parent
commit
095a1123c1

+ 4
- 2
Marlin/src/MarlinCore.cpp View File

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

+ 13
- 3
Marlin/src/MarlinCore.h View File

@@ -76,9 +76,19 @@ void minkill(const bool steppers_off=false);
76 76
 
77 77
 void quickstop_stepper();
78 78
 
79
-extern bool Running;
80
-inline bool IsRunning() { return  Running; }
81
-inline bool IsStopped() { return !Running; }
79
+// Global State of the firmware
80
+enum MarlinState : uint8_t {
81
+  MF_INITIALIZING =  0,
82
+  MF_RUNNING      = _BV(0),
83
+  MF_PAUSED       = _BV(1),
84
+  MF_WAITING      = _BV(2),
85
+  MF_STOPPED      = _BV(3),
86
+  MF_KILLED       = _BV(7)
87
+};
88
+
89
+extern MarlinState marlin_state;
90
+inline bool IsRunning() { return marlin_state == MF_RUNNING; }
91
+inline bool IsStopped() { return marlin_state != MF_RUNNING; }
82 92
 
83 93
 bool printingIsActive();
84 94
 bool printingIsPaused();

+ 2
- 2
Marlin/src/gcode/control/M999.cpp View File

@@ -23,7 +23,7 @@
23 23
 #include "../gcode.h"
24 24
 
25 25
 #include "../../lcd/ultralcd.h" // for lcd_reset_alert_level
26
-#include "../../MarlinCore.h"   // for Running
26
+#include "../../MarlinCore.h"   // for marlin_state
27 27
 #include "../queue.h"           // for flush_and_request_resend
28 28
 
29 29
 /**
@@ -37,7 +37,7 @@
37 37
  *
38 38
  */
39 39
 void GcodeSuite::M999() {
40
-  Running = true;
40
+  marlin_state = MF_RUNNING;
41 41
   ui.reset_alert_level();
42 42
 
43 43
   if (parser.boolval('S')) return;

+ 2
- 2
Marlin/src/module/temperature.cpp View File

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

Loading…
Cancel
Save