Skip to content

Commit

Permalink
Fix MKS LVGL UI Main screen / print buttons (MarlinFirmware#21468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malderin authored and W4tel-BiDi committed Apr 5, 2021
1 parent 03e5f13 commit 8eb6835
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void lv_draw_dialog(uint8_t type) {

void filament_sprayer_temp() {
char buf[20] = {0};
sprintf(buf, preheat_menu.value_state, (int)thermalManager.degHotend(uiCfg.extruderIndex), (int)thermalManager.degTargetHotend(uiCfg.extruderIndex));
sprintf(buf, preheat_menu.value_state, thermalManager.degHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));

strcpy(public_buf_l, uiCfg.extruderIndex < 1 ? extrude_menu.ext1 : extrude_menu.ext2);
strcat_P(public_buf_l, PSTR(": "));
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void disp_ext_speed() {

void disp_hotend_temp() {
char buf[20] = {0};
sprintf(buf, extrude_menu.temp_value, (int)thermalManager.degHotend(uiCfg.extruderIndex), (int)thermalManager.degTargetHotend(uiCfg.extruderIndex));
sprintf(buf, extrude_menu.temp_value, thermalManager.degHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));
strcpy(public_buf_l, extrude_menu.temper_text);
strcat(public_buf_l, buf);
lv_label_set_text(tempText, public_buf_l);
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
switch (obj->mks_obj_id) {
case ID_FILAMNT_IN:
uiCfg.filament_load_heat_flg = true;
if ((abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex)) <= 1)
|| (gCfgItems.filament_limit_temp <= thermalManager.degHotend(uiCfg.extruderIndex))) {
if (abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex)) <= 1
|| gCfgItems.filament_limit_temp <= thermalManager.degHotend(uiCfg.extruderIndex)) {
lv_clear_filament_change();
lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED);
}
Expand All @@ -67,8 +67,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_FILAMNT_OUT:
uiCfg.filament_unload_heat_flg = true;
if (thermalManager.degTargetHotend(uiCfg.extruderIndex)
&& ((abs((int)((int)thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex))) <= 1)
|| ((int)thermalManager.degHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp))
&& (abs((int)(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex))) <= 1
|| thermalManager.degHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp)
) {
lv_clear_filament_change();
lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED);
Expand Down Expand Up @@ -154,7 +154,7 @@ void disp_filament_temp() {
public_buf_l[0] = '\0';

strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2);
sprintf(buf, preheat_menu.value_state, (int)thermalManager.degHotend(uiCfg.extruderIndex), (int)thermalManager.degTargetHotend(uiCfg.extruderIndex));
sprintf(buf, preheat_menu.value_state, thermalManager.degHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));

strcat_P(public_buf_l, PSTR(": "));
strcat(public_buf_l, buf);
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {

case ID_P_DEC:
if (uiCfg.curTempType == 0) {
if ((int)thermalManager.degTargetHotend(uiCfg.extruderIndex) > uiCfg.stepHeat)
if (thermalManager.degTargetHotend(uiCfg.extruderIndex) > uiCfg.stepHeat)
thermalManager.temp_hotend[uiCfg.extruderIndex].target -= uiCfg.stepHeat;
else
thermalManager.setTargetHotend(0, uiCfg.extruderIndex);
thermalManager.start_watching_hotend(uiCfg.extruderIndex);
}
#if HAS_HEATED_BED
else {
if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat)
if (thermalManager.degTargetBed() > uiCfg.stepHeat)
thermalManager.temp_bed.target -= uiCfg.stepHeat;
else
thermalManager.setTargetBed(0);
Expand Down Expand Up @@ -217,12 +217,12 @@ void disp_desire_temp() {

if (uiCfg.curTempType == 0) {
strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2);
sprintf(buf, preheat_menu.value_state, (int)thermalManager.degHotend(uiCfg.extruderIndex), (int)thermalManager.degTargetHotend(uiCfg.extruderIndex));
sprintf(buf, preheat_menu.value_state, thermalManager.degHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));
}
#if HAS_HEATED_BED
else {
strcat(public_buf_l, preheat_menu.hotbed);
sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target);
sprintf(buf, preheat_menu.value_state, thermalManager.degBed(), thermalManager.degTargetBed());
}
#endif
strcat_P(public_buf_l, PSTR(": "));
Expand Down
58 changes: 36 additions & 22 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static lv_obj_t *scr;
static lv_obj_t *labelExt1, *labelFan, *labelZpos, *labelTime;
static lv_obj_t *labelPause, *labelStop, *labelOperat;
static lv_obj_t *bar1, *bar1ValueText;
static lv_obj_t *buttonPause, *buttonOperat, *buttonStop;
static lv_obj_t *buttonPause, *buttonOperat, *buttonStop, *buttonExt1, *buttonExt2, *buttonBedstate, *buttonFanstate, *buttonZpos;

