|
@@ -0,0 +1,228 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
4
|
+ *
|
|
5
|
+ * Based on Sprinter and grbl.
|
|
6
|
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
7
|
+ *
|
|
8
|
+ * This program is free software: you can redistribute it and/or modify
|
|
9
|
+ * it under the terms of the GNU General Public License as published by
|
|
10
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+ * (at your option) any later version.
|
|
12
|
+ *
|
|
13
|
+ * This program is distributed in the hope that it will be useful,
|
|
14
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+ * GNU General Public License for more details.
|
|
17
|
+ *
|
|
18
|
+ * You should have received a copy of the GNU General Public License
|
|
19
|
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+#include "../../../inc/MarlinConfigPre.h"
|
|
24
|
+
|
|
25
|
+#if BOTH(HAS_TFT_LVGL_UI, PROBE_OFFSET_WIZARD)
|
|
26
|
+
|
|
27
|
+#include "draw_ui.h"
|
|
28
|
+#include <lv_conf.h>
|
|
29
|
+
|
|
30
|
+#include "../../../gcode/queue.h"
|
|
31
|
+#include "../../../module/motion.h"
|
|
32
|
+
|
|
33
|
+#include "../../../module/planner.h"
|
|
34
|
+#include "../../../inc/MarlinConfig.h"
|
|
35
|
+#include "../../../module/probe.h"
|
|
36
|
+
|
|
37
|
+#if HAS_LEVELING
|
|
38
|
+ #include "../../../feature/bedlevel/bedlevel.h"
|
|
39
|
+ bool leveling_was_active;
|
|
40
|
+#endif
|
|
41
|
+
|
|
42
|
+extern lv_group_t *g;
|
|
43
|
+static lv_obj_t *scr;
|
|
44
|
+
|
|
45
|
+static lv_obj_t *labelV, *buttonV, *labelP;
|
|
46
|
+static lv_obj_t *labelP_z_offset_ref;
|
|
47
|
+static lv_task_t *updatePosTask;
|
|
48
|
+static char cur_label = 'Z';
|
|
49
|
+static float cur_pos = 0;
|
|
50
|
+static float cur_OffsetPos = 0;
|
|
51
|
+
|
|
52
|
+// Global storage
|
|
53
|
+float z_offset_backup, calculated_z_offset, z_offset_ref;
|
|
54
|
+
|
|
55
|
+enum {
|
|
56
|
+ ID_M_Z_P = 1,
|
|
57
|
+ ID_M_Z_N,
|
|
58
|
+ ID_M_STEP,
|
|
59
|
+ ID_M_SAVE,
|
|
60
|
+ ID_M_RETURN
|
|
61
|
+};
|
|
62
|
+
|
|
63
|
+void disp_cur_wizard_pos() {
|
|
64
|
+ char str_1[18];
|
|
65
|
+ sprintf_P(public_buf_l, PSTR("%c:%s mm"), cur_label, dtostrf(cur_pos, 1, 3, str_1));
|
|
66
|
+ if (labelP) lv_label_set_text(labelP, public_buf_l);
|
|
67
|
+
|
|
68
|
+ sprintf_P(public_buf_l, PSTR("%c Offset:%s mm"), cur_label, dtostrf(cur_OffsetPos, 1, 3, str_1));
|
|
69
|
+ if (labelP_z_offset_ref) lv_label_set_text(labelP_z_offset_ref, public_buf_l);
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
|
73
|
+ char str_1[16];
|
|
74
|
+ if (event != LV_EVENT_RELEASED) return;
|
|
75
|
+ //lv_clear_z_offset_wizard();
|
|
76
|
+ if (!queue.ring_buffer.full(3)) {
|
|
77
|
+ bool do_inject = true;
|
|
78
|
+ float dist = uiCfg.move_dist;
|
|
79
|
+ switch (obj->mks_obj_id) {
|
|
80
|
+ case ID_M_Z_N: dist *= -1; case ID_M_Z_P: cur_label = 'Z'; break;
|
|
81
|
+ default: do_inject = false;
|
|
82
|
+ }
|
|
83
|
+ if (do_inject) {
|
|
84
|
+ sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed);
|
|
85
|
+ queue.inject(public_buf_l);
|
|
86
|
+ //calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
|
|
87
|
+ disp_cur_wizard_pos();
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ switch (obj->mks_obj_id) {
|
|
92
|
+ case ID_M_STEP:
|
|
93
|
+ if (ABS((int)(10 * uiCfg.move_dist)) == 10)
|
|
94
|
+ uiCfg.move_dist = 0.025;
|
|
95
|
+ else if (ABS((int)(1000 * uiCfg.move_dist)) == 25)
|
|
96
|
+ uiCfg.move_dist = 0.1;
|
|
97
|
+ else
|
|
98
|
+ uiCfg.move_dist *= 10.0f;
|
|
99
|
+ disp_move_wizard_dist();
|
|
100
|
+ break;
|
|
101
|
+ case ID_M_SAVE:
|
|
102
|
+ current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
|
|
103
|
+ probe.offset.z = calculated_z_offset;
|
|
104
|
+ sync_plan_position();
|
|
105
|
+ // Raise Z as if it was homed
|
|
106
|
+ do_z_clearance(Z_POST_CLEARANCE);
|
|
107
|
+ watchdog_refresh();
|
|
108
|
+ draw_return_ui();
|
|
109
|
+ return;
|
|
110
|
+ case ID_M_RETURN:
|
|
111
|
+ probe.offset.z = z_offset_backup;
|
|
112
|
+ SET_SOFT_ENDSTOP_LOOSE(false);
|
|
113
|
+ TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
|
|
114
|
+ #if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
|
|
115
|
+ set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
|
|
116
|
+ queue.inject_P(PSTR("G28Z"));
|
|
117
|
+ #else // Otherwise do a Z clearance move like after Homing
|
|
118
|
+ do_z_clearance(Z_POST_CLEARANCE);
|
|
119
|
+ #endif
|
|
120
|
+ watchdog_refresh();
|
|
121
|
+ draw_return_ui();
|
|
122
|
+ return;
|
|
123
|
+ }
|
|
124
|
+ disp_cur_wizard_pos();
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+void refresh_wizard_pos(lv_task_t *) {
|
|
128
|
+ switch (cur_label) {
|
|
129
|
+ case 'Z':
|
|
130
|
+ cur_pos = current_position.z;
|
|
131
|
+ calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
|
|
132
|
+ cur_OffsetPos = calculated_z_offset;
|
|
133
|
+ break;
|
|
134
|
+ default: return;
|
|
135
|
+ }
|
|
136
|
+ disp_cur_wizard_pos();
|
|
137
|
+}
|
|
138
|
+
|
|
139
|
+void lv_draw_z_offset_wizard() {
|
|
140
|
+
|
|
141
|
+ set_all_unhomed();
|
|
142
|
+
|
|
143
|
+ // Store probe.offset.z for Case: Cancel
|
|
144
|
+ z_offset_backup = probe.offset.z;
|
|
145
|
+
|
|
146
|
+ #ifdef PROBE_OFFSET_WIZARD_START_Z
|
|
147
|
+ probe.offset.z = PROBE_OFFSET_WIZARD_START_Z;
|
|
148
|
+ #endif
|
|
149
|
+
|
|
150
|
+ // Store Bed-Leveling-State and disable
|
|
151
|
+ #if HAS_LEVELING
|
|
152
|
+ leveling_was_active = planner.leveling_active;
|
|
153
|
+ set_bed_leveling_enabled(leveling_was_active);
|
|
154
|
+ #endif
|
|
155
|
+
|
|
156
|
+ queue.inject_P(PSTR("G28"));
|
|
157
|
+
|
|
158
|
+ z_offset_ref = 0; // Set Z Value for Wizard Position to 0
|
|
159
|
+ calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
|
|
160
|
+ cur_OffsetPos = calculated_z_offset;
|
|
161
|
+
|
|
162
|
+ scr = lv_screen_create(Z_OFFSET_WIZARD_UI, machine_menu.LevelingZoffsetTitle);
|
|
163
|
+
|
|
164
|
+ lv_obj_t *buttonXI = lv_big_button_create(scr, "F:/bmp_zAdd.bin", move_menu.z_add, INTERVAL_V, titleHeight, event_handler, ID_M_Z_P);
|
|
165
|
+ lv_obj_clear_protect(buttonXI, LV_PROTECT_FOLLOW);
|
|
166
|
+ lv_big_button_create(scr, "F:/bmp_zDec.bin", move_menu.z_dec, INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Z_N);
|
|
167
|
+
|
|
168
|
+ // button with image and label changed dynamically by disp_move_dist
|
|
169
|
+ buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_STEP);
|
|
170
|
+ labelV = lv_label_create_empty(buttonV);
|
|
171
|
+ #if HAS_ROTARY_ENCODER
|
|
172
|
+ if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonV);
|
|
173
|
+ #endif
|
|
174
|
+
|
|
175
|
+ // save and back
|
|
176
|
+ lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_save, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_SAVE);
|
|
177
|
+ // cancel and back
|
|
178
|
+ 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_M_RETURN);
|
|
179
|
+
|
|
180
|
+ // We need to patch the title to leave some space on the right for displaying the status
|
|
181
|
+ lv_obj_t * z_offset_ref_title = lv_obj_get_child_back(scr, nullptr);
|
|
182
|
+ if (z_offset_ref_title != nullptr) lv_obj_set_width(z_offset_ref_title, (int)(TFT_WIDTH / 2) - 101);
|
|
183
|
+ labelP_z_offset_ref = lv_label_create(scr, (int)(TFT_WIDTH / 2) - 80, (int)(TFT_HEIGHT/2)-20, "Z Offset:0.0mm");
|
|
184
|
+
|
|
185
|
+ // We need to patch the Z Offset to leave some space in the middle for displaying the status
|
|
186
|
+ lv_obj_t * title= lv_obj_get_child_back(scr, nullptr);
|
|
187
|
+ if (title != nullptr) lv_obj_set_width(title, TFT_WIDTH - 101);
|
|
188
|
+ labelP = lv_label_create(scr, TFT_WIDTH - 100, TITLE_YPOS, "Z:0.0mm");
|
|
189
|
+
|
|
190
|
+ if (labelP != nullptr)
|
|
191
|
+ updatePosTask = lv_task_create(refresh_wizard_pos, 300, LV_TASK_PRIO_LOWEST, 0);
|
|
192
|
+
|
|
193
|
+ disp_move_wizard_dist();
|
|
194
|
+ disp_cur_wizard_pos();
|
|
195
|
+}
|
|
196
|
+
|
|
197
|
+void disp_move_wizard_dist() {
|
|
198
|
+ if ((int)(1000 * uiCfg.move_dist) == 25)
|
|
199
|
+ lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move0_1.bin");
|
|
200
|
+ else if ((int)(10 * uiCfg.move_dist) == 1)
|
|
201
|
+ lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move1.bin");
|
|
202
|
+ else if ((int)(10 * uiCfg.move_dist) == 10)
|
|
203
|
+ lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move10.bin");
|
|
204
|
+
|
|
205
|
+ if (gCfgItems.multiple_language) {
|
|
206
|
+ if ((int)(1000 * uiCfg.move_dist) == 25) {
|
|
207
|
+ lv_label_set_text(labelV, move_menu.step_0025mm);
|
|
208
|
+ lv_obj_align(labelV, buttonV, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
209
|
+ }
|
|
210
|
+ else if ((int)(10 * uiCfg.move_dist) == 1) {
|
|
211
|
+ lv_label_set_text(labelV, move_menu.step_01mm);
|
|
212
|
+ lv_obj_align(labelV, buttonV, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
213
|
+ }
|
|
214
|
+ else if ((int)(10 * uiCfg.move_dist) == 10) {
|
|
215
|
+ lv_label_set_text(labelV, move_menu.step_1mm);
|
|
216
|
+ lv_obj_align(labelV, buttonV, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
217
|
+ }
|
|
218
|
+ }
|
|
219
|
+}
|
|
220
|
+
|
|
221
|
+void lv_clear_z_offset_wizard() {
|
|
222
|
+ #if HAS_ROTARY_ENCODER
|
|
223
|
+ if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
|
|
224
|
+ #endif
|
|
225
|
+ lv_obj_del(scr);
|
|
226
|
+}
|
|
227
|
+
|
|
228
|
+#endif // HAS_TFT_LVGL_UI && PROBE_OFFSET_WIZARD
|