Fix multiple Z lifts when multiple short power panic

Add DEBUG_UVLO
Fix LCD menus to be hidden while power panic recovery isn't finished
This commit is contained in:
3d-gussner 2024-02-05 17:32:16 +01:00
parent 17dfa6b6a9
commit c513c6965a
14 changed files with 135 additions and 61 deletions

View File

@ -317,6 +317,8 @@ bool printingIsPaused();
bool printer_active();
bool printer_recovering();
//! 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

View File

@ -312,7 +312,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 = PowerPanic::PRINT_TYPE_SD;
uint8_t saved_printing_type = PowerPanic::PRINT_TYPE_NONE;
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;
@ -546,12 +546,18 @@ bool __attribute__((noinline)) printer_active() {
printf_P(PSTR("get_temp_error() = %d\n"), (int)get_temp_error());
printf_P(PSTR("card.mounted = %d\n"), (int)card.mounted);
printf_P(PSTR("card.isFileOpen() = %d\n"), (int)card.isFileOpen());
printf_P(PSTR("PP state = %d\n"), (int)printer_recovering());
SERIAL_ECHOLN("");
}
return res;
#endif //End DEBUG_PRINTER_ACTIVE
}
// Block LCD menus when
bool __attribute__((noinline)) printer_recovering() {
return (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY);
}
// Currently only used in one place, allowed to be inlined
bool check_fsensor() {
return printJobOngoing()
@ -1622,14 +1628,15 @@ void setup()
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
puts_P(_N("Normal recovery!"));
#endif
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PRINT_TYPE_HOST) {
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == 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);
if ( btn == LCD_LEFT_BUTTON_CHOICE) {
recover_print(0);
} else { // LCD_MIDDLE_BUTTON_CHOICE
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
// Print recovery canceled
cancel_saved_printing();
}
}
}
@ -11054,6 +11061,7 @@ void restore_print_from_ram_and_continue(float e_move)
restore_print_file_state();
lcd_setstatuspgm(MSG_WELCOME);
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY);
saved_printing_type = PowerPanic::PRINT_TYPE_NONE;
saved_printing = false;
planner_aborted = true; // unroll the stack

View File