#if ENABLED(HAS_MULTI_EXTRUDER)
static lv_obj_t *labelExt2;
Expand All @@ -60,7 +60,11 @@ static lv_obj_t *buttonPause, *buttonOperat, *buttonStop;
enum {
ID_PAUSE = 1,
ID_STOP,
ID_OPTION
ID_OPTION,
ID_TEMP_EXT,
ID_TEMP_BED,
ID_BABYSTEP,
ID_FAN
};

bool once_flag; // = false
Expand Down Expand Up @@ -100,7 +104,6 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
}
#endif
break;

case ID_STOP:
lv_clear_printing();
lv_draw_dialog(DIALOG_TYPE_STOP);
Expand All @@ -109,6 +112,24 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
lv_clear_printing();
lv_draw_operation();
break;
case ID_TEMP_EXT:
uiCfg.curTempType = 0;
lv_clear_printing();
lv_draw_preHeat();
break;
case ID_TEMP_BED:
uiCfg.curTempType = 1;
lv_clear_printing();
lv_draw_preHeat();
break;
case ID_BABYSTEP:
lv_clear_printing();
lv_draw_baby_stepping();
break;
case ID_FAN:
lv_clear_printing();
lv_draw_fan();
break;
}
}

Expand All @@ -118,33 +139,23 @@ void lv_draw_printing() {
scr = lv_screen_create(PRINTING_UI);

// Create image buttons
lv_obj_t *buttonExt1 = lv_img_create(scr, nullptr);
lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin");
lv_obj_set_pos(buttonExt1, 205, 136);
buttonExt1 = lv_imgbtn_create(scr, "F:/bmp_ext1_state.bin", 206, 136, event_handler, ID_TEMP_EXT);

#if HAS_MULTI_EXTRUDER
lv_obj_t *buttonExt2 = lv_img_create(scr, nullptr);
lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin");
lv_obj_set_pos(buttonExt2, 350, 136);
buttonExt2 = lv_imgbtn_create(scr, "F:/bmp_ext2_state.bin", 350, 136, event_handler, ID_TEMP_EXT);
#endif

#if HAS_HEATED_BED
lv_obj_t *buttonBedstate = lv_img_create(scr, nullptr);
lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin");
lv_obj_set_pos(buttonBedstate, 205, 186);
buttonBedstate = lv_imgbtn_create(scr, "F:/bmp_bed_state.bin", 206, 186, event_handler, ID_TEMP_BED);
#endif

lv_obj_t *buttonFanstate = lv_img_create(scr, nullptr);
lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin");
lv_obj_set_pos(buttonFanstate, 350, 186);
buttonFanstate = lv_imgbtn_create(scr, "F:/bmp_fan_state.bin", 350, 186, event_handler, ID_FAN);

lv_obj_t *buttonTime = lv_img_create(scr, nullptr);
lv_img_set_src(buttonTime, "F:/bmp_time_state.bin");
lv_obj_set_pos(buttonTime, 205, 86);
lv_obj_set_pos(buttonTime, 206, 86);

lv_obj_t *buttonZpos = lv_img_create(scr, nullptr);
lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin");
lv_obj_set_pos(buttonZpos, 350, 86);
buttonZpos = lv_imgbtn_create(scr, "F:/bmp_zpos_state.bin", 350, 86, event_handler, ID_BABYSTEP);

buttonPause = lv_imgbtn_create(scr, uiCfg.print_state == WORKING ? "F:/bmp_pause.bin" : "F:/bmp_resume.bin", 5, 240, event_handler, ID_PAUSE);
buttonStop = lv_imgbtn_create(scr, "F:/bmp_stop.bin", 165, 240, event_handler, ID_STOP);
Expand All @@ -155,6 +166,9 @@ void lv_draw_printing() {
lv_group_add_obj(g, buttonPause);
lv_group_add_obj(g, buttonStop);
lv_group_add_obj(g, buttonOperat);
lv_group_add_obj(g, buttonPause);
lv_group_add_obj(g, buttonPause);
lv_group_add_obj(g, buttonPause);
}
#endif

Expand Down Expand Up @@ -205,18 +219,18 @@ void lv_draw_printing() {
}

void disp_ext_temp() {
sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.degHotend(0), (int)thermalManager.degTargetHotend(0));
sprintf(public_buf_l, printing_menu.temp1, thermalManager.degHotend(0), thermalManager.degTargetHotend(0));
lv_label_set_text(labelExt1, public_buf_l);

#if HAS_MULTI_EXTRUDER
sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.degHotend(1), (int)thermalManager.degTargetHotend(1));
sprintf(public_buf_l, printing_menu.temp1, thermalManager.degHotend(1), thermalManager.degTargetHotend(1));
lv_label_set_text(labelExt2, public_buf_l);
#endif
}

