PFW-1543 Move printing types into enum

Also add power panic namespace
This commit is contained in:
gudnimg 2023-10-01 12:57:25 +00:00
parent fcd61a378d
commit 3eaca29b0b
5 changed files with 33 additions and 26 deletions

View File

@ -298,9 +298,6 @@ extern bool mesh_bed_leveling_flag;
extern bool saved_printing;
extern uint32_t saved_sdpos;
extern uint8_t saved_printing_type;
#define PRINTING_TYPE_SD 0
#define PRINTING_TYPE_USB 1
#define PRINTING_TYPE_NONE 2
extern uint16_t saved_extruder_temperature; //!< Active extruder temperature
extern uint8_t saved_bed_temperature; //!< Bed temperature

View File

@ -310,7 +310,7 @@ static bool chdkActive = false;
//! @{
bool saved_printing = false; //!< Print is paused and saved in RAM
uint32_t saved_sdpos = 0; //!< SD card position, or line number in case of USB printing
uint8_t saved_printing_type = PRINTING_TYPE_SD;
uint8_t saved_printing_type = PowerPanic::PRINT_TYPE_SD;
float saved_pos[NUM_AXIS] = { X_COORD_INVALID, 0, 0, 0 };
uint16_t saved_feedrate2 = 0; //!< Default feedrate (truncated from float)
static int saved_feedmultiply2 = 0;
@ -638,9 +638,9 @@ void crashdet_cancel()
{
saved_printing = false;
tmc2130_sg_stop_on_crash = true;
if (saved_printing_type == PRINTING_TYPE_SD) {
if (saved_printing_type == PowerPanic::PRINT_TYPE_SD) {
print_stop();
}else if(saved_printing_type == PRINTING_TYPE_USB){
}else if(saved_printing_type == PowerPanic::PRINT_TYPE_USB){
SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); //for Octoprint: works the same as clicking "Abort" button in Octoprint GUI
cmdqueue_reset();
}
@ -1458,7 +1458,7 @@ void setup()
}
eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0);
}
eeprom_init_default_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
eeprom_init_default_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
eeprom_init_default_byte((uint8_t*)EEPROM_SD_SORT, 0);
//mbl_mode_init();
@ -1579,7 +1579,7 @@ void setup()
fw_crash_init();
#ifdef UVLO_SUPPORT
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != NO_PENDING_RECOVERY) { //previous print was terminated by UVLO
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY) { //previous print was terminated by UVLO
manage_heater(); // Update temperatures
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
printf_P(_N("Power panic detected!\nCurrent bed temp:%d\nSaved bed temp:%d\n"), (int)degBed(), eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED));
@ -1597,7 +1597,7 @@ void setup()
if ( lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_RECOVER_PRINT), false) == LCD_LEFT_BUTTON_CHOICE) {
recover_print(0);
} else {
eeprom_update_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
lcd_update_enable(true);
lcd_update(2);
lcd_setstatuspgm(MSG_WELCOME);
@ -1728,7 +1728,7 @@ void loop()
KEEPALIVE_STATE(NOT_BUSY);
}
if (isPrintPaused && saved_printing_type == PRINTING_TYPE_USB) { //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing.
if (isPrintPaused && saved_printing_type == PowerPanic::PRINT_TYPE_USB) { //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing.
usb_timer.start();
}
else if (usb_timer.expired(10000)) { //just need to check if it expired. Nothing else is needed to be done.
@ -4084,7 +4084,7 @@ void process_commands()
printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]);
}
else if (code_seen_P(PSTR("uvlo"))) { // PRUSA uvlo
eeprom_update_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
enquecommand_P(MSG_M24);
}
else if (code_seen_P(PSTR("MMURES"))) // PRUSA MMURES
@ -10341,7 +10341,7 @@ void save_print_file_state() {
saved_sdpos -= sdlen_planner;
sdlen_cmdqueue = cmdqueue_calc_sd_length(); //length of sd commands in cmdqueue
saved_sdpos -= sdlen_cmdqueue;
saved_printing_type = PRINTING_TYPE_SD;
saved_printing_type = PowerPanic::PRINT_TYPE_SD;
}
else if (usb_timer.running()) { //reuse saved_sdpos for storing line number
saved_sdpos = gcode_LastN; //start with line number of command added recently to cmd queue
@ -10349,10 +10349,10 @@ void save_print_file_state() {
nlines = planner_calc_sd_length(); //number of lines of commands in planner
saved_sdpos -= nlines;
saved_sdpos -= buflen; //number of blocks in cmd buffer
saved_printing_type = PRINTING_TYPE_USB;
saved_printing_type = PowerPanic::PRINT_TYPE_USB;
}
else {
saved_printing_type = PRINTING_TYPE_NONE;
saved_printing_type = PowerPanic::PRINT_TYPE_NONE;
//not sd printing nor usb printing
}
@ -10446,11 +10446,11 @@ void save_print_file_state() {
}
void restore_print_file_state() {
if (saved_printing_type == PRINTING_TYPE_SD) { //was sd printing
if (saved_printing_type == PowerPanic::PRINT_TYPE_SD) { //was sd printing
card.setIndex(saved_sdpos);
sdpos_atomic = saved_sdpos;
card.sdprinting = true;
} else if (saved_printing_type == PRINTING_TYPE_USB) { //was usb printing
} else if (saved_printing_type == PowerPanic::PRINT_TYPE_USB) { //was usb printing
gcode_LastN = saved_sdpos; //saved_sdpos was reused for storing line number when usb printing
serial_count = 0;
FlushSerialRequestResend();
@ -10642,7 +10642,7 @@ void restore_print_from_ram_and_continue(float e_move)
restore_print_file_state();
lcd_setstatuspgm(MSG_WELCOME);
saved_printing_type = PRINTING_TYPE_NONE;
saved_printing_type = PowerPanic::PRINT_TYPE_NONE;
saved_printing = false;
planner_aborted = true; // unroll the stack
}
@ -10650,9 +10650,9 @@ void restore_print_from_ram_and_continue(float e_move)
// Cancel the state related to a currently saved print
void cancel_saved_printing()
{
eeprom_update_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
saved_start_position[0] = SAVED_START_POSITION_UNSET;
saved_printing_type = PRINTING_TYPE_NONE;
saved_printing_type = PowerPanic::PRINT_TYPE_NONE;
saved_printing = false;
}

View File

@ -7,6 +7,7 @@
#include "temperature.h"
#include "language.h"
#include "Prusa_farm.h"
#include "power_panic.h"
#ifdef SDSUPPORT
@ -557,7 +558,7 @@ void CardReader::getStatus(bool arg_P)
{
if (isPrintPaused)
{
if (saved_printing && (saved_printing_type == PRINTING_TYPE_SD))
if (saved_printing && (saved_printing_type == PowerPanic::PRINT_TYPE_SD))
SERIAL_PROTOCOLLNPGM("SD print paused");
else
SERIAL_PROTOCOLLNPGM("Print saved");

View File

@ -41,7 +41,7 @@ void uvlo_() {
unsigned long time_start = _millis();
// True if a print is already saved to RAM
bool sd_print_saved_in_ram = saved_printing && (saved_printing_type == PRINTING_TYPE_SD);
bool sd_print_saved_in_ram = saved_printing && (saved_printing_type == PowerPanic::PRINT_TYPE_SD);
// Flag to decide whether or not to set EEPROM_UVLO bit
bool sd_print = card.sdprinting || sd_print_saved_in_ram;
@ -199,7 +199,7 @@ void uvlo_() {
// Note: Recovering a print from EEPROM currently assumes the user
// is printing from an SD card, this is why this EEPROM byte is only set
// when SD card print is detected
if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, PENDING_RECOVERY);
if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::PENDING_RECOVERY);
// Increment power failure counter
eeprom_increment_byte((uint8_t*)EEPROM_POWER_COUNT);
@ -272,7 +272,7 @@ static void uvlo_tiny() {
}
// Update the the "power outage" flag.
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PENDING_RECOVERY_RETRY);
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::PENDING_RECOVERY_RETRY);
// Increment power failure counter
eeprom_increment_byte((uint8_t*)EEPROM_POWER_COUNT);
@ -294,7 +294,7 @@ void setup_uvlo_interrupt() {
EIMSK |= (1 << 4);
// check if power was lost before we armed the interrupt
if(!(PINE & (1 << 4)) && eeprom_read_byte((uint8_t*)EEPROM_UVLO) != NO_PENDING_RECOVERY)
if(!(PINE & (1 << 4)) && eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY)
{
SERIAL_ECHOLNRPGM(MSG_INT4);
uvlo_drain_reset();
@ -304,7 +304,7 @@ void setup_uvlo_interrupt() {
ISR(INT4_vect) {
EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once
SERIAL_ECHOLNRPGM(MSG_INT4);
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == NO_PENDING_RECOVERY)
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::NO_PENDING_RECOVERY)
{
if(printer_active()) {
uvlo_();
@ -327,7 +327,7 @@ void recover_print(uint8_t automatic) {
// Lift the print head 25mm, first to avoid collisions with oozed material with the print,
// and second also so one may remove the excess priming material.
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PENDING_RECOVERY)
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PENDING_RECOVERY)
{
enquecommandf_P(PSTR("G1 Z%.3f F800"), current_position[Z_AXIS] + 25);
}

View File

@ -1,11 +1,20 @@
#pragma once
namespace PowerPanic {
enum PowerPanicFlag : uint8_t {
NO_PENDING_RECOVERY = 0,
PENDING_RECOVERY = 1, // First power panic, print state is saved in EEPROM
PENDING_RECOVERY_RETRY = 2, // Power outage occured during recovery, print is still saved in EEPROM
};
// Types of printjobs possible when power panic is triggered
enum PrintType : uint8_t {
PRINT_TYPE_SD = 0,
PRINT_TYPE_USB = 1,
PRINT_TYPE_NONE = 2,
};
} // namespace PowerPanic
void uvlo_();
void recover_print(uint8_t automatic);
void setup_uvlo_interrupt();