Skip to content

Commit

Permalink
Add HOST power panic auto recovery option
Browse files Browse the repository at this point in the history
Change `PRINT_TYPE_USB` to `PRINT_TYPE_HOST`
  • Loading branch information
3d-gussner committed Jan 10, 2024
1 parent c3bd109 commit fe06263
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
22 changes: 14 additions & 8 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ uint8_t saved_bed_temperature; //!< Bed temperature
bool saved_extruder_relative_mode;
uint8_t saved_fan_speed = 0; //!< Print fan speed
//! @}
bool uvlo_auto_recovery_ready = false;

static int saved_feedmultiply_mm = 100;

Expand Down Expand Up @@ -1580,7 +1581,8 @@ void setup()
#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));
#endif
if ( degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET) ){
uvlo_auto_recovery_ready = (degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET));
if (uvlo_auto_recovery_ready){
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
puts_P(_N("Automatic recovery!"));
#endif
Expand All @@ -1590,7 +1592,7 @@ void setup()
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
puts_P(_N("Normal recovery!"));
#endif
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PRINT_TYPE_USB) {
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PRINT_TYPE_HOST) {
recover_print(0);
} else {
const uint8_t btn = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_RECOVER_PRINT), false);
Expand Down Expand Up @@ -1726,7 +1728,7 @@ void loop()
KEEPALIVE_STATE(NOT_BUSY);
}

if (print_job_timer.isPaused() && saved_printing_type == PowerPanic::PRINT_TYPE_USB) { //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing.
if (print_job_timer.isPaused() && saved_printing_type == PowerPanic::PRINT_TYPE_HOST) { //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.
Expand Down Expand Up @@ -4129,7 +4131,7 @@ void process_commands()
// Print is recovered, clear the recovery flag
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
}
else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB)
else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_HOST)
{
// For Host prints we need to start the timer so that the pause has any effect
// this will allow g-codes to be processed while in the paused state
Expand Down Expand Up @@ -5998,14 +6000,18 @@ SERIAL_PROTOCOLPGM("\n\n");
}
}

if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_HOST
&& eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY
&& print_job_timer.isPaused()) {
// The print is in a paused state. The print was recovered following a power panic
// but up to this point the printer has been waiting for the M79 from the host
// Send action to the host, so the host can resume the print. It is up to the host
// to resume the print correctly.
SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_UVLO_RECOVERY_READY);
if (uvlo_auto_recovery_ready) {
SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_UVLO_AUTO_RECOVERY_READY);
} else {
SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_UVLO_RECOVERY_READY);
}
}

break;
Expand Down Expand Up @@ -10643,7 +10649,7 @@ 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 = PowerPanic::PRINT_TYPE_USB;
saved_printing_type = PowerPanic::PRINT_TYPE_HOST;
}
else {
saved_printing_type = PowerPanic::PRINT_TYPE_NONE;
Expand Down Expand Up @@ -10744,7 +10750,7 @@ void restore_print_file_state() {
card.setIndex(saved_sdpos);
sdpos_atomic = saved_sdpos;
card.sdprinting = true;
} else if (saved_printing_type == PowerPanic::PRINT_TYPE_USB) { //was usb printing
} else if (saved_printing_type == PowerPanic::PRINT_TYPE_HOST) { //was usb printing
gcode_LastN = saved_sdpos; //saved_sdpos was reused for storing line number when usb printing
serial_count = 0;
FlushSerialRequestResend();
Expand Down
1 change: 1 addition & 0 deletions Firmware/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const char MSG_HOST_ACTION_READY[] PROGMEM_N1 = "//action:ready"; ////
const char MSG_HOST_ACTION_NOT_READY[] PROGMEM_N1 = "//action:not_ready"; ////
const char MSG_HOST_ACTION_START[] PROGMEM_N1 = "//action:start"; ////
const char MSG_HOST_ACTION_UVLO_RECOVERY_READY[] PROGMEM_N1 = "//action:uvlo_recovery_ready"; ////
const char MSG_HOST_ACTION_UVLO_AUTO_RECOVERY_READY[] PROGMEM_N1 = "//action:uvlo_auto_recovery_ready"; ////
const char MSG_FANCHECK_HOTEND[] PROGMEM_N1 = "Err:HOTEND FAN ERROR"; ////c=20
const char MSG_FANCHECK_PRINT[] PROGMEM_N1 = "Err:PRINT FAN ERROR"; ////c=20
const char MSG_M112_KILL[] PROGMEM_N1 = "M112 called. Emergency Stop."; ////c=20
Expand Down
1 change: 1 addition & 0 deletions Firmware/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ extern const char MSG_HOST_ACTION_READY[];
extern const char MSG_HOST_ACTION_NOT_READY[];
extern const char MSG_HOST_ACTION_START[];
extern const char MSG_HOST_ACTION_UVLO_RECOVERY_READY[];
extern const char MSG_HOST_ACTION_UVLO_AUTO_RECOVERY_READY[];
extern const char MSG_FANCHECK_HOTEND[];
extern const char MSG_FANCHECK_PRINT[];
extern const char MSG_M112_KILL[];
Expand Down
2 changes: 1 addition & 1 deletion Firmware/power_panic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void restore_print_from_eeprom(bool mbl_was_active) {
// Set a position in the file.
enquecommandf_P(PSTR("M26 S%lu"), position);
}
else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB)
else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_HOST)
{
// Set line number
enquecommandf_P(PSTR("M110 N%lu"), position);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/power_panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum PowerPanicFlag : uint8_t {
// Types of printjobs possible when power panic is triggered
enum PrintType : uint8_t {
PRINT_TYPE_SD = 0,
PRINT_TYPE_USB = 1,
PRINT_TYPE_HOST = 1,
PRINT_TYPE_NONE = 2,
};
} // namespace PowerPanic
Expand Down

0 comments on commit fe06263

Please sign in to comment.