Fix MKS LVGL UI Main screen / print buttons (#21468)

This commit is contained in:
Malderin 2021-03-29 11:19:38 +03:00 committed by Scott Lahteine
parent 3ed4503c30
commit 627331aa68
9 changed files with 82 additions and 63 deletions

View file

@ -486,7 +486,7 @@ void lv_draw_dialog(uint8_t type) {
void filament_sprayer_temp() { void filament_sprayer_temp() {
char buf[20] = {0}; 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); strcpy(public_buf_l, uiCfg.extruderIndex < 1 ? extrude_menu.ext1 : extrude_menu.ext2);
strcat_P(public_buf_l, PSTR(": ")); strcat_P(public_buf_l, PSTR(": "));

View file

@ -195,7 +195,7 @@ void disp_ext_speed() {
void disp_hotend_temp() { void disp_hotend_temp() {
char buf[20] = {0}; 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); strcpy(public_buf_l, extrude_menu.temper_text);
strcat(public_buf_l, buf); strcat(public_buf_l, buf);
lv_label_set_text(tempText, public_buf_l); lv_label_set_text(tempText, public_buf_l);

View file

@ -50,8 +50,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
switch (obj->mks_obj_id) { switch (obj->mks_obj_id) {
case ID_FILAMNT_IN: case ID_FILAMNT_IN:
uiCfg.filament_load_heat_flg = true; uiCfg.filament_load_heat_flg = true;
if ((abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex)) <= 1) if (abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex)) <= 1
|| (gCfgItems.filament_limit_temp <= thermalManager.degHotend(uiCfg.extruderIndex))) { || gCfgItems.filament_limit_temp <= thermalManager.degHotend(uiCfg.extruderIndex)) {
lv_clear_filament_change(); lv_clear_filament_change();
lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED);
} }
@ -67,8 +67,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_FILAMNT_OUT: case ID_FILAMNT_OUT:
uiCfg.filament_unload_heat_flg = true; uiCfg.filament_unload_heat_flg = true;
if (thermalManager.degTargetHotend(uiCfg.extruderIndex) if (thermalManager.degTargetHotend(uiCfg.extruderIndex)
&& ((abs((int)((int)thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex))) <= 1) && (abs((int)(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex))) <= 1
|| ((int)thermalManager.degHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp)) || thermalManager.degHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp)
) { ) {
lv_clear_filament_change(); lv_clear_filament_change();
lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED);
@ -154,7 +154,7 @@ void disp_filament_temp() {
public_buf_l[0] = '\0'; public_buf_l[0] = '\0';
strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2); 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_P(public_buf_l, PSTR(": "));
strcat(public_buf_l, buf); strcat(public_buf_l, buf);

View file

@ -76,7 +76,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_P_DEC: case ID_P_DEC:
if (uiCfg.curTempType == 0) { 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; thermalManager.temp_hotend[uiCfg.extruderIndex].target -= uiCfg.stepHeat;
else else
thermalManager.setTargetHotend(0, uiCfg.extruderIndex); thermalManager.setTargetHotend(0, uiCfg.extruderIndex);
@ -84,7 +84,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
} }
#if HAS_HEATED_BED #if HAS_HEATED_BED
else { else {
if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat) if (thermalManager.degTargetBed() > uiCfg.stepHeat)
thermalManager.temp_bed.target -= uiCfg.stepHeat; thermalManager.temp_bed.target -= uiCfg.stepHeat;
else else
thermalManager.setTargetBed(0); thermalManager.setTargetBed(0);
@ -217,12 +217,12 @@ void disp_desire_temp() {
if (uiCfg.curTempType == 0) { if (uiCfg.curTempType == 0) {
strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2); 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 #if HAS_HEATED_BED
else { else {
strcat(public_buf_l, preheat_menu.hotbed); 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 #endif
strcat_P(public_buf_l, PSTR(": ")); strcat_P(public_buf_l, PSTR(": "));

View file

@ -47,7 +47,7 @@ static lv_obj_t *scr;
static lv_obj_t *labelExt1, *labelFan, *labelZpos, *labelTime; static lv_obj_t *labelExt1, *labelFan, *labelZpos, *labelTime;
static lv_obj_t *labelPause, *labelStop, *labelOperat; static lv_obj_t *labelPause, *labelStop, *labelOperat;
static lv_obj_t *bar1, *bar1ValueText; 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) #if ENABLED(HAS_MULTI_EXTRUDER)
static lv_obj_t *labelExt2; static lv_obj_t *labelExt2;
@ -60,7 +60,11 @@ static lv_obj_t *buttonPause, *buttonOperat, *buttonStop;
enum { enum {
ID_PAUSE = 1, ID_PAUSE = 1,
ID_STOP, ID_STOP,
ID_OPTION ID_OPTION,
ID_TEMP_EXT,
ID_TEMP_BED,
ID_BABYSTEP,
ID_FAN
}; };
bool once_flag; // = false bool once_flag; // = false
@ -100,7 +104,6 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
} }
#endif #endif
break; break;
case ID_STOP: case ID_STOP:
lv_clear_printing(); lv_clear_printing();
lv_draw_dialog(DIALOG_TYPE_STOP); lv_draw_dialog(DIALOG_TYPE_STOP);
@ -109,6 +112,24 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
lv_clear_printing(); lv_clear_printing();
lv_draw_operation(); lv_draw_operation();
break; 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;
} }
} }
@ -118,33 +139,23 @@ void lv_draw_printing() {
scr = lv_screen_create(PRINTING_UI); scr = lv_screen_create(PRINTING_UI);
// Create image buttons // Create image buttons
lv_obj_t *buttonExt1 = lv_img_create(scr, nullptr); buttonExt1 = lv_imgbtn_create(scr, "F:/bmp_ext1_state.bin", 206, 136, event_handler, ID_TEMP_EXT);
lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin");
lv_obj_set_pos(buttonExt1, 205, 136);
#if HAS_MULTI_EXTRUDER #if HAS_MULTI_EXTRUDER
lv_obj_t *buttonExt2 = lv_img_create(scr, nullptr); buttonExt2 = lv_imgbtn_create(scr, "F:/bmp_ext2_state.bin", 350, 136, event_handler, ID_TEMP_EXT);
lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin");
lv_obj_set_pos(buttonExt2, 350, 136);
#endif #endif
#if HAS_HEATED_BED #if HAS_HEATED_BED
lv_obj_t *buttonBedstate = lv_img_create(scr, nullptr); buttonBedstate = lv_imgbtn_create(scr, "F:/bmp_bed_state.bin", 206, 186, event_handler, ID_TEMP_BED);
lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin");
lv_obj_set_pos(buttonBedstate, 205, 186);
#endif #endif
lv_obj_t *buttonFanstate = lv_img_create(scr, nullptr); buttonFanstate = lv_imgbtn_create(scr, "F:/bmp_fan_state.bin", 350, 186, event_handler, ID_FAN);
lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin");
lv_obj_set_pos(buttonFanstate, 350, 186);
lv_obj_t *buttonTime = lv_img_create(scr, nullptr); lv_obj_t *buttonTime = lv_img_create(scr, nullptr);
lv_img_set_src(buttonTime, "F:/bmp_time_state.bin"); 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); buttonZpos = lv_imgbtn_create(scr, "F:/bmp_zpos_state.bin", 350, 86, event_handler, ID_BABYSTEP);
lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin");
lv_obj_set_pos(buttonZpos, 350, 86);
buttonPause = lv_imgbtn_create(scr, uiCfg.print_state == WORKING ? "F:/bmp_pause.bin" : "F:/bmp_resume.bin", 5, 240, event_handler, ID_PAUSE); 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); buttonStop = lv_imgbtn_create(scr, "F:/bmp_stop.bin", 165, 240, event_handler, ID_STOP);
@ -155,6 +166,9 @@ void lv_draw_printing() {
lv_group_add_obj(g, buttonPause); lv_group_add_obj(g, buttonPause);
lv_group_add_obj(g, buttonStop); lv_group_add_obj(g, buttonStop);
lv_group_add_obj(g, buttonOperat); 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 #endif
@ -205,18 +219,18 @@ void lv_draw_printing() {
} }
void disp_ext_temp() { 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); lv_label_set_text(labelExt1, public_buf_l);
#if HAS_MULTI_EXTRUDER #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); lv_label_set_text(labelExt2, public_buf_l);
#endif #endif
} }
void disp_bed_temp() { void disp_bed_temp() {
#if HAS_HEATED_BED #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); lv_label_set_text(labelBed, public_buf_l);
#endif #endif
} }

