Skip to content

Commit

Permalink
Fix up E3 DWIN Power Panic
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and vgadreau committed Dec 9, 2020
1 parent 2fe7ed2 commit b8429b2
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions Marlin/src/lcd/dwin/e3v2/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,15 +991,15 @@ void Popup_Window_Resume() {
if (HMI_IsChinese()) {
DWIN_Frame_AreaCopy(1, 160, 338, 235, 354, 98, 135);
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, 146, 307);
DWIN_ICON_Show(ICON, ICON_Cancel_C, 26, 307);
DWIN_ICON_Show(ICON, ICON_Continue_C, 146, 307);
}
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 * 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_ICON_Show(ICON, ICON_Continue_E, 26, 307);
DWIN_ICON_Show(ICON, ICON_Cancel_E, 146, 307);
DWIN_ICON_Show(ICON, ICON_Cancel_E, 26, 307);
DWIN_ICON_Show(ICON, ICON_Continue_E, 146, 307);
}
}

Expand Down Expand Up @@ -3597,68 +3597,53 @@ void EachMomentUpdate() {
#if ENABLED(POWER_LOSS_RECOVERY)
else if (DWIN_lcd_sd_status && recovery.dwin_flag) { // resume print before power off
static bool recovery_flag = false;
recovery.dwin_flag = false;

recovery.load();
if (!recovery.valid()) return recovery.purge();
recovery.dwin_flag = false;
recovery_flag = true;

auto draw_first_option = [](const bool sel) {
auto update_selection = [&](const bool sel) {
HMI_flag.select_flag = 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) {
HMI_flag.select_flag = sel;
draw_first_option(sel);
const uint16_t c2 = sel ? Select_Color : Color_Bg_Window;
DWIN_Draw_Rectangle(0, c2, 145, 306, 246, 345);
DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
};

const uint16_t fileCnt = card.get_num_Files();
for (uint16_t i = 0; i < fileCnt; i++) {
// 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;
}
}
Popup_Window_Resume();
update_selection(true);

// if hasn't resumable G-code file
if (!recovery_flag) return;
// TODO: Get the name of the current file from someplace
//
//(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) {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState != ENCODER_DIFF_NO) {
if (encoder_diffState == ENCODER_DIFF_ENTER) {
recovery_flag = false;
if (HMI_flag.select_flag) break;
TERN_(POWER_LOSS_RECOVERY, recovery.cancel());
TERN_(POWER_LOSS_RECOVERY, queue.inject_P(PSTR("M1000C")));
HMI_StartFrame(true);
return;
}
else
update_selection(encoder_diffState == ENCODER_DIFF_CCW);
update_selection(encoder_diffState == ENCODER_DIFF_CW);

DWIN_UpdateLCD();
}
}

select_print.set(0);
HMI_ValueStruct.show_mode = 0;
HMI_StartFrame(false);
recovery.resume();
return;
queue.inject_P(PSTR("M1000"));
Goto_PrintProcess();
Draw_Status_Area(true);
}
#endif
DWIN_UpdateLCD();
Expand Down

0 comments on commit b8429b2

Please sign in to comment.