diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h
index c569cab061..1a05ecea6c 100755
--- a/Firmware/Marlin.h
+++ b/Firmware/Marlin.h
@@ -22,6 +22,7 @@
#include "pins.h"
#include "Timer.h"
#include "mmu2.h"
+#include "printer_state.h"
#ifndef AT90USB
#define HardwareSerial_h // trick to disable the standard HWserial
@@ -316,19 +317,6 @@ bool printJobOngoing();
bool printer_active();
-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
//! There can be a considerable lag between posting M600 and its real processing which might result
diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index ca9a4cfa16..bd73f4c07d 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -520,8 +520,6 @@ bool __attribute__((noinline)) printer_active() {
|| mesh_bed_leveling_flag;
}
-PrinterStatus printer_status;
-
// Currently only used in one place, allowed to be inlined
bool check_fsensor() {
return printJobOngoing()
@@ -1735,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_status = PrinterStatus::HostPrintingFinished; //set printer state to show LCD menu after finished SD print and report correctly M862.7 Q when USB times out
+ SetPrinterState(PrinterState::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
@@ -5841,17 +5839,40 @@ SERIAL_PROTOCOLPGM("\n\n");
#endif // ENABLE_AUTO_BED_LEVELING
/*!
- ### M72 - Set Ready M72: Set Ready
+ ### M72 - Set/get Printer State M72: Set/get Printer State
+ Without any parameter get printer state
+ - 0 = NotReady Used by PrusaConnect
+ - 1 = IsReady Used by PrusaConnect
+ - 2 = Idle
+ - 3 = SD printing finished
+ - 4 = Host printing finished
+ - 5 = SD printing
+ - 6 = Host printing
+
#### Usage
M72 [ S ]
#### Parameters
- - `S` - Set printer ready
+ - `Snnn` - Set printer state 0 = not_ready, 1 = ready
*/
case 72:
{
- if(code_seen('S')) printer_status = PrinterStatus(code_value_uint8());
+ if(code_seen('S')){
+ switch (code_value_uint8()){
+ case 0:
+ SetPrinterState(PrinterState::NotReady);
+ break;
+ case 1:
+ SetPrinterState(PrinterState::IsReady);
+ break;
+ default:
+ break;
+ }
+ } else {
+ printf_P(_N("PrinterState: %d\n"),uint8_t(GetPrinterState()));
+ break;
+ }
break;
}
@@ -7956,8 +7977,7 @@ SERIAL_PROTOCOLPGM("\n\n");
- M862.3 { P"" | Q }
- M862.4 { P | Q }
- M862.5 { P | Q }
- - M862.6 Not used but reserved
- - M862.7 { Q }
+ - M862.6 Not used but reserved by 32-bit
When run with P<> argument, the check is performed against the input value.
When run with Q argument, the current value is shown.
@@ -8040,10 +8060,9 @@ SERIAL_PROTOCOLPGM("\n\n");
else if(code_seen('Q'))
SERIAL_PROTOCOLLN(GCODE_LEVEL);
break;
- case ClPrintChecking::_Features: // ~ .6
+ case ClPrintChecking::_Features: // ~ .6 used by 32-bit
break;
- case ClPrintChecking::_PrinterState: // ~.7
- SERIAL_PROTOCOLLN((int)printer_status);
+ default:
break;
}
break;
diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp
index dead09942b..5ae1043ec4 100644
--- a/Firmware/cardreader.cpp
+++ b/Firmware/cardreader.cpp
@@ -273,7 +273,7 @@ void CardReader::startFileprint()
if(cardOK)
{
sdprinting = true;
- printer_status = PrinterStatus::IsSDPrinting; //set printer state to hide LCD menu and report correctly M862.7 Q while SD printing
+ SetPrinterState(PrinterState::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_status = PrinterStatus::SDPrintingFinished; //set printer state to show LCD menu after finished SD print
+ SetPrinterState(PrinterState::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 96bdc3d8de..f4d197c9de 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_status = PrinterStatus::IsHostPrinting; //set printer state busy printing to hide LCD menu and report correctly M862.7 Q while USB printing
+ SetPrinterState(PrinterState::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/printer_state.cpp b/Firmware/printer_state.cpp
new file mode 100644
index 0000000000..fb15fcedf1
--- /dev/null
+++ b/Firmware/printer_state.cpp
@@ -0,0 +1,16 @@
+//! @file
+//! @brief Printer State
+//! @param GetPrinterState get current printer state
+//! @param SetPrinterState set printer state
+
+#include "printer_state.h"
+
+static PrinterState printer_state;
+
+PrinterState GetPrinterState() {
+ return printer_state;
+}
+
+PrinterState SetPrinterState(PrinterState status) {
+ return printer_state = status;
+}
diff --git a/Firmware/printer_state.h b/Firmware/printer_state.h
new file mode 100644
index 0000000000..a94b0f7428
--- /dev/null
+++ b/Firmware/printer_state.h
@@ -0,0 +1,27 @@
+//! @file
+//! @brief Printer States
+//! @param NotReady
+//! @param IsReady
+//! @param Idle
+//! @param SDPrintingFinished
+//! @param HostPrintingFinished
+//! @param IsSDPrinting
+//! @param IsHostPrinting
+//! @todo Pause/Resume states, Heating states and more
+
+#pragma once
+#include "macros.h"
+
+enum class PrinterState : uint8_t
+{
+ NotReady = 0, //Lowest state to simplify queries
+ IsReady = 1, //
+ Idle = 2,
+ SDPrintingFinished = 3,
+ HostPrintingFinished = 4,
+ IsSDPrinting = 5,
+ IsHostPrinting = 6,
+};
+
+PrinterState GetPrinterState();
+PrinterState SetPrinterState(PrinterState status);
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index 6554ad6bf5..986c375a3e 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -901,6 +901,7 @@ void lcd_commands()
pid_temp = DEFAULT_PID_TEMP;
lcd_commands_step = 0;
lcd_commands_type = LcdCommands::Idle;
+ SetPrinterState(PrinterState::Idle);
}
}
@@ -5127,9 +5128,9 @@ static void lcd_sheet_menu()
//! @endcode
static void lcd_printer_status_toggle()
{
- 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");
+ if (GetPrinterState() == PrinterState::IsReady) SetPrinterState(PrinterState::NotReady);
+ else SetPrinterState(PrinterState::IsReady);
+ enquecommandf_P(PSTR("M118 A1 action:%s"), (GetPrinterState() == PrinterState::IsReady) ? "ready" : "not_ready");
}
//! @brief Show Main Menu
@@ -5204,8 +5205,12 @@ static void lcd_main_menu()
} else if (!Stopped) {
MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
}
- 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 (GetPrinterState() < PrinterState::IsSDPrinting) {
+ if(GetPrinterState() == PrinterState::IsReady) {
+ MENU_ITEM_TOGGLE_P(_T(MSG_SET_READY), _T(MSG_NO), lcd_printer_status_toggle);
+ } else {
+ MENU_ITEM_TOGGLE_P(_T(MSG_SET_READY), _T(MSG_YES), lcd_printer_status_toggle);
+ }
}
if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused && !processing_tcode) {
if (usb_timer.running()) {
@@ -5664,7 +5669,7 @@ void print_stop(bool interactive)
// return to status is required to continue processing in the main loop!
lcd_commands_type = LcdCommands::StopPrint;
- printer_status = PrinterStatus::NotReady; //set printer state to show LCD menu after print has been stopped and report correctly M862.7 Q
+ SetPrinterState(PrinterState::NotReady); //set printer state to show LCD menu after print has been stopped and report correctly M862.7 Q
lcd_return_to_status();
}