Browse Source

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

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Malderin 3 years ago
parent
commit
9025c63c43
No account linked to committer's email address

+ 2
- 1
Marlin/Configuration_adv.h View File

3342
 #endif
3342
 #endif
3343
 
3343
 
3344
 /**
3344
 /**
3345
- * User-defined menu items that execute custom GCode
3345
+ * User-defined menu items to run custom G-code.
3346
+ * Up to 25 may be defined, but the actual number is LCD-dependent.
3346
  */
3347
  */
3347
 //#define CUSTOM_USER_MENUS
3348
 //#define CUSTOM_USER_MENUS
3348
 #if ENABLED(CUSTOM_USER_MENUS)
3349
 #if ENABLED(CUSTOM_USER_MENUS)

+ 68
- 30
Marlin/src/lcd/extui/lib/mks_ui/draw_more.cpp View File

33
 extern lv_group_t * g;
33
 extern lv_group_t * g;
34
 static lv_obj_t * scr;
34
 static lv_obj_t * scr;
35
 
35
 
36
+#define HAS_USER_ITEM(N) (ENABLED(CUSTOM_USER_MENUS) && defined(USER_DESC_##N) && defined(USER_GCODE_##N))
37
+
36
 enum {
38
 enum {
37
   ID_GCODE = 1,
39
   ID_GCODE = 1,
38
-  ID_CUSTOM_1,
39
-  ID_CUSTOM_2,
40
-  ID_CUSTOM_3,
41
-  ID_CUSTOM_4,
42
-  ID_CUSTOM_5,
43
-  ID_CUSTOM_6,
40
+  #if HAS_USER_ITEM(1)
41
+    ID_CUSTOM_1,
42
+  #endif
43
+  #if HAS_USER_ITEM(2)
44
+    ID_CUSTOM_2,
45
+  #endif
46
+  #if HAS_USER_ITEM(3)
47
+    ID_CUSTOM_3,
48
+  #endif
49
+  #if HAS_USER_ITEM(4)
50
+    ID_CUSTOM_4,
51
+  #endif
52
+  #if HAS_USER_ITEM(5)
53
+    ID_CUSTOM_5,
54
+  #endif
55
+  #if HAS_USER_ITEM(6)
56
+    ID_CUSTOM_6,
57
+  #endif
44
   ID_M_RETURN,
58
   ID_M_RETURN,
45
 };
59
 };
46
 
60
 
48
   if (event != LV_EVENT_RELEASED) return;
62
   if (event != LV_EVENT_RELEASED) return;
49
   switch (obj->mks_obj_id) {
63
   switch (obj->mks_obj_id) {
50
     case ID_GCODE: lv_clear_more(); lv_draw_gcode(true); break;
64
     case ID_GCODE: lv_clear_more(); lv_draw_gcode(true); break;
51
-    case ID_CUSTOM_1: TERN_(USER_CMD_1_ENABLE, queue.inject_P(PSTR(USER_GCODE_1))); break;
52
-    case ID_CUSTOM_2: TERN_(USER_CMD_2_ENABLE, queue.inject_P(PSTR(USER_GCODE_2))); break;
53
-    case ID_CUSTOM_3: TERN_(USER_CMD_3_ENABLE, queue.inject_P(PSTR(USER_GCODE_3))); break;
54
-    case ID_CUSTOM_4: TERN_(USER_CMD_4_ENABLE, queue.inject_P(PSTR(USER_GCODE_4))); break;
55
-    case ID_CUSTOM_5: TERN_(USER_CMD_5_ENABLE, queue.inject_P(PSTR(USER_GCODE_5))); break;
56
-    case ID_CUSTOM_6: TERN_(USER_CMD_6_ENABLE, queue.inject_P(PSTR(USER_GCODE_6))); break;
65
+    #if HAS_USER_ITEM(1)
66
+      case ID_CUSTOM_1: queue.inject_P(PSTR(USER_GCODE_1)); break;
67
+    #endif
68
+    #if HAS_USER_ITEM(2)
69
+      case ID_CUSTOM_2: queue.inject_P(PSTR(USER_GCODE_2)); break;
70
+    #endif
71
+    #if HAS_USER_ITEM(3)
72
+      case ID_CUSTOM_3: queue.inject_P(PSTR(USER_GCODE_3)); break;
73
+    #endif
74
+    #if HAS_USER_ITEM(4)
75
+      case ID_CUSTOM_4: queue.inject_P(PSTR(USER_GCODE_4)); break;
76
+    #endif
77
+    #if HAS_USER_ITEM(5)
78
+      case ID_CUSTOM_5: queue.inject_P(PSTR(USER_GCODE_5)); break;
79
+    #endif
80
+    #if HAS_USER_ITEM(6)
81
+      case ID_CUSTOM_6: queue.inject_P(PSTR(USER_GCODE_6)); break;
82
+    #endif
57
     case ID_M_RETURN:
83
     case ID_M_RETURN:
58
       lv_clear_more();
84
       lv_clear_more();
59
       lv_draw_tool();
85
       lv_draw_tool();
70
   if (enc_ena) lv_group_add_obj(g, buttonGCode);
96
   if (enc_ena) lv_group_add_obj(g, buttonGCode);
71
   lv_obj_t *labelGCode = lv_label_create_empty(buttonGCode);
97
   lv_obj_t *labelGCode = lv_label_create_empty(buttonGCode);
72
 
98
 
73
-  #if ENABLED(USER_CMD_1_ENABLE)
99
+  #if HAS_USER_ITEM(1)
74
     lv_obj_t *buttonCustom1 = lv_imgbtn_create(scr, "F:/bmp_custom1.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_CUSTOM_1);
100
     lv_obj_t *buttonCustom1 = lv_imgbtn_create(scr, "F:/bmp_custom1.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_CUSTOM_1);
75
     if (enc_ena) lv_group_add_obj(g, buttonCustom1);
101
     if (enc_ena) lv_group_add_obj(g, buttonCustom1);
76
     lv_obj_t *labelCustom1 = lv_label_create_empty(buttonCustom1);
102
     lv_obj_t *labelCustom1 = lv_label_create_empty(buttonCustom1);
77
   #endif
103
   #endif
78
 
104
 
79
-  #if ENABLED(USER_CMD_2_ENABLE)
105
+  #if HAS_USER_ITEM(2)
80
     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);
106
     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);
81
     if (enc_ena) lv_group_add_obj(g, buttonCustom2);
107
     if (enc_ena) lv_group_add_obj(g, buttonCustom2);
82
     lv_obj_t *labelCustom2 = lv_label_create_empty(buttonCustom2);
108
     lv_obj_t *labelCustom2 = lv_label_create_empty(buttonCustom2);
83
   #endif
109
   #endif
84
 
110
 
85
-  #if ENABLED(USER_CMD_3_ENABLE)
111
+  #if HAS_USER_ITEM(3)
86
     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);
112
     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);