View file

@ -63,7 +63,7 @@ static lv_obj_t *labelExt1, *labelExt1Target, *labelFan;
uint8_t curent_disp_ui = 0; uint8_t curent_disp_ui = 0;
#endif #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) { static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return; if (event != LV_EVENT_RELEASED) return;
@ -71,6 +71,9 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
switch (obj->mks_obj_id) { switch (obj->mks_obj_id) {
case ID_TOOL: lv_draw_tool(); break; case ID_TOOL: lv_draw_tool(); break;
case ID_SET: lv_draw_set(); 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; case ID_PRINT: lv_draw_print_file(); break;
} }
} }
@ -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); lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 180, event_handler, ID_PRINT);
// Monitoring // 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 #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 #endif
#if HAS_HEATED_BED #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 #endif
lv_obj_t *buttonFanstate = lv_img_create(scr, NULL); lv_obj_t *buttonFanstate = lv_big_button_create(scr, "F:/bmp_fan_state.bin", " ", 380, ICON_POS_Y, event_handler, ID_INFO_FAN);
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);
labelExt1 = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr); labelExt1 = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr);
labelExt1Target = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr); labelExt1Target = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr);
@ -262,6 +247,21 @@ void lv_draw_ready_print() {
#endif #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() { void lv_clear_ready_print() {
#if HAS_ROTARY_ENCODER #if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g); if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);

View file

@ -32,6 +32,7 @@ extern void disp_Limit_error();
extern void disp_det_error(); extern void disp_det_error();
extern void disp_det_ok(); extern void disp_det_ok();
extern void lv_clear_ready_print(); extern void lv_clear_ready_print();
extern void lv_temp_refr();
#ifdef __cplusplus #ifdef __cplusplus
} /* C-declarations for C++ */ } /* C-declarations for C++ */

