power panic: add readable flags and optimise ISR(INT4_vect)
Add more readable names for the EEPROM_UVLO values Change in memory: Flash: -14 bytes SRAM: 0 bytes
This commit is contained in:
parent
4dc5d97ca9
commit
2cd5ab2349
|
|
@ -1457,7 +1457,7 @@ void setup()
|
||||||
}
|
}
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0);
|
eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0);
|
||||||
}
|
}
|
||||||
eeprom_init_default_byte((uint8_t*)EEPROM_UVLO, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
|
||||||
eeprom_init_default_byte((uint8_t*)EEPROM_SD_SORT, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_SD_SORT, 0);
|
||||||
|
|
||||||
//mbl_mode_init();
|
//mbl_mode_init();
|
||||||
|
|
@ -1578,7 +1578,7 @@ void setup()
|
||||||
fw_crash_init();
|
fw_crash_init();
|
||||||
|
|
||||||
#ifdef UVLO_SUPPORT
|
#ifdef UVLO_SUPPORT
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != 0) { //previous print was terminated by UVLO
|
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != NO_PENDING_RECOVERY) { //previous print was terminated by UVLO
|
||||||
manage_heater(); // Update temperatures
|
manage_heater(); // Update temperatures
|
||||||
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
|
#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));
|
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));
|
||||||
|
|
@ -1596,7 +1596,7 @@ void setup()
|
||||||
if ( lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_RECOVER_PRINT), false) == LCD_LEFT_BUTTON_CHOICE) {
|
if ( lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_RECOVER_PRINT), false) == LCD_LEFT_BUTTON_CHOICE) {
|
||||||
recover_print(0);
|
recover_print(0);
|
||||||
} else {
|
} else {
|
||||||
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0);
|
eeprom_update_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
|
||||||
lcd_update_enable(true);
|
lcd_update_enable(true);
|
||||||
lcd_update(2);
|
lcd_update(2);
|
||||||
lcd_setstatuspgm(MSG_WELCOME);
|
lcd_setstatuspgm(MSG_WELCOME);
|
||||||
|
|
@ -4149,7 +4149,7 @@ void process_commands()
|
||||||
printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]);
|
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
|
else if (code_seen_P(PSTR("uvlo"))) { // PRUSA uvlo
|
||||||
eeprom_update_byte((uint8_t*)EEPROM_UVLO,0);
|
eeprom_update_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
|
||||||
enquecommand_P(MSG_M24);
|
enquecommand_P(MSG_M24);
|
||||||
}
|
}
|
||||||
else if (code_seen_P(PSTR("MMURES"))) // PRUSA MMURES
|
else if (code_seen_P(PSTR("MMURES"))) // PRUSA MMURES
|
||||||
|
|
@ -10660,7 +10660,7 @@ void restore_print_from_ram_and_continue(float e_move)
|
||||||
// Cancel the state related to a currently saved print
|
// Cancel the state related to a currently saved print
|
||||||
void cancel_saved_printing()
|
void cancel_saved_printing()
|
||||||
{
|
{
|
||||||
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0);
|
eeprom_update_byte((uint8_t*)EEPROM_UVLO, NO_PENDING_RECOVERY);
|
||||||
saved_start_position[0] = SAVED_START_POSITION_UNSET;
|
saved_start_position[0] = SAVED_START_POSITION_UNSET;
|
||||||
saved_printing_type = PRINTING_TYPE_NONE;
|
saved_printing_type = PRINTING_TYPE_NONE;
|
||||||
saved_printing = false;
|
saved_printing = false;
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ void uvlo_() {
|
||||||
// Note: Recovering a print from EEPROM currently assumes the user
|
// 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
|
// is printing from an SD card, this is why this EEPROM byte is only set
|
||||||
// when SD card print is detected
|
// when SD card print is detected
|
||||||
if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1);
|
if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, PENDING_RECOVERY);
|
||||||
|
|
||||||
// Increment power failure counter
|
// Increment power failure counter
|
||||||
eeprom_increment_byte((uint8_t*)EEPROM_POWER_COUNT);
|
eeprom_increment_byte((uint8_t*)EEPROM_POWER_COUNT);
|
||||||
|
|
@ -268,7 +268,7 @@ static void uvlo_tiny() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the the "power outage" flag.
|
// Update the the "power outage" flag.
|
||||||
eeprom_update_byte((uint8_t*)EEPROM_UVLO,2);
|
eeprom_update_byte((uint8_t*)EEPROM_UVLO, PENDING_RECOVERY_RETRY);
|
||||||
|
|
||||||
// Increment power failure counter
|
// Increment power failure counter
|
||||||
eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
|
eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
|
||||||
|
|
@ -290,7 +290,7 @@ void setup_uvlo_interrupt() {
|
||||||
EIMSK |= (1 << 4);
|
EIMSK |= (1 << 4);
|
||||||
|
|
||||||
// check if power was lost before we armed the interrupt
|
// check if power was lost before we armed the interrupt
|
||||||
if(!(PINE & (1 << 4)) && eeprom_read_byte((uint8_t*)EEPROM_UVLO))
|
if(!(PINE & (1 << 4)) && eeprom_read_byte((uint8_t*)EEPROM_UVLO) != NO_PENDING_RECOVERY)
|
||||||
{
|
{
|
||||||
SERIAL_ECHOLNRPGM(MSG_INT4);
|
SERIAL_ECHOLNRPGM(MSG_INT4);
|
||||||
uvlo_drain_reset();
|
uvlo_drain_reset();
|
||||||
|
|
@ -300,9 +300,17 @@ void setup_uvlo_interrupt() {
|
||||||
ISR(INT4_vect) {
|
ISR(INT4_vect) {
|
||||||
EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once
|
EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once
|
||||||
SERIAL_ECHOLNRPGM(MSG_INT4);
|
SERIAL_ECHOLNRPGM(MSG_INT4);
|
||||||
//fire normal uvlo only in case where EEPROM_UVLO is 0 or if IS_SD_PRINTING is 1.
|
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == NO_PENDING_RECOVERY)
|
||||||
if(printer_active() && (!(eeprom_read_byte((uint8_t*)EEPROM_UVLO)))) uvlo_();
|
{
|
||||||
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)) uvlo_tiny();
|
if(printer_active()) {
|
||||||
|
uvlo_();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// There is already a pending recovery waiting. Power outage in this scenario
|
||||||
|
// arrives before we can fully recover the print. In that case call a 'tiny'
|
||||||
|
// version of uvlo_() which doesn't overwrite the print state already waiting in EEPROM
|
||||||
|
uvlo_tiny();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void recover_print(uint8_t automatic) {
|
void recover_print(uint8_t automatic) {
|
||||||
|
|
@ -315,7 +323,7 @@ void recover_print(uint8_t automatic) {
|
||||||
|
|
||||||
// Lift the print head 25mm, first to avoid collisions with oozed material with the print,
|
// 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.
|
// and second also so one may remove the excess priming material.
|
||||||
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1)
|
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 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] + 25);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
void uvlo_();
|
void uvlo_();
|
||||||
void recover_print(uint8_t automatic);
|
void recover_print(uint8_t automatic);
|
||||||
void setup_uvlo_interrupt();
|
void setup_uvlo_interrupt();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue