소스 검색

Mesh Editor for FTDI Eve Touch UI (#21381)

Marcio T 3 년 전
부모
커밋
3e7d830f57
No account linked to committer's email address

+ 13
- 0
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/grid_layout.h 파일 보기

@@ -87,6 +87,19 @@
87 87
     cmd.cmd(LINE_WIDTH(16)); \
88 88
   }
89 89
 
90
+// Routines for subdividing a grid within a box (x,y,w,h)
91
+
92
+#define SUB_GRID_W(W)     ((W)*w/SUB_COLS)
93
+#define SUB_GRID_H(H)     ((H)*h/SUB_ROWS)
94
+#define SUB_GRID_X(X)     (SUB_GRID_W((X)-1) + x)
95
+#define SUB_GRID_Y(Y)     (SUB_GRID_H((Y)-1) + y)
96
+#define SUB_X(X)          (SUB_GRID_X(X) + MARGIN_L)
97
+#define SUB_Y(Y)          (SUB_GRID_Y(Y) + MARGIN_T)
98
+#define SUB_W(W)          (SUB_GRID_W(W) - MARGIN_L - MARGIN_R)
99
+#define SUB_H(H)          (SUB_GRID_H(H) - MARGIN_T - MARGIN_B)
100
+#define SUB_POS(X,Y)      SUB_X(X), SUB_Y(Y)
101
+#define SUB_SIZE(W,H)     SUB_W(W), SUB_H(H)
102
+
90 103
 namespace FTDI {
91 104
   #if ENABLED(TOUCH_UI_PORTRAIT)
92 105
     constexpr uint16_t display_width  = Vsize;

+ 54
- 0
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extras/adjuster_widget.cpp 파일 보기

@@ -0,0 +1,54 @@
1
+/***********************
2
+ * adjuster_widget.cpp *
3
+ ***********************/
4
+
5
+/****************************************************************************
6
+ *   Written By Marcio Teixeira 2021 - Cocoa Press                          *
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
+ *   To view a copy of the GNU General Public License, go to the following  *
19
+ *   location: <https://www.gnu.org/licenses/>.                             *
20
+ ****************************************************************************/
21
+
22
+#include "../ftdi_eve_lib.h"
23
+#include "../extended/grid_layout.h"
24
+
25
+#include "adjuster_widget.h"
26
+
27
+#define SUB_COLS          9
28
+#define SUB_ROWS          1
29
+#define VAL_POS           SUB_POS(1,1), SUB_SIZE(5,1)
30
+#define INC_POS           SUB_POS(6,1), SUB_SIZE(2,1)
31
+#define DEC_POS           SUB_POS(8,1), SUB_SIZE(2,1)
32
+
33
+void draw_adjuster(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t tag, float value, progmem_str units, int8_t width, uint8_t precision, draw_mode_t what) {
34
+    if (what & BACKGROUND)
35
+      cmd.tag(0).button(VAL_POS, F(""), FTDI::OPT_FLAT);
36
+
37
+    if (what & FOREGROUND) {
38
+      char str[width + precision + 10 + (units ? strlen_P((const char*) units) : 0)];
39
+      if (isnan(value))
40
+        strcpy_P(str, PSTR("-"));
41
+      else
42
+        dtostrf(value, width, precision, str);
43
+
44
+      if (units) {
45
+        strcat_P(str, PSTR(" "));
46
+        strcat_P(str, (const char*) units);
47
+      }
48
+
49
+      cmd.tag(0)
50
+         .text(VAL_POS, str)
51
+         .tag(tag  ).button(INC_POS, F("-"))
52
+         .tag(tag+1).button(DEC_POS, F("+"));
53
+    }
54
+}

+ 32
- 0
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extras/adjuster_widget.h 파일 보기

@@ -0,0 +1,32 @@
1
+/*********************
2
+ * adjuster_widget.h *
3
+ *********************/
4
+
5
+/****************************************************************************
6
+ *   Written By Marcio Teixeira 2021 - Cocoa Press                          *
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
+ *   To view a copy of the GNU General Public License, go to the following  *
19
+ *   location: <https://www.gnu.org/licenses/>.                             *
20
+ ****************************************************************************/
21
+
22
+#pragma once
23
+#include "../extended/screen_types.h"
24
+
25
+void draw_adjuster(
26
+  CommandProcessor& cmd,
27
+  int16_t x, int16_t y, int16_t w, int16_t h,
28
+  uint8_t tag,
29
+  float value, progmem_str units = nullptr,
30
+  int8_t width = 5, uint8_t precision = 1,
31
+  draw_mode_t what = BOTH
32
+);

+ 0
- 1
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/language/language_en.h 파일 보기

@@ -144,7 +144,6 @@ namespace Language_en {
144 144
   PROGMEM Language_Str MSG_BED_MAPPING_DONE         = u8"Bed mapping finished";
145 145
   PROGMEM Language_Str MSG_BED_MAPPING_INCOMPLETE   = u8"Not all points probed";
146 146
   PROGMEM Language_Str MSG_LEVELING                 = u8"Leveling";
147
-  PROGMEM Language_Str MSG_SHOW_MESH                = u8"Show Bed Mesh";
148 147
 
149 148
   #if ENABLED(TOUCH_UI_LULZBOT_BIO)
150 149
     PROGMEM Language_Str MSG_MOVE_TO_HOME           = u8"Move to Home";

+ 71
- 32
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp 파일 보기

@@ -25,21 +25,24 @@
25 25
 
26 26
 #ifdef FTDI_BED_MESH_SCREEN
27 27
 
28
+#include "../ftdi_eve_lib/extras/adjuster_widget.h"
29
+
28 30
 using namespace FTDI;
29 31
 using namespace Theme;
30 32
 using namespace ExtUI;
31 33
 
32 34
 constexpr static BedMeshScreenData &mydata = screen_data.BedMeshScreen;
35
+constexpr static float gaugeThickness = 0.25;
33 36
 
34 37
 #if ENABLED(TOUCH_UI_PORTRAIT)
35
-  #define GRID_COLS 2
38
+  #define GRID_COLS 3
36 39
   #define GRID_ROWS 10
37 40
 
38
-  #define MESH_POS    BTN_POS(1, 2), BTN_SIZE(2,5)
39
-  #define MESSAGE_POS BTN_POS(1, 7), BTN_SIZE(2,1)
41
+  #define MESH_POS    BTN_POS(1, 2), BTN_SIZE(3,5)
42
+  #define MESSAGE_POS BTN_POS(1, 7), BTN_SIZE(3,1)
40 43
   #define Z_LABEL_POS BTN_POS(1, 8), BTN_SIZE(1,1)
41
-  #define Z_VALUE_POS BTN_POS(2, 8), BTN_SIZE(1,1)
42
-  #define OKAY_POS    BTN_POS(1,10), BTN_SIZE(2,1)
44
+  #define Z_VALUE_POS BTN_POS(2, 8), BTN_SIZE(2,1)
45
+  #define OKAY_POS    BTN_POS(1,10), BTN_SIZE(3,1)
43 46
 #else
44 47
   #define GRID_COLS 5
45 48
   #define GRID_ROWS 5
@@ -198,12 +201,12 @@ void BedMeshScreen::drawMesh(int16_t x, int16_t y, int16_t w, int16_t h, ExtUI::
198 201
 
199 202
   if (opts & USE_HIGHLIGHT) {
200 203
     const uint8_t tag = mydata.highlightedTag;
201
-    uint8_t x, y;
202
-    if (tagToPoint(tag, x, y)) {
204
+    xy_uint8_t pt;
205
+    if (tagToPoint(tag, pt)) {
203 206
       cmd.cmd(COLOR_A(128))
204 207
          .cmd(POINT_SIZE(basePointSize * 6))
205 208
          .cmd(BEGIN(POINTS))
206
-         .tag(tag).cmd(VERTEX2F(TRANSFORM(x, y, HEIGHT(x, y))));
209
+         .tag(tag).cmd(VERTEX2F(TRANSFORM(pt.x, pt.y, HEIGHT(pt.x, pt.y))));
207 210
     }
208 211
   }
209 212
   cmd.cmd(END());
@@ -214,43 +217,68 @@ uint8_t BedMeshScreen::pointToTag(uint8_t x, uint8_t y) {
214 217
   return y * (GRID_MAX_POINTS_X) + x + 10;
215 218
 }
216 219
 
217
-bool BedMeshScreen::tagToPoint(uint8_t tag, uint8_t &x, uint8_t &y) {
220
+bool BedMeshScreen::tagToPoint(uint8_t tag, xy_uint8_t &pt) {
218 221
   if (tag < 10) return false;
219
-  x = (tag - 10) % (GRID_MAX_POINTS_X);
220
-  y = (tag - 10) / (GRID_MAX_POINTS_X);
222
+  pt.x = (tag - 10) % (GRID_MAX_POINTS_X);
223
+  pt.y = (tag - 10) / (GRID_MAX_POINTS_X);
221 224
   return true;
222 225
 }
223 226
 
224 227
 void BedMeshScreen::onEntry() {
225 228
   mydata.highlightedTag = 0;
229
+  mydata.zAdjustment = 0;
226 230
   mydata.count = GRID_MAX_POINTS;
227 231
   mydata.message = mydata.MSG_NONE;
228 232
   BaseScreen::onEntry();
229 233
 }
230 234
 
231
-float BedMeshScreen::getHightlightedValue() {
232
-  if (mydata.highlightedTag) {
233
-    xy_uint8_t pt;
234
-    tagToPoint(mydata.highlightedTag, pt.x, pt.y);
235
-    return ExtUI::getMeshPoint(pt);
235
+float BedMeshScreen::getHighlightedValue(bool nanAsZero) {
236
+  xy_uint8_t pt;
237
+  if (tagToPoint(mydata.highlightedTag, pt)) {
238
+    const float val = ExtUI::getMeshPoint(pt);
239
+    return (isnan(val) && nanAsZero) ? 0 : val;
236 240
   }
237 241
   return NAN;
238 242
 }
239 243
 
240
-void BedMeshScreen::drawHighlightedPointValue() {
241
-  char str[16];
242
-  const float val = getHightlightedValue();
243
-  const bool isGood = !isnan(val);
244
-  if (isGood)
245
-    dtostrf(val, 5, 3, str);
246
-  else
247
-    strcpy_P(str, PSTR("-"));
244
+void BedMeshScreen::setHighlightedValue(float value) {
245
+  xy_uint8_t pt;
246
+  if (tagToPoint(mydata.highlightedTag, pt))
247
+    ExtUI::setMeshPoint(pt, value);
248
+}
249
+
250
+void BedMeshScreen::moveToHighlightedValue() {
251
+  xy_uint8_t pt;
252
+  if (tagToPoint(mydata.highlightedTag, pt))
253
+    ExtUI::moveToMeshPoint(pt, gaugeThickness + mydata.zAdjustment);
254
+}
255
+
256
+void BedMeshScreen::adjustHighlightedValue(float increment) {
257
+  mydata.zAdjustment += increment;
258
+  moveToHighlightedValue();
259
+}
260
+
261
+void BedMeshScreen::saveAdjustedHighlightedValue() {
262
+  if(mydata.zAdjustment) {
263
+    BedMeshScreen::setHighlightedValue(BedMeshScreen::getHighlightedValue(true) + mydata.zAdjustment);
264
+    mydata.zAdjustment = 0;
265
+  }
266
+}
248 267
 
268
+void BedMeshScreen::changeHighlightedValue(uint8_t tag) {
269
+  saveAdjustedHighlightedValue();
270
+  mydata.highlightedTag = tag;
271
+  moveToHighlightedValue();
272
+}
273
+
274
+void BedMeshScreen::drawHighlightedPointValue() {
249 275
   CommandProcessor cmd;
250 276
   cmd.font(Theme::font_medium)
277
+     .colors(normal_btn)
251 278
      .text(Z_LABEL_POS, GET_TEXT_F(MSG_MESH_EDIT_Z))
252
-     .text(Z_VALUE_POS, str)
253
-     .colors(action_btn)
279
+     .font(font_small);
280
+  draw_adjuster(cmd, Z_VALUE_POS, 2, getHighlightedValue(true) + mydata.zAdjustment, GET_TEXT_F(MSG_UNITS_MM), 4, 3);
281
+  cmd.colors(action_btn)
254 282
      .tag(1).button(OKAY_POS, GET_TEXT_F(MSG_BUTTON_OKAY))
255 283
      .tag(0);
256 284
 
@@ -292,19 +320,23 @@ void BedMeshScreen::onRedraw(draw_mode_t what) {
292 320
   }
293 321
 }
294 322
 
295
-bool BedMeshScreen::onTouchStart(uint8_t tag) {
296
-  mydata.highlightedTag = tag;
297
-  return true;
298
-}
299
-
300 323
 bool BedMeshScreen::onTouchEnd(uint8_t tag) {
324
+  constexpr float increment = 0.01;
301 325
   switch (tag) {
302 326
     case 1:
327
+      saveAdjustedHighlightedValue();
328
+      injectCommands_P(PSTR("G29 S1"));
303 329
       GOTO_PREVIOUS();
304 330
       return true;
331
+    case 2: adjustHighlightedValue(-increment); break;
332
+    case 3: adjustHighlightedValue( increment); break;
305 333
     default:
306
-      return false;
334
+        if (tag >= 10)
335
+            changeHighlightedValue(tag);
336
+        else
337
+            return false;
307 338
   }
339
+  return true;
308 340
 }
309 341
 
310 342
 void BedMeshScreen::onMeshUpdate(const int8_t, const int8_t, const float) {
@@ -341,4 +373,11 @@ void BedMeshScreen::startMeshProbe() {
341 373
   injectCommands_P(PSTR(BED_LEVELING_COMMANDS));
342 374
 }
343 375
 
376
+void BedMeshScreen::showMeshEditor() {
377
+  SpinnerDialogBox::enqueueAndWait_P(ExtUI::isMachineHomed() ? F("M420 S1") : F("G28\nM420 S1"));
378
+  // After the spinner, go to this screen.
379
+  current_screen.forget();
380
+  PUSH_SCREEN(BedMeshScreen);
381
+}
382
+
344 383
 #endif // FTDI_BED_MESH_SCREEN

+ 10
- 5
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.h 파일 보기

@@ -32,6 +32,7 @@ struct BedMeshScreenData {
32 32
   } message;
33 33
   uint8_t count;
34 34
   uint8_t highlightedTag;
35
+  float zAdjustment;
35 36
 };
36 37
 
37 38
 class BedMeshScreen : public BaseScreen, public CachedScreen<BED_MESH_SCREEN_CACHE> {
@@ -45,18 +46,22 @@ class BedMeshScreen : public BaseScreen, public CachedScreen<BED_MESH_SCREEN_CAC
45 46
     };
46 47
 
47 48
     static uint8_t pointToTag(uint8_t x, uint8_t y);
48
-    static bool tagToPoint(uint8_t tag, uint8_t &x, uint8_t &y);
49
-    static float getHightlightedValue();
49
+    static bool tagToPoint(uint8_t tag, xy_uint8_t &pt);
50
+    static float getHighlightedValue(bool nanAsZero);
51
+    static void setHighlightedValue(float value);
52
+    static void moveToHighlightedValue();
53
+    static void adjustHighlightedValue(float increment);
54
+    static void saveAdjustedHighlightedValue();
55
+    static void changeHighlightedValue(uint8_t tag);
50 56
     static void drawHighlightedPointValue();
51 57
     static void drawMesh(int16_t x, int16_t y, int16_t w, int16_t h, ExtUI::bed_mesh_t data, uint8_t opts, float autoscale_max = 0.1);
52
-
53 58
   public:
54
-    static void onMeshUpdate(const int8_t x, const int8_t y, const float &val);
59
+    static void onMeshUpdate(const int8_t x, const int8_t y, const float val);
55 60
     static void onMeshUpdate(const int8_t x, const int8_t y, const ExtUI::probe_state_t);
56 61
     static void onEntry();
57 62
     static void onRedraw(draw_mode_t);
58
-    static bool onTouchStart(uint8_t tag);
59 63
     static bool onTouchEnd(uint8_t tag);
60 64
 
61 65
     static void startMeshProbe();
66
+    static void showMeshEditor();
62 67
 };

+ 4
- 4
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/leveling_menu.cpp 파일 보기

@@ -39,7 +39,7 @@ using namespace Theme;
39 39
   #define TITLE_POS          BTN_POS(1,1), BTN_SIZE(2,1)
40 40
   #define LEVEL_AXIS_POS     BTN_POS(1,2), BTN_SIZE(2,1)
41 41
   #define LEVEL_BED_POS      BTN_POS(1,3), BTN_SIZE(2,1)
42
-  #define SHOW_MESH_POS      BTN_POS(1,4), BTN_SIZE(2,1)
42
+  #define EDIT_MESH_POS      BTN_POS(1,4), BTN_SIZE(2,1)
43 43
   #define BLTOUCH_TITLE_POS  BTN_POS(1,6), BTN_SIZE(2,1)
44 44
   #define BLTOUCH_RESET_POS  BTN_POS(1,7), BTN_SIZE(1,1)
45 45
   #define BLTOUCH_TEST_POS   BTN_POS(2,7), BTN_SIZE(1,1)
@@ -50,7 +50,7 @@ using namespace Theme;
50 50
   #define TITLE_POS          BTN_POS(1,1), BTN_SIZE(2,1)
51 51
   #define LEVEL_AXIS_POS     BTN_POS(1,2), BTN_SIZE(2,1)
52 52
   #define LEVEL_BED_POS      BTN_POS(1,3), BTN_SIZE(2,1)
53
-  #define SHOW_MESH_POS      BTN_POS(1,4), BTN_SIZE(2,1)
53
+  #define EDIT_MESH_POS      BTN_POS(1,4), BTN_SIZE(2,1)
54 54
   #define BLTOUCH_TITLE_POS  BTN_POS(1,5), BTN_SIZE(2,1)
55 55
   #define BLTOUCH_RESET_POS  BTN_POS(1,6), BTN_SIZE(1,1)
56 56
   #define BLTOUCH_TEST_POS   BTN_POS(2,6), BTN_SIZE(1,1)
@@ -79,7 +79,7 @@ void LevelingMenu::onRedraw(draw_mode_t what) {
79 79
     #endif
80 80
        .tag(3).button(LEVEL_BED_POS, GET_TEXT_F(MSG_LEVEL_BED))
81 81
        .enabled(ENABLED(HAS_MESH))
82
-       .tag(4).button(SHOW_MESH_POS, GET_TEXT_F(MSG_SHOW_MESH))
82
+       .tag(4).button(EDIT_MESH_POS, GET_TEXT_F(MSG_EDIT_MESH))
83 83
     #if ENABLED(BLTOUCH)
84 84
        .tag(5).button(BLTOUCH_RESET_POS, GET_TEXT_F(MSG_BLTOUCH_RESET))
85 85
        .tag(6).button(BLTOUCH_TEST_POS,  GET_TEXT_F(MSG_BLTOUCH_SELFTEST))
@@ -106,7 +106,7 @@ bool LevelingMenu::onTouchEnd(uint8_t tag) {
106 106
     #endif
107 107
     break;
108 108
     #if ENABLED(AUTO_BED_LEVELING_UBL)
109
-    case 4: GOTO_SCREEN(BedMeshScreen); break;
109
+    case 4: BedMeshScreen::showMeshEditor(); break;
110 110
     #endif
111 111
     #if ENABLED(BLTOUCH)
112 112
     case 5: injectCommands_P(PSTR("M280 P0 S60")); break;

+ 20
- 0
Marlin/src/lcd/extui/ui_api.cpp 파일 보기

@@ -825,6 +825,26 @@ namespace ExtUI {
825 825
           TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
826 826
         }
827 827
       }
828
+      void moveToMeshPoint(const xy_uint8_t &pos, const float &z) {
829
+        #if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
830
+          const feedRate_t old_feedrate = feedrate_mm_s;
831
+          feedrate_mm_s = Z_PROBE_FEEDRATE_FAST;
832
+          destination = current_position;
833
+          destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
834
+          prepare_line_to_destination();
835
+          feedrate_mm_s = XY_PROBE_FEEDRATE;
836
+          destination[X_AXIS] = MESH_MIN_X + pos.x * MESH_X_DIST;
837
+          destination[Y_AXIS] = MESH_MIN_Y + pos.y * MESH_Y_DIST;
838
+          prepare_line_to_destination();
839
+          feedrate_mm_s = Z_PROBE_FEEDRATE_FAST;
840
+          destination[Z_AXIS] = z;
841
+          prepare_line_to_destination();
842
+          feedrate_mm_s = old_feedrate;
843
+        #else
844
+          UNUSED(pos);
845
+          UNUSED(z);
846
+        #endif
847
+      }
828 848
     #endif
829 849
   #endif
830 850
 

+ 1
- 0
Marlin/src/lcd/extui/ui_api.h 파일 보기

@@ -162,6 +162,7 @@ namespace ExtUI {
162 162
       bed_mesh_t& getMeshArray();
163 163
       float getMeshPoint(const xy_uint8_t &pos);
164 164
       void setMeshPoint(const xy_uint8_t &pos, const float &zval);
165
+      void moveToMeshPoint(const xy_uint8_t &pos, const float &z);
165 166
       void onMeshLevelingStart();
166 167
       void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float &zval);
167 168
       inline void onMeshUpdate(const xy_int8_t &pos, const float &zval) { onMeshUpdate(pos.x, pos.y, zval); }

Loading…
취소
저장