View file

@ -805,6 +805,10 @@ void GUI_RefreshPage() {
} }
break; break;
case PRINT_READY_UI: case PRINT_READY_UI:
if (temps_update_flag) {
temps_update_flag = false;
lv_temp_refr();
}
break; break;
case PRINT_FILE_UI: break; case PRINT_FILE_UI: break;
@ -843,8 +847,8 @@ void GUI_RefreshPage() {
#if ENABLED(MKS_WIFI_MODULE) #if ENABLED(MKS_WIFI_MODULE)
case WIFI_UI: case WIFI_UI:
if (temps_update_flag) { if (temps_update_flag) {
disp_wifi_state();
temps_update_flag = false; temps_update_flag = false;
disp_wifi_state();
} }
break; break;

View file

@ -897,9 +897,9 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
strcpy_P(outBuf, PSTR(" B:")); strcpy_P(outBuf, PSTR(" B:"));
outBuf += 3; outBuf += 3;
#if HAS_HEATED_BED #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_P(outBuf, PSTR(" /"));
strcat(outBuf, dtostrf(thermalManager.temp_bed.target, 1, 1, str_1)); strcat(outBuf, dtostrf(thermalManager.degTargetBed(), 1, 1, str_1));
#else #else
strcpy_P(outBuf, PSTR("0 /0")); strcpy_P(outBuf, PSTR("0 /0"));
#endif #endif
@ -924,15 +924,15 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
} }
else { else {
sprintf_P((char *)tempBuf, PSTR("T:%d /%d B:%d /%d T0:%d /%d T1:%d /%d @:0 B@:0\r\n"), 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 #if HAS_HEATED_BED
(int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target, thermalManager.degBed(), thermalManager.degTargetBed(),
#else #else
0, 0, 0, 0,
#endif #endif
(int)thermalManager.degHotend(0), (int)thermalManager.degTargetHotend(0), thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
#if HAS_MULTI_HOTEND #if HAS_MULTI_HOTEND
(int)thermalManager.degHotend(1), (int)thermalManager.degTargetHotend(1) thermalManager.degHotend(1), thermalManager.degTargetHotend(1)
#else #else
0, 0 0, 0
#endif #endif