21
21
*/
22
22
23
23
/* *
24
- * UBL Tools and Mesh Viewer for Pro UI
25
- * Version: 1.0.0
26
- * Date: 2022/04/13
24
+ * Bed Level Tools for Pro UI
25
+ * Extended by: Miguel A. Risco-Castillo (MRISCOC)
26
+ * Version: 2.0.0
27
+ * Date: 2022/05/23
27
28
*
28
- * Original Author : Henri-J-Norden
29
- * Original Source: https://github.com/Jyers/Marlin/pull/126
29
+ * Based on the original work of : Henri-J-Norden
30
+ * https://github.com/Jyers/Marlin/pull/126
30
31
*/
31
32
32
33
#include " ../../../inc/MarlinConfigPre.h"
34
+ #include " bedlevel_tools.h"
33
35
34
- #if BOTH(DWIN_LCD_PROUI, AUTO_BED_LEVELING_UBL )
36
+ #if BOTH(DWIN_LCD_PROUI, HAS_LEVELING )
35
37
36
- #include " ubl_tools.h"
37
38
#include " ../../marlinui.h"
38
39
#include " ../../../core/types.h"
39
40
#include " dwin.h"
47
48
#include " ../../../libs/least_squares_fit.h"
48
49
#include " ../../../libs/vector_3.h"
49
50
50
- UBLMeshToolsClass ubl_tools ;
51
+ BedLevelToolsClass BedLevelTools ;
51
52
52
- #if ENABLED( USE_UBL_VIEWER)
53
- bool UBLMeshToolsClass ::viewer_asymmetric_range = false ;
54
- bool UBLMeshToolsClass ::viewer_print_value = false ;
53
+ #if USE_UBL_VIEWER
54
+ bool BedLevelToolsClass ::viewer_asymmetric_range = false ;
55
+ bool BedLevelToolsClass ::viewer_print_value = false ;
55
56
#endif
56
- bool UBLMeshToolsClass::goto_mesh_value = false ;
57
- uint8_t UBLMeshToolsClass::tilt_grid = 1 ;
57
+ bool BedLevelToolsClass::goto_mesh_value = false ;
58
+ uint8_t BedLevelToolsClass::mesh_x = 0 ;
59
+ uint8_t BedLevelToolsClass::mesh_y = 0 ;
60
+ uint8_t BedLevelToolsClass::tilt_grid = 1 ;
58
61
59
62
bool drawing_mesh = false ;
60
63
char cmd[MAX_CMD_SIZE+16 ], str_1[16 ], str_2[16 ], str_3[16 ];
61
64
62
65
#if ENABLED(AUTO_BED_LEVELING_UBL)
63
66
64
- void UBLMeshToolsClass ::manual_value_update (const uint8_t mesh_x, const uint8_t mesh_y, bool undefined/* =false*/ ) {
67
+ void BedLevelToolsClass ::manual_value_update (const uint8_t mesh_x, const uint8_t mesh_y, bool undefined/* =false*/ ) {
65
68
sprintf_P (cmd, PSTR (" M421 I%i J%i Z%s %s" ), mesh_x, mesh_y, dtostrf (current_position.z , 1 , 3 , str_1), undefined ? " N" : " " );
66
69
gcode.process_subcommands_now (cmd);
67
70
planner.synchronize ();
68
71
}
69
72
70
- bool UBLMeshToolsClass ::create_plane_from_mesh () {
73
+ bool BedLevelToolsClass ::create_plane_from_mesh () {
71
74
struct linear_fit_data lsf_results;
72
75
incremental_LSF_reset (&lsf_results);
73
76
GRID_LOOP (x, y) {
@@ -119,15 +122,16 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
119
122
120
123
#else
121
124
122
- void UBLMeshToolsClass ::manual_value_update (const uint8_t mesh_x, const uint8_t mesh_y) {
125
+ void BedLevelToolsClass ::manual_value_update (const uint8_t mesh_x, const uint8_t mesh_y) {
123
126
sprintf_P (cmd, PSTR (" G29 I%i J%i Z%s" ), mesh_x, mesh_y, dtostrf (current_position.z , 1 , 3 , str_1));
124
127
gcode.process_subcommands_now (cmd);
125
128
planner.synchronize ();
126
129
}
127
130
128
131
#endif
129
132
130
- void UBLMeshToolsClass::manual_move (const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/* =false*/ ) {
133
+ void BedLevelToolsClass::manual_move (const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/* =false*/ ) {
134
+ gcode.process_subcommands_now (F (" G28O" ));
131
135
if (zmove) {
132
136
planner.synchronize ();
133
137
current_position.z = goto_mesh_value ? bedlevel.z_values [mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
@@ -149,16 +153,36 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
149
153
}
150
154
}
151
155
152
- float UBLMeshToolsClass::get_max_value () {
153
- float max = __FLT_MIN__;
156
+ void BedLevelToolsClass::MoveToXYZ () {
157
+ BedLevelTools.goto_mesh_value = true ;
158
+ BedLevelTools.manual_move (BedLevelTools.mesh_x , BedLevelTools.mesh_y , false );
159
+ }
160
+ void BedLevelToolsClass::MoveToXY () {
161
+ BedLevelTools.goto_mesh_value = false ;
162
+ BedLevelTools.manual_move (BedLevelTools.mesh_x , BedLevelTools.mesh_y , false );
163
+ }
164
+ void BedLevelToolsClass::MoveToZ () {
165
+ BedLevelTools.goto_mesh_value = true ;
166
+ BedLevelTools.manual_move (BedLevelTools.mesh_x , BedLevelTools.mesh_y , true );
167
+ }
168
+ void BedLevelToolsClass::ProbeXY () {
169
+ sprintf_P (cmd, PSTR (" G30X%sY%s" ),
170
+ dtostrf (bedlevel.get_mesh_x (BedLevelTools.mesh_x ), 1 , 2 , str_1),
171
+ dtostrf (bedlevel.get_mesh_y (BedLevelTools.mesh_y ), 1 , 2 , str_2)
172
+ );
173
+ gcode.process_subcommands_now (cmd);
174
+ }
175
+
176
+ float BedLevelToolsClass::get_max_value () {
177
+ float max = __FLT_MAX__ * -1 ;
154
178
GRID_LOOP (x, y) {
155
179
if (!isnan (bedlevel.z_values [x][y]) && bedlevel.z_values [x][y] > max)
156
180
max = bedlevel.z_values [x][y];
157
181
}
158
182
return max;
159
183
}
160
184
161
- float UBLMeshToolsClass ::get_min_value () {
185
+ float BedLevelToolsClass ::get_min_value () {
162
186
float min = __FLT_MAX__;
163
187
GRID_LOOP (x, y) {
164
188
if (!isnan (bedlevel.z_values [x][y]) && bedlevel.z_values [x][y] < min)
@@ -167,19 +191,20 @@ float UBLMeshToolsClass::get_min_value() {
167
191
return min;
168
192
}
169
193
170
- bool UBLMeshToolsClass::validate () {
171
- float min = __FLT_MAX__, max = __FLT_MIN__ ;
194
+ bool BedLevelToolsClass::meshvalidate () {
195
+ float min = __FLT_MAX__, max = __FLT_MAX__ * - 1 ;
172
196
173
197
GRID_LOOP (x, y) {
174
198
if (isnan (bedlevel.z_values [x][y])) return false ;
175
199
if (bedlevel.z_values [x][y] < min) min = bedlevel.z_values [x][y];
176
200
if (bedlevel.z_values [x][y] > max) max = bedlevel.z_values [x][y];
177
201
}
178
- return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN ;
202
+ return WITHIN ( max, MESH_Z_OFFSET_MIN, MESH_Z_OFFSET_MAX) ;
179
203
}
180
204
181
- #if ENABLED(USE_UBL_VIEWER)
182
- void UBLMeshToolsClass::Draw_Bed_Mesh (int16_t selected /* = -1*/ , uint8_t gridline_width /* = 1*/ , uint16_t padding_x /* = 8*/ , uint16_t padding_y_top /* = 40 + 53 - 7*/ ) {
205
+ #if USE_UBL_VIEWER
206
+
207
+ void BedLevelToolsClass::Draw_Bed_Mesh (int16_t selected /* = -1*/ , uint8_t gridline_width /* = 1*/ , uint16_t padding_x /* = 8*/ , uint16_t padding_y_top /* = 40 + 53 - 7*/ ) {
183
208
drawing_mesh = true ;
184
209
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
185
210
const uint16_t cell_width_px = total_width_px / (GRID_MAX_POINTS_X);
@@ -237,7 +262,7 @@ bool UBLMeshToolsClass::validate() {
237
262
}
238
263
}
239
264
240
- void UBLMeshToolsClass ::Set_Mesh_Viewer_Status () { // TODO: draw gradient with values as a legend instead
265
+ void BedLevelToolsClass ::Set_Mesh_Viewer_Status () { // TODO: draw gradient with values as a legend instead
241
266
float v_max = abs (get_max_value ()), v_min = abs (get_min_value ()), range = _MAX (v_min, v_max);
242
267
if (v_min > 3e+10F ) v_min = 0.0000001 ;
243
268
if (v_max > 3e+10F ) v_max = 0.0000001 ;
@@ -255,6 +280,7 @@ bool UBLMeshToolsClass::validate() {
255
280
ui.set_status (msg);
256
281
drawing_mesh = false ;
257
282
}
258
- #endif
259
283
260
- #endif // DWIN_LCD_PROUI && AUTO_BED_LEVELING_UBL
284
+ #endif // USE_UBL_VIEWER
285
+
286
+ #endif // DWIN_LCD_PROUI && HAS_LEVELING
0 commit comments