void disp_bed_temp() {
#if HAS_HEATED_BED
sprintf(public_buf_l, printing_menu.bed_temp, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target);
sprintf(public_buf_l, printing_menu.bed_temp, thermalManager.degBed(), thermalManager.degTargetBed());
lv_label_set_text(labelBed, public_buf_l);
#endif
}
Expand Down
46 changes: 23 additions & 23 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ static lv_obj_t *labelExt1, *labelExt1Target, *labelFan;
uint8_t curent_disp_ui = 0;
#endif

enum { ID_TOOL = 1, ID_SET, ID_PRINT };
enum { ID_TOOL = 1, ID_SET, ID_PRINT, ID_INFO_EXT, ID_INFO_BED, ID_INFO_FAN };

static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
lv_clear_ready_print();
switch (obj->mks_obj_id) {
case ID_TOOL: lv_draw_tool(); break;
case ID_SET: lv_draw_set(); break;
case ID_INFO_EXT: uiCfg.curTempType = 0; lv_draw_preHeat(); break;
case ID_INFO_BED: uiCfg.curTempType = 1; lv_draw_preHeat(); break;
case ID_INFO_FAN: lv_draw_fan(); break;
case ID_PRINT: lv_draw_print_file(); break;
}
}
Expand Down Expand Up @@ -181,32 +184,14 @@ void lv_draw_ready_print() {
lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 180, event_handler, ID_PRINT);

// Monitoring
lv_obj_t *buttonExt1 = lv_img_create(scr, NULL);
lv_obj_t *buttonExt1 = lv_big_button_create(scr, "F:/bmp_ext1_state.bin", " ", 55, ICON_POS_Y, event_handler, ID_INFO_EXT);
#if HAS_MULTI_EXTRUDER
lv_obj_t *buttonExt2 = lv_img_create(scr, NULL);
lv_obj_t *buttonExt2 = lv_big_button_create(scr, "F:/bmp_ext2_state.bin", " ", 55, ICON_POS_Y + SECOND_EXT_MOD_Y, event_handler, ID_INFO_EXT);
#endif
#if HAS_HEATED_BED
lv_obj_t *buttonBedstate = lv_img_create(scr, NULL);
lv_obj_t *buttonBedstate = lv_big_button_create(scr, "F:/bmp_bed_state.bin", " ", 210, ICON_POS_Y, event_handler, ID_INFO_BED);
#endif
lv_obj_t *buttonFanstate = lv_img_create(scr, NULL);

lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin");
#if HAS_MULTI_EXTRUDER
lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin");
#endif
#if HAS_HEATED_BED
lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin");
#endif
lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin");

lv_obj_set_pos(buttonExt1, 55, ICON_POS_Y);
#if HAS_MULTI_EXTRUDER
lv_obj_set_pos(buttonExt2, 55, ICON_POS_Y + SECOND_EXT_MOD_Y);
#endif
#if HAS_HEATED_BED
lv_obj_set_pos(buttonBedstate, 210, ICON_POS_Y);
#endif
lv_obj_set_pos(buttonFanstate, 380, ICON_POS_Y);
lv_obj_t *buttonFanstate = lv_big_button_create(scr, "F:/bmp_fan_state.bin", " ", 380, ICON_POS_Y, event_handler, ID_INFO_FAN);

labelExt1 = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr);
labelExt1Target = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr);
Expand Down Expand Up @@ -262,6 +247,21 @@ void lv_draw_ready_print() {
#endif
}

void lv_temp_refr() {
#if HAS_HEATED_BED
sprintf(public_buf_l, printing_menu.bed_temp, thermalManager.degBed(), thermalManager.degTargetBed());
lv_label_set_text(labelBed, public_buf_l);
#endif

sprintf(public_buf_l, printing_menu.temp1, thermalManager.degHotend(0), thermalManager.degTargetHotend(0));
lv_label_set_text(labelExt1, public_buf_l);

#if HAS_MULTI_EXTRUDER
sprintf(public_buf_l, printing_menu.temp1, thermalManager.degHotend(1), thermalManager.degTargetHotend(1));
lv_label_set_text(labelExt2, public_buf_l);
#endif
}

void lv_clear_ready_print() {
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern void disp_Limit_error();
extern void disp_det_error();
extern void disp_det_ok();
extern void lv_clear_ready_print();
extern void lv_temp_refr();

#ifdef __cplusplus
} /* C-declarations for C++ */
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,10 @@ void GUI_RefreshPage() {
}
break;
case PRINT_READY_UI:
if (temps_update_flag) {
temps_update_flag = false;
lv_temp_refr();
}
break;

case PRINT_FILE_UI: break;
Expand Down Expand Up @@ -843,8 +847,8 @@ void GUI_RefreshPage() {
#if ENABLED(MKS_WIFI_MODULE)
case WIFI_UI:
if (temps_update_flag) {
disp_wifi_state();
temps_update_flag = false;
disp_wifi_state();
}
break;

Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,9 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
strcpy_P(outBuf, PSTR(" B:"));
outBuf += 3;
#if HAS_HEATED_BED
strcpy(outBuf, dtostrf(thermalManager.temp_bed.celsius, 1, 1, str_1));
strcpy(outBuf, dtostrf(thermalManager.degBed(), 1, 1, str_1));
strcat_P(outBuf, PSTR(" /"));
strcat(outBuf, dtostrf(thermalManager.temp_bed.target, 1, 1, str_1));
strcat(outBuf, dtostrf(thermalManager.degTargetBed(), 1, 1, str_1));
#else
strcpy_P(outBuf, PSTR("0 /0"));
#endif
Expand All @@ -924,15 +924,15 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
}
else {
sprintf_P((char *)tempBuf, PSTR("T:%d /%d B:%d /%d T0:%d /%d T1:%d /%d @:0 B@:0\r\n"),
(int)thermalManager.degHotend(0), (int)thermalManager.degTargetHotend(0),
thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
#if HAS_HEATED_BED
(int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target,
thermalManager.degBed(), thermalManager.degTargetBed(),
#else
0, 0,
#endif
(int)thermalManager.degHotend(0), (int)thermalManager.degTargetHotend(0),
thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
#if HAS_MULTI_HOTEND
(int)thermalManager.degHotend(1), (int)thermalManager.degTargetHotend(1)
thermalManager.degHotend(1), thermalManager.degTargetHotend(1)
#else
0, 0
#endif
Expand Down

0 comments on commit 8eb6835

Please sign in to comment.