diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h
index d5643c0546..572a40c95e 100755
--- a/Firmware/Marlin.h
+++ b/Firmware/Marlin.h
@@ -316,7 +316,18 @@ bool printJobOngoing();
bool printer_active();
-extern uint8_t printer_state;
+enum class PrinterStatus : uint8_t
+{
+ NotReady = 0,
+ IsReady = 1,
+ Idle = 2,
+ SDPrintingFinished = 3,
+ HostPrintingFinished = 4,
+ IsSDPrinting = 5,
+ IsHostPrinting = 6,
+};
+
+extern PrinterStatus printer_status;
//! Beware - mcode_in_progress is set as soon as the command gets really processed,
//! which is not the same as posting the M600 command into the command queue
diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index 8702e60b70..047a994221 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -519,14 +519,7 @@ bool __attribute__((noinline)) printer_active() {
|| mesh_bed_leveling_flag;
}
-//!@brief printer_state
-//!printer state state
-//!0 = unknown or finished print
-//!1 = printer ready for next print
-//!2 = printer SD printing
-//!3 = printer USB printing
-//!@endcode
-uint8_t printer_state=0;
+PrinterStatus printer_status;
// Currently only used in one place, allowed to be inlined
bool check_fsensor() {
@@ -1740,7 +1733,7 @@ void loop()
usb_timer.start();
}
else if (usb_timer.expired(10000)) { //just need to check if it expired. Nothing else is needed to be done.
- printer_state = 0; //set printer state to show LCD menu after finished SD print and report correctly M862.7 Q when USB times out
+ printer_status = PrinterStatus::HostPrintingFinished; //set printer state to show LCD menu after finished SD print and report correctly M862.7 Q when USB times out
}
#ifdef PRUSA_M28
@@ -5824,6 +5817,22 @@ SERIAL_PROTOCOLPGM("\n\n");
#endif // Z_PROBE_REPEATABILITY_TEST
#endif // ENABLE_AUTO_BED_LEVELING
+ /*!
+ ### M72 - Set Ready M72: Set Ready
+ #### Usage
+
+ M72 [ S ]
+
+ #### Parameters
+ - `S` - Set printer ready
+ */
+ case 72:
+ {
+ if(code_seen('S')) printer_status = PrinterStatus(code_value_uint8());
+ break;
+ }
+
+
/*!
### M73 - Set/get print progress M73: Set/Get build percentage
#### Usage
@@ -7902,7 +7911,7 @@ SERIAL_PROTOCOLPGM("\n\n");
- M862.4 { P | Q }
- M862.5 { P | Q }
- M862.6 Not used but reserved
- - M862.7 { P<0|1> | Q } 0 = Printer not ready for next print (default), 1 = Printer is ready for next print , 2 = Printer busy printing
+ - M862.7 { Q }
When run with P<> argument, the check is performed against the input value.
When run with Q argument, the current value is shown.
@@ -7988,10 +7997,7 @@ SERIAL_PROTOCOLPGM("\n\n");
case ClPrintChecking::_Features: // ~ .6
break;
case ClPrintChecking::_PrinterState: // ~.7
- if(code_seen('P'))
- printer_state=code_value_uint8();
- else if(code_seen('Q'))
- SERIAL_PROTOCOLLN((int)printer_state);
+ SERIAL_PROTOCOLLN((int)printer_status);
break;
}
break;
diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp
index dd159ce913..dead09942b 100644
--- a/Firmware/cardreader.cpp
+++ b/Firmware/cardreader.cpp
@@ -273,7 +273,7 @@ void CardReader::startFileprint()
if(cardOK)
{
sdprinting = true;
- printer_state = 2; //set printer state to hide LCD menu and report correctly M862.7 Q while SD printing
+ printer_status = PrinterStatus::IsSDPrinting; //set printer state to hide LCD menu and report correctly M862.7 Q while SD printing
#ifdef SDCARD_SORT_ALPHA
//flush_presort();
#endif
@@ -1019,7 +1019,7 @@ void CardReader::printingHasFinished()
else
{
sdprinting = false;
- printer_state = 0; //set printer state to show LCD menu after finished SD print
+ printer_status = PrinterStatus::SDPrintingFinished; //set printer state to show LCD menu after finished SD print
if(SD_FINISHED_STEPPERRELEASE)
{
finishAndDisableSteppers();
diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp
index 5ab79bd63d..96bdc3d8de 100755
--- a/Firmware/cmdqueue.cpp
+++ b/Firmware/cmdqueue.cpp
@@ -481,7 +481,7 @@ void get_command()
// Handle the USB timer
if ((*cmd_start == 'G') && !(IS_SD_PRINTING)) {
usb_timer.start();
- printer_state = 3; //set printer state busy printing to hide LCD menu and report correctly M862.7 Q while USB printing
+ printer_status = PrinterStatus::IsHostPrinting; //set printer state busy printing to hide LCD menu and report correctly M862.7 Q while USB printing
}
if (allow_when_stopped == false && Stopped == true) {
// Stopped can be set either during error states (thermal error: cannot continue), or
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index 3af0235971..cec791c290 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -5124,10 +5124,11 @@ static void lcd_sheet_menu()
//! @brief Set printer state
//! Sets the printer state for next print via LCD menu
//! @endcode
-static void lcd_printer_state()
+static void lcd_printer_status_toggle()
{
- enquecommand_P(PSTR("M118 A1 action:printer_state"));
- printer_state=1;
+ if (printer_status == PrinterStatus::NotReady) printer_status = PrinterStatus::IsReady;
+ else printer_status = PrinterStatus::NotReady;
+ enquecommandf_P(PSTR("M118 A1 action:%s"), (printer_status == PrinterStatus::NotReady) ? "not_ready" : "ready");
}
//! @brief Show Main Menu
@@ -5202,8 +5203,8 @@ static void lcd_main_menu()
} else if (!Stopped) {
MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
}
- if (printer_state == 0) {
- MENU_ITEM_FUNCTION_P(_T(MSG_SET_READY), lcd_printer_state);
+ if (printer_status < PrinterStatus::IsSDPrinting) {
+ MENU_ITEM_TOGGLE_P(_T(MSG_SET_READY), (printer_status == PrinterStatus::IsReady) ? _T(MSG_YES) : _T(MSG_NO), lcd_printer_status_toggle);
}
if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused && !processing_tcode) {
if (usb_timer.running()) {
@@ -5659,7 +5660,7 @@ void print_stop(bool interactive)
// return to status is required to continue processing in the main loop!
lcd_commands_type = LcdCommands::StopPrint;
- printer_state = 0; //set printer state to show LCD menu after print has been stopped and report correctly M862.7 Q
+ printer_status = PrinterStatus::NotReady; //set printer state to show LCD menu after print has been stopped and report correctly M862.7 Q
lcd_return_to_status();
}