@ -161,6 +161,11 @@ void uvlo_() {
eeprom_update_word((uint16_t*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL +2*mesh_point), *reinterpret_cast<uint16_t*>(&v));
}
#ifdef DEBUG_UVLO
print_world_coordinates();
print_physical_coordinates();
#endif //End DEBUG_UVLO
// Write the _final_ Z position
eeprom_update_float((float*)EEPROM_UVLO_TINY_CURRENT_POSITION_Z, current_position[Z_AXIS]);
@ -197,8 +202,12 @@ void uvlo_() {
// Increment power failure counter
eeprom_increment_byte((uint8_t*)EEPROM_POWER_COUNT);
eeprom_increment_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
#ifdef DEBUG_UVLO
printf_P(_N("EEPROM_UVLO: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO)));
printf_P(_N("EEPROM_UVLO_PRINT_TYPE: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE)));
#endif //End DEBUG_UVLO
printf_P(_N("UVLO - end %d\n"), _millis() - time_start);
WRITE(BEEPER,HIGH);
// All is set: with all the juice left, try to move extruder away to detach the nozzle completely from the print
@ -233,6 +242,11 @@ static void uvlo_tiny() {
// extruder, causing the Z position to change. Similarly, when recovering, the Z position is
// lowered. In such cases we cannot just save Z, we need to re-align the steppers to a fullstep.
// Disable MBL (if not already) to work with physical coordinates.
#ifdef DEBUG_UVLO
print_world_coordinates();
print_physical_coordinates();
#endif //End DEBUG_UVLO
mbl.active = false;
planner_abort_hard();
@ -269,7 +283,10 @@ static void uvlo_tiny() {
// Increment power failure counter
eeprom_increment_byte((uint8_t*)EEPROM_POWER_COUNT);
eeprom_increment_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
#ifdef DEBUG_UVLO
printf_P(_N("EEPROM_UVLO: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO)));
printf_P(_N("EEPROM_UVLO_PRINT_TYPE: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE)));
#endif //End DEBUG_UVLO
printf_P(_N("UVLO_TINY - end %d\n"), _millis() - time_start);
uvlo_drain_reset();
}
@ -315,13 +332,25 @@ void recover_print(uint8_t automatic) {
// Recover position, temperatures and extrude_multipliers
bool mbl_was_active = recover_machine_state_after_power_panic();
// Lift the print head 25mm, first to avoid collisions with oozed material with the print,
// Lift the print head ONCE plus Z_PAUSE_LIFT, first to avoid collisions with oozed material with the print,
// and second also so one may remove the excess priming material.
#ifdef DEBUG_UVLO
print_world_coordinates();
print_physical_coordinates();
#endif //End DEBUG_UVLO
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PENDING_RECOVERY)
{
enquecommandf_P(PSTR("G1 Z%.3f F800"), current_position[Z_AXIS] + 25);
enquecommandf_P(PSTR("G1 Z%.3f F800"), current_position[Z_AXIS] + Z_PAUSE_LIFT);
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::PENDING_RECOVERY_RETRY);
}
#ifdef DEBUG_UVLO
print_world_coordinates();
print_physical_coordinates();
#endif //End DEBUG_UVLO
// Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine
// transformation status. G28 will not touch Z when MBL is off.
enquecommand_P(PSTR("G28 X Y"));
@ -346,6 +375,10 @@ void recover_print(uint8_t automatic) {
restore_print_from_eeprom(mbl_was_active);
puts_P(_N("Done reading EEPROM\n"));
gcode_M114();
#ifdef DEBUG_UVLO
printf_P(_N("EEPROM_UVLO: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO)));
printf_P(_N("EEPROM_UVLO_PRINT_TYPE: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE)));
#endif //End DEBUG_UVLO
}
bool recover_machine_state_after_power_panic() {
@ -386,8 +419,11 @@ bool recover_machine_state_after_power_panic() {
clamp_to_software_endstops(current_position);
set_destination_to_current();
plan_set_position_curposXYZE();
SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
#ifdef DEBUG_UVLO
SERIAL_ECHOLNPGM("recover_machine_state_after_power_panic, initial ");
print_world_coordinates();
print_physical_coordinates();
#endif //End DEBUG_UVLO
// 6) Power up the Z motors, mark their positions as known.
axis_known_position[Z_AXIS] = true;
@ -411,6 +447,10 @@ bool recover_machine_state_after_power_panic() {
#endif
return mbl_was_active;
#ifdef DEBUG_UVLO
printf_P(_N("EEPROM_UVLO: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO)));
printf_P(_N("EEPROM_UVLO_PRINT_TYPE: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE)));
#endif //End DEBUG_UVLO
}
void restore_print_from_eeprom(bool mbl_was_active) {
@ -478,7 +518,10 @@ void restore_print_from_eeprom(bool mbl_was_active) {
// Set line number
enquecommandf_P(PSTR("M110 N%lu"), position);
}
#ifdef DEBUG_UVLO
printf_P(_N("EEPROM_UVLO: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO)));
printf_P(_N("EEPROM_UVLO_PRINT_TYPE: %d\n"), uint8_t(eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE)));
#endif //End DEBUG_UVLO
enquecommand_P(PSTR("G4 S0"));
enquecommand_P(PSTR("PRUSA uvlo"));
}

View File

@ -5234,7 +5234,7 @@ static void lcd_main_menu()
#endif //TMC2130_DEBUG
// Menu item for reprint
if(!printer_active() && (heating_status == HeatingStatus::NO_HEATING)) {
if(!printer_active() && !printer_recovering() && (heating_status == HeatingStatus::NO_HEATING)) {
if ((GetPrinterState() == PrinterState::SDPrintingFinished) && card.mounted) {
MENU_ITEM_FUNCTION_P(_T(MSG_REPRINT), lcd_reprint_from_eeprom);
} else if ((GetPrinterState() == PrinterState::HostPrintingFinished) && M79_timer_get_status()) {
@ -5249,6 +5249,7 @@ static void lcd_main_menu()
if (farm_mode)
MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
if (!printer_recovering()) {
if ( moves_planned() || printer_active() ) {
MENU_ITEM_SUBMENU_P(_T(MSG_TUNE), lcd_tune_menu);
} else if (!Stopped) {
@ -5268,6 +5269,7 @@ static void lcd_main_menu()
MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);
}
}
}
if(printingIsPaused())
{
// only allow resuming if hardware errors (temperature or fan) are cleared
@ -5297,77 +5299,76 @@ static void lcd_main_menu()
#endif
// only allow starting SD print if hardware errors (temperature or fan) are cleared
if(!get_temp_error()
&& !printer_active()
if (!printer_recovering() && !printer_active()) {
if(!get_temp_error()
#ifdef FANCHECK
&& fan_check_error != EFCE_REPORTED
&& fan_check_error != EFCE_REPORTED
#endif //FANCHECK
)
{
)
{
#ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
if (card.mounted || lcd_commands_type != LcdCommands::Idle) {
if (!card.isFileOpen()) {
if (!usb_timer.running() && (lcd_commands_type == LcdCommands::Idle)) {
bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
}
if (card.mounted || lcd_commands_type != LcdCommands::Idle) {
if (!card.isFileOpen()) {
if (!usb_timer.running() && (lcd_commands_type == LcdCommands::Idle)) {
bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
}
#if SDCARDDETECT < 1
MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user ////MSG_CNG_SDCARD c=18
MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user ////MSG_CNG_SDCARD c=18
#endif //SDCARDDETECT
}
} else {
bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu); ////MSG_NO_CARD c=18
#if SDCARDDETECT < 1
MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface ////MSG_INIT_SDCARD c=18
#endif //SDCARDDETECT
}
} else {
bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu); ////MSG_NO_CARD c=18
#if SDCARDDETECT < 1
MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface ////MSG_INIT_SDCARD c=18
#endif //SDCARDDETECT
}
#endif //SDSUPPORT
}
if(!printer_active() && !farm_mode) {
const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
}
if(!farm_mode) {
const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
#ifdef QUICK_NOZZLE_CHANGE
SETTINGS_NOZZLE;
#endif //QUICK_NOZZLE_CHANGE
}
}
if ( ! ( printer_active() || (eFilamentAction != FilamentAction::None) || Stopped ) ) {
if (MMU2::mmu2.Enabled()) {
if(!MMU2::mmu2.FindaDetectsFilament() && !fsensor.getFilamentPresent()) {
// The MMU 'Load filament' state machine will reject the command if any
// filament sensor is reporting a detected filament
MENU_ITEM_SUBMENU_P(_T(MSG_PRELOAD_TO_MMU), mmu_preload_filament_menu);
}
MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), lcd_mmuLoadFilament);////MSG_LOAD_TO_NOZZLE c=18
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_mmuUnloadFilament);
MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FROM_MMU), lcd_mmuEjectFilament);
if ( ! ((eFilamentAction != FilamentAction::None) || Stopped )) {
if (MMU2::mmu2.Enabled()) {
if(!MMU2::mmu2.FindaDetectsFilament() && !fsensor.getFilamentPresent()) {
// The MMU 'Load filament' state machine will reject the command if any
// filament sensor is reporting a detected filament
MENU_ITEM_SUBMENU_P(_T(MSG_PRELOAD_TO_MMU), mmu_preload_filament_menu);
}
MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), lcd_mmuLoadFilament);////MSG_LOAD_TO_NOZZLE c=18
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_mmuUnloadFilament);
MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FROM_MMU), lcd_mmuEjectFilament);
#ifdef MMU_HAS_CUTTER
if (eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) != 0) {
MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), lcd_mmuCutFilament);
}
if (eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) != 0) {
MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), lcd_mmuCutFilament);
}
#endif //MMU_HAS_CUTTER
} else {
} else {
#ifdef FILAMENT_SENSOR
if (fsensor.isEnabled() && fsensor.getAutoLoadEnabled()) {
MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
}
else
if (fsensor.isEnabled() && fsensor.getAutoLoadEnabled()) {
MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
}
else
#endif //FILAMENT_SENSOR
{
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
{
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
}
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
}
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
if(!printingIsPaused()) MENU_ITEM_SUBMENU_P(_T(MSG_CALIBRATION), lcd_calibration_menu);
}
MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
if(!printingIsPaused()) MENU_ITEM_SUBMENU_P(_T(MSG_CALIBRATION), lcd_calibration_menu);
}
MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
#if defined(TMC2130) || defined(FILAMENT_SENSOR)

View File

@ -128,6 +128,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
#ifdef DEBUG_BUILD
//#define _NO_ASM

View File

@ -129,6 +129,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
#ifdef DEBUG_BUILD
//#define _NO_ASM

View File

@ -128,6 +128,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
#ifdef DEBUG_BUILD
//#define _NO_ASM

View File

@ -129,6 +129,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
#ifdef DEBUG_BUILD
//#define _NO_ASM

View File

@ -167,6 +167,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
//#define DEBUG_XFLASH //debug external spi flash

View File

@ -167,6 +167,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
//#define DEBUG_XFLASH //debug external spi flash

View File

@ -167,6 +167,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
//#define DEBUG_XFLASH //debug external spi flash

View File

@ -169,6 +169,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
//#define DEBUG_XFLASH //debug external spi flash

View File

@ -169,6 +169,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
//#define DEBUG_XFLASH //debug external spi flash

View File

@ -169,6 +169,8 @@
//#define DEBUG_PRINTER_ACTIVE
//#define DEBUG_UVLO
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
//#define DEBUG_XFLASH //debug external spi flash