Skip to content

Commit

Permalink
Create enum class and use M72 to Set Ready
Browse files Browse the repository at this point in the history
  • Loading branch information
3d-gussner committed Oct 25, 2023
1 parent 16a2e42 commit 8216f56
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
13 changes: 12 additions & 1 deletion Firmware/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 20 additions & 14 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -5824,6 +5817,22 @@ SERIAL_PROTOCOLPGM("\n\n");
#endif // Z_PROBE_REPEATABILITY_TEST
#endif // ENABLE_AUTO_BED_LEVELING

/*!
### M72 - Set Ready <a href="https://reprap.org/wiki/G-code#M73:_Set_Ready">M72: Set Ready</a>
#### 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 <a href="https://reprap.org/wiki/G-code#M73:_Set.2FGet_build_percentage">M73: Set/Get build percentage</a>
#### Usage
Expand Down Expand Up @@ -7902,7 +7911,7 @@ SERIAL_PROTOCOLPGM("\n\n");
- M862.4 { P<fw_version> | Q }
- M862.5 { P<gcode_level> | 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.
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Firmware/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Firmware/cmdqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 8216f56

Please sign in to comment.