Fix up E3 DWIN Power Panic

This commit is contained in:
Scott Lahteine 2020-09-27 16:51:16 -05:00
parent de4f882a22
commit bb90bc6165

View File

@ -991,15 +991,15 @@ void Popup_Window_Resume() {
if (HMI_IsChinese()) { if (HMI_IsChinese()) {
DWIN_Frame_AreaCopy(1, 160, 338, 235, 354, 98, 135); DWIN_Frame_AreaCopy(1, 160, 338, 235, 354, 98, 135);
DWIN_Frame_AreaCopy(1, 103, 321, 271, 335, 52, 192); DWIN_Frame_AreaCopy(1, 103, 321, 271, 335, 52, 192);
DWIN_ICON_Show(ICON, ICON_Continue_C, 26, 307); DWIN_ICON_Show(ICON, ICON_Cancel_C, 26, 307);
DWIN_ICON_Show(ICON, ICON_Cancel_C, 146, 307); DWIN_ICON_Show(ICON, ICON_Continue_C, 146, 307);
} }
else { else {
DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, (272 - 8 * 14) / 2, 115, F("Continue Print")); DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, (272 - 8 * 14) / 2, 115, F("Continue Print"));
DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, (272 - 8 * 22) / 2, 192, F("It looks like the last")); DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, (272 - 8 * 22) / 2, 192, F("It looks like the last"));
DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, (272 - 8 * 22) / 2, 212, F("file was interrupted.")); DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, (272 - 8 * 22) / 2, 212, F("file was interrupted."));
DWIN_ICON_Show(ICON, ICON_Continue_E, 26, 307); DWIN_ICON_Show(ICON, ICON_Cancel_E, 26, 307);
DWIN_ICON_Show(ICON, ICON_Cancel_E, 146, 307); DWIN_ICON_Show(ICON, ICON_Continue_E, 146, 307);
} }
} }
@ -3597,45 +3597,30 @@ void EachMomentUpdate() {
#if ENABLED(POWER_LOSS_RECOVERY) #if ENABLED(POWER_LOSS_RECOVERY)
else if (DWIN_lcd_sd_status && recovery.dwin_flag) { // resume print before power off else if (DWIN_lcd_sd_status && recovery.dwin_flag) { // resume print before power off
static bool recovery_flag = false; static bool recovery_flag = false;
recovery.dwin_flag = false; recovery.dwin_flag = false;
recovery_flag = true;
recovery.load();
if (!recovery.valid()) return recovery.purge();
auto draw_first_option = [](const bool sel) {
const uint16_t c1 = sel ? Color_Bg_Window : Select_Color;
DWIN_Draw_Rectangle(0, c1, 25, 306, 126, 345);
DWIN_Draw_Rectangle(0, c1, 24, 305, 127, 346);
};
auto update_selection = [&](const bool sel) { auto update_selection = [&](const bool sel) {
HMI_flag.select_flag = sel; HMI_flag.select_flag = sel;
draw_first_option(sel); const uint16_t c1 = sel ? Color_Bg_Window : Select_Color;
DWIN_Draw_Rectangle(0, c1, 25, 306, 126, 345);
DWIN_Draw_Rectangle(0, c1, 24, 305, 127, 346);
const uint16_t c2 = sel ? Select_Color : Color_Bg_Window; const uint16_t c2 = sel ? Select_Color : Color_Bg_Window;
DWIN_Draw_Rectangle(0, c2, 145, 306, 246, 345); DWIN_Draw_Rectangle(0, c2, 145, 306, 246, 345);
DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346); DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
}; };
const uint16_t fileCnt = card.get_num_Files(); Popup_Window_Resume();
for (uint16_t i = 0; i < fileCnt; i++) { update_selection(true);
// TODO: Resume print via M1000 then update the UI
// with the active filename which can come from CardReader.
card.getfilename_sorted(SD_ORDER(i, fileCnt));
if (!strcmp(card.filename, &recovery.info.sd_filename[1])) { // Resume print before power failure while have the same file
recovery_flag = true;
HMI_flag.select_flag = true;
Popup_Window_Resume();
draw_first_option(false);
char * const name = card.longest_filename();
const int8_t npos = _MAX(0, DWIN_WIDTH - strlen(name) * (MENU_CHR_W)) / 2;
DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, npos, 252, name);
DWIN_UpdateLCD();
break;
}
}
// if hasn't resumable G-code file // TODO: Get the name of the current file from someplace
if (!recovery_flag) return; //
//(void)recovery.interrupted_file_exists();
char * const name = card.longest_filename();
const int8_t npos = _MAX(0U, DWIN_WIDTH - strlen(name) * (MENU_CHR_W)) / 2;
DWIN_Draw_String(false, true, font8x16, Popup_Text_Color, Color_Bg_Window, npos, 252, name);
DWIN_UpdateLCD();
while (recovery_flag) { while (recovery_flag) {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
@ -3643,12 +3628,12 @@ void EachMomentUpdate() {
if (encoder_diffState == ENCODER_DIFF_ENTER) { if (encoder_diffState == ENCODER_DIFF_ENTER) {
recovery_flag = false; recovery_flag = false;
if (HMI_flag.select_flag) break; if (HMI_flag.select_flag) break;
TERN_(POWER_LOSS_RECOVERY, recovery.cancel()); TERN_(POWER_LOSS_RECOVERY, queue.inject_P(PSTR("M1000C")));
HMI_StartFrame(true); HMI_StartFrame(true);
return; return;
} }
else else
update_selection(encoder_diffState == ENCODER_DIFF_CCW); update_selection(encoder_diffState == ENCODER_DIFF_CW);
DWIN_UpdateLCD(); DWIN_UpdateLCD();
} }
@ -3656,9 +3641,9 @@ void EachMomentUpdate() {
select_print.set(0); select_print.set(0);
HMI_ValueStruct.show_mode = 0; HMI_ValueStruct.show_mode = 0;
HMI_StartFrame(false); queue.inject_P(PSTR("M1000"));
recovery.resume(); Goto_PrintProcess();
return; Draw_Status_Area(true);
} }
#endif #endif
DWIN_UpdateLCD(); DWIN_UpdateLCD();