1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../../../../inc/MarlinConfigPre.h"
#if HAS_TFT_LVGL_UI
#include "draw_ui.h"
#include <lv_conf.h>
#include "../../../../module/temperature.h"
#include "../../../../inc/MarlinConfig.h"
#include "../../../../module/motion.h"
static lv_obj_t *scr;
extern lv_group_t* g;
static lv_obj_t *buttonType, *buttonStep;
static lv_obj_t *labelType;
static lv_obj_t *labelStep;
static lv_obj_t *tempText1;
enum {
ID_P_ADD = 1,
ID_P_DEC,
ID_P_TYPE,
ID_P_STEP,
ID_P_OFF,
ID_P_RETURN
};
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_P_ADD:
if (uiCfg.curTempType == 0) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target += uiCfg.stepHeat;
if (uiCfg.curSprayerChoose == 0) {
if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
}
}
#if DISABLED(SINGLENOZZLE) && HAS_MULTI_EXTRUDER
else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
}
#endif
thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
}
#if HAS_HEATED_BED
else {
thermalManager.temp_bed.target += uiCfg.stepHeat;
if ((int)thermalManager.temp_bed.target > BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
thermalManager.temp_bed.target = (float)BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1);
}
thermalManager.start_watching_bed();
}
#endif
disp_desire_temp();
break;
case ID_P_DEC:
if (uiCfg.curTempType == 0) {
if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > uiCfg.stepHeat)
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target -= uiCfg.stepHeat;
else
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = 0;
thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
}
#if HAS_HEATED_BED
else {
if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat)
thermalManager.temp_bed.target -= uiCfg.stepHeat;
else
thermalManager.temp_bed.target = 0;
thermalManager.start_watching_bed();
}
#endif
disp_desire_temp();
break;
case ID_P_TYPE:
if (uiCfg.curTempType == 0) {
if (ENABLED(HAS_MULTI_EXTRUDER)) {
#if DISABLED(SINGLENOZZLE)
if (uiCfg.curSprayerChoose == 0) {
uiCfg.curSprayerChoose = 1;
}
else if (uiCfg.curSprayerChoose == 1) {
if (TEMP_SENSOR_BED != 0) {
uiCfg.curTempType = 1;
}
else {
uiCfg.curTempType = 0;
uiCfg.curSprayerChoose = 0;
}
}
#else
if (TEMP_SENSOR_BED != 0) {
uiCfg.curTempType = 1;
}
else {
uiCfg.curTempType = 0;
}
#endif
}
else if (uiCfg.curSprayerChoose == 0) {
if (TEMP_SENSOR_BED != 0)
uiCfg.curTempType = 1;
else
uiCfg.curTempType = 0;
}
}
else if (uiCfg.curTempType == 1) {
uiCfg.curSprayerChoose = 0;
uiCfg.curTempType = 0;
}
disp_temp_type();
break;
case ID_P_STEP:
switch (uiCfg.stepHeat) {
case 1: uiCfg.stepHeat = 5; break;
case 5: uiCfg.stepHeat = 10; break;
case 10: uiCfg.stepHeat = 1; break;
default: break;
}
disp_step_heat();
break;
case ID_P_OFF:
if (uiCfg.curTempType == 0) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = 0;
thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
}
#if HAS_HEATED_BED
else {
thermalManager.temp_bed.target = 0;
thermalManager.start_watching_bed();
}
#endif
disp_desire_temp();
break;
case ID_P_RETURN:
lv_clear_cur_ui();
lv_draw_return_ui();
break;
}
}
void lv_draw_preHeat(void) {
scr = lv_screen_create(PRE_HEAT_UI);
// Create image buttons
lv_big_button_create(scr, "F:/bmp_Add.bin", preheat_menu.add, INTERVAL_V, titleHeight, event_handler, ID_P_ADD);
lv_big_button_create(scr, "F:/bmp_Dec.bin", preheat_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_DEC);
buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_TYPE);
buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_STEP);
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) {
lv_group_add_obj(g, buttonType);
lv_group_add_obj(g, buttonStep);
}
#endif
lv_big_button_create(scr, "F:/bmp_speed0.bin", preheat_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_OFF);
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_RETURN);
// Create labels on the image buttons
labelType = lv_label_create_empty(buttonType);
labelStep = lv_label_create_empty(buttonStep);
#if ENABLED(SINGLENOZZLE)
uiCfg.curSprayerChoose = 0;
#else
uiCfg.curSprayerChoose = active_extruder;
#endif
disp_temp_type();
disp_step_heat();
tempText1 = lv_label_create_empty(scr);
lv_obj_set_style(tempText1, &tft_style_label_rel);
disp_desire_temp();
}
void disp_temp_type() {
if (uiCfg.curTempType == 0) {
#if DISABLED(SINGLENOZZLE)
if (uiCfg.curSprayerChoose == 1) {
lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin");
if (gCfgItems.multiple_language) {
lv_label_set_text(labelType, preheat_menu.ext2);
lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
}
else {
lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin");
if (gCfgItems.multiple_language) {
lv_label_set_text(labelType, preheat_menu.ext1);
lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
}
#else
lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin");
if (gCfgItems.multiple_language) {
lv_label_set_text(labelType, preheat_menu.ext1);
lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
#endif
}
else {
lv_imgbtn_set_src_both(buttonType, "F:/bmp_bed.bin");
if (gCfgItems.multiple_language) {
lv_label_set_text(labelType, preheat_menu.hotbed);
lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
}
}
void disp_desire_temp() {
char buf[20] = {0};
public_buf_l[0] = '\0';
if (uiCfg.curTempType == 0) {
#if DISABLED(SINGLENOZZLE)
strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? preheat_menu.ext1 : preheat_menu.ext2);
sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target);
#else
strcat(public_buf_l, preheat_menu.ext1);
sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[0].celsius, (int)thermalManager.temp_hotend[0].target);
#endif
}
#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);
}
#endif
strcat_P(public_buf_l, PSTR(": "));
strcat(public_buf_l, buf);
lv_label_set_text(tempText1, public_buf_l);
lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50);
}
void disp_step_heat() {
if (uiCfg.stepHeat == 1) {
lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step1_degree.bin");
}
else if (uiCfg.stepHeat == 5) {
lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step5_degree.bin");
}
else if (uiCfg.stepHeat == 10) {
lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step10_degree.bin");
}
if (gCfgItems.multiple_language) {
if (uiCfg.stepHeat == 1) {
lv_label_set_text(labelStep, preheat_menu.step_1c);
lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
else if (uiCfg.stepHeat == 5) {
lv_label_set_text(labelStep, preheat_menu.step_5c);
lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
else if (uiCfg.stepHeat == 10) {
lv_label_set_text(labelStep, preheat_menu.step_10c);
lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
}
}
void lv_clear_preHeat() {
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
#endif
lv_obj_del(scr);
}
#endif // HAS_TFT_LVGL_UI
|