87
     if (enc_ena) lv_group_add_obj(g, buttonCustom3);
113
     if (enc_ena) lv_group_add_obj(g, buttonCustom3);
88
     lv_obj_t *labelCustom3 = lv_label_create_empty(buttonCustom3);
114
     lv_obj_t *labelCustom3 = lv_label_create_empty(buttonCustom3);
89
   #endif
115
   #endif
90
 
116
 
91
-  #if ENABLED(USER_CMD_4_ENABLE)
117
+  #if HAS_USER_ITEM(4)
92
     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);
118
     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);
93
     if (enc_ena) lv_group_add_obj(g, buttonCustom4);
119
     if (enc_ena) lv_group_add_obj(g, buttonCustom4);
94
     lv_obj_t *labelCustom4 = lv_label_create_empty(buttonCustom4);
120
     lv_obj_t *labelCustom4 = lv_label_create_empty(buttonCustom4);
95
   #endif
121
   #endif
96
 
122
 
97
-  #if ENABLED(USER_CMD_5_ENABLE)
123
+  #if HAS_USER_ITEM(5)
98
     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);
124
     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);
99
     if (enc_ena) lv_group_add_obj(g, buttonCustom5);
125
     if (enc_ena) lv_group_add_obj(g, buttonCustom5);
100
     lv_obj_t *labelCustom5 = lv_label_create_empty(buttonCustom5);
126
     lv_obj_t *labelCustom5 = lv_label_create_empty(buttonCustom5);
101
   #endif
127
   #endif
102
 
128
 
103
-  #if ENABLED(USER_CMD_6_ENABLE)
129
+  #if HAS_USER_ITEM(6)
104
     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);
130
     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);
105
     if (enc_ena) lv_group_add_obj(g, buttonCustom6);
131
     if (enc_ena) lv_group_add_obj(g, buttonCustom6);
106
     lv_obj_t *labelCustom6 = lv_label_create_empty(buttonCustom6);
132
     lv_obj_t *labelCustom6 = lv_label_create_empty(buttonCustom6);
114
     lv_label_set_text(labelGCode, more_menu.gcode);
140
     lv_label_set_text(labelGCode, more_menu.gcode);
115
     lv_obj_align(labelGCode, buttonGCode, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
141
     lv_obj_align(labelGCode, buttonGCode, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
116
 
142
 
117
-    #if ENABLED(USER_CMD_1_ENABLE)
143
+    #if HAS_USER_ITEM(1)
118
       lv_label_set_text(labelCustom1, more_menu.custom1);
144
       lv_label_set_text(labelCustom1, more_menu.custom1);
119
       lv_obj_align(labelCustom1, buttonCustom1, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
145
       lv_obj_align(labelCustom1, buttonCustom1, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
120
     #endif
146
     #endif
121
-    #if ENABLED(USER_CMD_2_ENABLE)
147
+    #if HAS_USER_ITEM(2)
122
       lv_label_set_text(labelCustom2, more_menu.custom2);
148
       lv_label_set_text(labelCustom2, more_menu.custom2);
123
       lv_obj_align(labelCustom2, buttonCustom2, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
149
       lv_obj_align(labelCustom2, buttonCustom2, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
124
     #endif
150
     #endif
125
-    #if ENABLED(USER_CMD_3_ENABLE)
151
+    #if HAS_USER_ITEM(3)
126
       lv_label_set_text(labelCustom3, more_menu.custom3);
152
       lv_label_set_text(labelCustom3, more_menu.custom3);
127
       lv_obj_align(labelCustom3, buttonCustom3, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
153
       lv_obj_align(labelCustom3, buttonCustom3, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
128
     #endif
154
     #endif
129
-    #if ENABLED(USER_CMD_4_ENABLE)
155
+    #if HAS_USER_ITEM(4)
130
       lv_label_set_text(labelCustom4, more_menu.custom4);
156
       lv_label_set_text(labelCustom4, more_menu.custom4);
131
       lv_obj_align(labelCustom4, buttonCustom4, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
157
       lv_obj_align(labelCustom4, buttonCustom4, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
132
     #endif
158
     #endif
133
-    #if ENABLED(USER_CMD_5_ENABLE)
159
+    #if HAS_USER_ITEM(5)
134
       lv_label_set_text(labelCustom5, more_menu.custom5);
160
       lv_label_set_text(labelCustom5, more_menu.custom5);
135
       lv_obj_align(labelCustom5, buttonCustom5, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
161
       lv_obj_align(labelCustom5, buttonCustom5, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
136
     #endif
162
     #endif
137
-    #if ENABLED(USER_CMD_6_ENABLE)
163
+    #if HAS_USER_ITEM(6)
138
       lv_label_set_text(labelCustom6, more_menu.custom6);
164
       lv_label_set_text(labelCustom6, more_menu.custom6);
139
       lv_obj_align(labelCustom6, buttonCustom6, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
165
       lv_obj_align(labelCustom6, buttonCustom6, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
140
     #endif
166
     #endif
145
   #if BUTTONS_EXIST(EN1, EN2, ENC)
171
   #if BUTTONS_EXIST(EN1, EN2, ENC)
146
     if (enc_ena) {
172
     if (enc_ena) {
147
       lv_group_add_obj(g, buttonGCode);
173
       lv_group_add_obj(g, buttonGCode);
148
-      TERN_(USER_CMD_1_ENABLE, lv_group_add_obj(g, buttonCustom1));
149
-      TERN_(USER_CMD_2_ENABLE, lv_group_add_obj(g, buttonCustom2));
150
-      TERN_(USER_CMD_3_ENABLE, lv_group_add_obj(g, buttonCustom3));
151
-      TERN_(USER_CMD_4_ENABLE, lv_group_add_obj(g, buttonCustom4));
152
-      TERN_(USER_CMD_5_ENABLE, lv_group_add_obj(g, buttonCustom5));
153
-      TERN_(USER_CMD_6_ENABLE, lv_group_add_obj(g, buttonCustom6));
174
+      #if HAS_USER_ITEM(1)
175
+        lv_group_add_obj(g, buttonCustom1);
176
+      #endif
177
+      #if HAS_USER_ITEM(2)
178
+        lv_group_add_obj(g, buttonCustom2);
179
+      #endif
180
+      #if HAS_USER_ITEM(3)
181
+        lv_group_add_obj(g, buttonCustom3);
182
+      #endif
183
+      #if HAS_USER_ITEM(4)
184
+        lv_group_add_obj(g, buttonCustom4);
185
+      #endif
186
+      #if HAS_USER_ITEM(5)
187
+        lv_group_add_obj(g, buttonCustom5);
188
+      #endif
189
+      #if HAS_USER_ITEM(6)
190
+        lv_group_add_obj(g, buttonCustom6);
191
+      #endif
154
       lv_group_add_obj(g, buttonBack);
192
       lv_group_add_obj(g, buttonBack);
155
     }
193
     }
156
   #endif
194
   #endif

+ 3
- 1
Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp View File

71
       uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target;
71
       uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target;
72
       lv_draw_filament_change();
72
       lv_draw_filament_change();
73
       break;
73
       break;
74
-    case ID_T_MORE: lv_draw_more(); break;
74
+    case ID_T_MORE:
75
+      lv_draw_more();
76
+      break;
75
     case ID_T_RETURN:
77
     case ID_T_RETURN:
76
       TERN_(MKS_TEST, curent_disp_ui = 1);
78
       TERN_(MKS_TEST, curent_disp_ui = 1);
77
       lv_draw_ready_print();
79
       lv_draw_ready_print();

Loading…
Cancel
Save