Add printer_state.cpp/.h
This commit is contained in:
parent
d276695ce7
commit
514607318e
|
|
@ -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
|
||||
|
|
@ -311,19 +312,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -5840,17 +5838,40 @@ Sigma_Exit:
|
|||
#endif // ENABLE_AUTO_BED_LEVELING
|
||||
|
||||
/*!
|
||||
### M72 - Set Ready <a href="https://reprap.org/wiki/G-code#M73:_Set_Ready">M72: Set Ready</a>
|
||||
### M72 - Set/get Printer State <a href="https://reprap.org/wiki/G-code#M72:_Set.2FGet_Printer_State">M72: Set/get Printer State</a>
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -8058,8 +8079,7 @@ Sigma_Exit:
|
|||
- M862.3 { P"<model_name>" | Q }
|
||||
- M862.4 { P<fw_version> | Q }
|
||||
- M862.5 { P<gcode_level> | 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.
|
||||
|
|
@ -8142,10 +8162,9 @@ Sigma_Exit:
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -274,7 +274,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
|
||||
|
|
@ -1020,7 +1020,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();
|
||||
|
|
|
|||
|
|
@ -482,7 +482,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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
@ -899,6 +899,7 @@ void lcd_commands()
|
|||
pid_temp = DEFAULT_PID_TEMP;
|
||||
lcd_commands_step = 0;
|
||||
lcd_commands_type = LcdCommands::Idle;
|
||||
SetPrinterState(PrinterState::Idle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5123,9 +5124,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
|
||||
|
|
@ -5200,8 +5201,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 && !print_job_timer.isPaused() && !processing_tcode) {
|
||||
if (usb_timer.running()) {
|
||||
|
|
@ -5655,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_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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue