Browse Source

Add "more" menu in LVGL interface (#20940)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
vanilla_fb_2.0.x
Malderin 4 years ago
committed by Scott Lahteine
parent
commit
129e9151da
  1. 3
      Marlin/Configuration_adv.h
  2. 98
      Marlin/src/lcd/extui/lib/mks_ui/draw_more.cpp
  3. 4
      Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp

3
Marlin/Configuration_adv.h

@ -3342,7 +3342,8 @@
#endif
/**
* User-defined menu items that execute custom GCode
* User-defined menu items to run custom G-code.
* Up to 25 may be defined, but the actual number is LCD-dependent.
*/
//#define CUSTOM_USER_MENUS
#if ENABLED(CUSTOM_USER_MENUS)

98
Marlin/src/lcd/extui/lib/mks_ui/draw_more.cpp

@ -33,14 +33,28 @@
extern lv_group_t * g;
static lv_obj_t * scr;
#define HAS_USER_ITEM(N) (ENABLED(CUSTOM_USER_MENUS) && defined(USER_DESC_##N) && defined(USER_GCODE_##N))
enum {
ID_GCODE = 1,
ID_CUSTOM_1,
ID_CUSTOM_2,
ID_CUSTOM_3,
ID_CUSTOM_4,
ID_CUSTOM_5,
ID_CUSTOM_6,
#if HAS_USER_ITEM(1)
ID_CUSTOM_1,
#endif
#if HAS_USER_ITEM(2)
ID_CUSTOM_2,
#endif
#if HAS_USER_ITEM(3)
ID_CUSTOM_3,
#endif
#if HAS_USER_ITEM(4)
ID_CUSTOM_4,
#endif
#if HAS_USER_ITEM(5)
ID_CUSTOM_5,
#endif
#if HAS_USER_ITEM(6)
ID_CUSTOM_6,
#endif
ID_M_RETURN,
};
@ -48,12 +62,24 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
switch (obj->mks_obj_id) {
case ID_GCODE: lv_clear_more(); lv_draw_gcode(true); break;
case ID_CUSTOM_1: TERN_(USER_CMD_1_ENABLE, queue.inject_P(PSTR(USER_GCODE_1))); break;
case ID_CUSTOM_2: TERN_(USER_CMD_2_ENABLE, queue.inject_P(PSTR(USER_GCODE_2))); break;
case ID_CUSTOM_3: TERN_(USER_CMD_3_ENABLE, queue.inject_P(PSTR(USER_GCODE_3))); break;
case ID_CUSTOM_4: TERN_(USER_CMD_4_ENABLE, queue.inject_P(PSTR(USER_GCODE_4))); break;
case ID_CUSTOM_5: TERN_(USER_CMD_5_ENABLE, queue.inject_P(PSTR(USER_GCODE_5))); break;
case ID_CUSTOM_6: TERN_(USER_CMD_6_ENABLE, queue.inject_P(PSTR(USER_GCODE_6))); break;
#if HAS_USER_ITEM(1)
case ID_CUSTOM_1: queue.inject_P(PSTR(USER_GCODE_1)); break;
#endif
#if HAS_USER_ITEM(2)
case ID_CUSTOM_2: queue.inject_P(PSTR(USER_GCODE_2)); break;
#endif
#if HAS_USER_ITEM(3)
case ID_CUSTOM_3: queue.inject_P(PSTR(USER_GCODE_3)); break;
#endif
#if HAS_USER_ITEM(4)
case ID_CUSTOM_4: queue.inject_P(PSTR(USER_GCODE_4)); break;
#endif
#if HAS_USER_ITEM(5)
case ID_CUSTOM_5: queue.inject_P(PSTR(USER_GCODE_5)); break;
#endif
#if HAS_USER_ITEM(6)
case ID_CUSTOM_6: queue.inject_P(PSTR(USER_GCODE_6)); break;
#endif
case ID_M_RETURN:
lv_clear_more();
lv_draw_tool();
@ -70,37 +96,37 @@ void lv_draw_more() {
if (enc_ena) lv_group_add_obj(g, buttonGCode);
lv_obj_t *labelGCode = lv_label_create_empty(buttonGCode);
#if ENABLED(USER_CMD_1_ENABLE)
#if HAS_USER_ITEM(1)
lv_obj_t *buttonCustom1 = lv_imgbtn_create(scr, "F:/bmp_custom1.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_CUSTOM_1);
if (enc_ena) lv_group_add_obj(g, buttonCustom1);
lv_obj_t *labelCustom1 = lv_label_create_empty(buttonCustom1);
#endif
#if ENABLED(USER_CMD_2_ENABLE)
#if HAS_USER_ITEM(2)
lv_obj_t *buttonCustom2 = lv_imgbtn_create(scr, "F:/bmp_custom2.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_CUSTOM_2);
if (enc_ena) lv_group_add_obj(g, buttonCustom2);
lv_obj_t *labelCustom2 = lv_label_create_empty(buttonCustom2);
#endif
#if ENABLED(USER_CMD_3_ENABLE)
#if HAS_USER_ITEM(3)
lv_obj_t *buttonCustom3 = lv_imgbtn_create(scr, "F:/bmp_custom3.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_CUSTOM_3);
if (enc_ena) lv_group_add_obj(g, buttonCustom3);
lv_obj_t *labelCustom3 = lv_label_create_empty(buttonCustom3);
#endif
#if ENABLED(USER_CMD_4_ENABLE)
#if HAS_USER_ITEM(4)
lv_obj_t *buttonCustom4 = lv_imgbtn_create(scr, "F:/bmp_custom4.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_CUSTOM_4);
if (enc_ena) lv_group_add_obj(g, buttonCustom4);
lv_obj_t *labelCustom4 = lv_label_create_empty(buttonCustom4);
#endif
#if ENABLED(USER_CMD_5_ENABLE)
#if HAS_USER_ITEM(5)
lv_obj_t *buttonCustom5 = lv_imgbtn_create(scr, "F:/bmp_custom5.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_CUSTOM_5);
if (enc_ena) lv_group_add_obj(g, buttonCustom5);
lv_obj_t *labelCustom5 = lv_label_create_empty(buttonCustom5);
#endif
#if ENABLED(USER_CMD_6_ENABLE)
#if HAS_USER_ITEM(6)
lv_obj_t *buttonCustom6 = lv_imgbtn_create(scr, "F:/bmp_custom6.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_CUSTOM_6);
if (enc_ena) lv_group_add_obj(g, buttonCustom6);
lv_obj_t *labelCustom6 = lv_label_create_empty(buttonCustom6);
@ -114,27 +140,27 @@ void lv_draw_more() {
lv_label_set_text(labelGCode, more_menu.gcode);
lv_obj_align(labelGCode, buttonGCode, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#if ENABLED(USER_CMD_1_ENABLE)
#if HAS_USER_ITEM(1)
lv_label_set_text(labelCustom1, more_menu.custom1);
lv_obj_align(labelCustom1, buttonCustom1, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#endif
#if ENABLED(USER_CMD_2_ENABLE)
#if HAS_USER_ITEM(2)
lv_label_set_text(labelCustom2, more_menu.custom2);
lv_obj_align(labelCustom2, buttonCustom2, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#endif
#if ENABLED(USER_CMD_3_ENABLE)
#if HAS_USER_ITEM(3)
lv_label_set_text(labelCustom3, more_menu.custom3);
lv_obj_align(labelCustom3, buttonCustom3, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#endif
#if ENABLED(USER_CMD_4_ENABLE)
#if HAS_USER_ITEM(4)
lv_label_set_text(labelCustom4, more_menu.custom4);
lv_obj_align(labelCustom4, buttonCustom4, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#endif
#if ENABLED(USER_CMD_5_ENABLE)
#if HAS_USER_ITEM(5)
lv_label_set_text(labelCustom5, more_menu.custom5);
lv_obj_align(labelCustom5, buttonCustom5, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#endif
#if ENABLED(USER_CMD_6_ENABLE)
#if HAS_USER_ITEM(6)
lv_label_set_text(labelCustom6, more_menu.custom6);
lv_obj_align(labelCustom6, buttonCustom6, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
#endif
@ -145,12 +171,24 @@ void lv_draw_more() {
#if BUTTONS_EXIST(EN1, EN2, ENC)
if (enc_ena) {
lv_group_add_obj(g, buttonGCode);
TERN_(USER_CMD_1_ENABLE, lv_group_add_obj(g, buttonCustom1));
TERN_(USER_CMD_2_ENABLE, lv_group_add_obj(g, buttonCustom2));
TERN_(USER_CMD_3_ENABLE, lv_group_add_obj(g, buttonCustom3));
TERN_(USER_CMD_4_ENABLE, lv_group_add_obj(g, buttonCustom4));
TERN_(USER_CMD_5_ENABLE, lv_group_add_obj(g, buttonCustom5));
TERN_(USER_CMD_6_ENABLE, lv_group_add_obj(g, buttonCustom6));
#if HAS_USER_ITEM(1)
lv_group_add_obj(g, buttonCustom1);
#endif
#if HAS_USER_ITEM(2)
lv_group_add_obj(g, buttonCustom2);
#endif
#if HAS_USER_ITEM(3)
lv_group_add_obj(g, buttonCustom3);
#endif
#if HAS_USER_ITEM(4)
lv_group_add_obj(g, buttonCustom4);
#endif
#if HAS_USER_ITEM(5)
lv_group_add_obj(g, buttonCustom5);
#endif
#if HAS_USER_ITEM(6)
lv_group_add_obj(g, buttonCustom6);
#endif
lv_group_add_obj(g, buttonBack);
}
#endif

4
Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp

@ -71,7 +71,9 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target;
lv_draw_filament_change();
break;
case ID_T_MORE: lv_draw_more(); break;
case ID_T_MORE:
lv_draw_more();
break;
case ID_T_RETURN:
TERN_(MKS_TEST, curent_disp_ui = 1);
lv_draw_ready_print();

Loading…
Cancel
Save