Skip to content

Commit bd017e8

Browse files
mriscocLCh-77
authored andcommitted
🚸 Fix and update ProUI (MarlinFirmware#24477)
1 parent 0c3f1dc commit bd017e8

17 files changed

+376
-303
lines changed

Marlin/src/lcd/e3v2/common/dwin_font.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
#pragma once
2323

24+
typedef uint8_t fontid_t;
25+
2426
/**
2527
* 3-.0:The font size, 0x00-0x09, corresponds to the font size below:
2628
* 0x00=6*12 0x01=8*16 0x02=10*20 0x03=12*24 0x04=14*28

Marlin/src/lcd/e3v2/proui/ubl_tools.cpp Marlin/src/lcd/e3v2/proui/bedlevel_tools.cpp

+54-28
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@
2121
*/
2222

2323
/**
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
2728
*
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
3031
*/
3132

3233
#include "../../../inc/MarlinConfigPre.h"
34+
#include "bedlevel_tools.h"
3335

34-
#if BOTH(DWIN_LCD_PROUI, AUTO_BED_LEVELING_UBL)
36+
#if BOTH(DWIN_LCD_PROUI, HAS_LEVELING)
3537

36-
#include "ubl_tools.h"
3738
#include "../../marlinui.h"
3839
#include "../../../core/types.h"
3940
#include "dwin.h"
@@ -47,27 +48,29 @@
4748
#include "../../../libs/least_squares_fit.h"
4849
#include "../../../libs/vector_3.h"
4950

50-
UBLMeshToolsClass ubl_tools;
51+
BedLevelToolsClass BedLevelTools;
5152

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;
5556
#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;
5861

5962
bool drawing_mesh = false;
6063
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
6164

6265
#if ENABLED(AUTO_BED_LEVELING_UBL)
6366

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*/) {
6568
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" : "");
6669
gcode.process_subcommands_now(cmd);
6770
planner.synchronize();
6871
}
6972

70-
bool UBLMeshToolsClass::create_plane_from_mesh() {
73+
bool BedLevelToolsClass::create_plane_from_mesh() {
7174
struct linear_fit_data lsf_results;
7275
incremental_LSF_reset(&lsf_results);
7376
GRID_LOOP(x, y) {
@@ -119,15 +122,16 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
119122

120123
#else
121124

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) {
123126
sprintf_P(cmd, PSTR("G29 I%i J%i Z%s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1));
124127
gcode.process_subcommands_now(cmd);
125128
planner.synchronize();
126129
}
127130

128131
#endif
129132

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"));
131135
if (zmove) {
132136
planner.synchronize();
133137
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,
149153
}
150154
}
151155

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;
154178
GRID_LOOP(x, y) {
155179
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
156180
max = bedlevel.z_values[x][y];
157181
}
158182
return max;
159183
}
160184

161-
float UBLMeshToolsClass::get_min_value() {
185+
float BedLevelToolsClass::get_min_value() {
162186
float min = __FLT_MAX__;
163187
GRID_LOOP(x, y) {
164188
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
@@ -167,19 +191,20 @@ float UBLMeshToolsClass::get_min_value() {
167191
return min;
168192
}
169193

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;
172196

173197
GRID_LOOP(x, y) {
174198
if (isnan(bedlevel.z_values[x][y])) return false;
175199
if (bedlevel.z_values[x][y] < min) min = bedlevel.z_values[x][y];
176200
if (bedlevel.z_values[x][y] > max) max = bedlevel.z_values[x][y];
177201
}
178-
return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
202+
return WITHIN(max, MESH_Z_OFFSET_MIN, MESH_Z_OFFSET_MAX);
179203
}
180204

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*/) {
183208
drawing_mesh = true;
184209
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
185210
const uint16_t cell_width_px = total_width_px / (GRID_MAX_POINTS_X);
@@ -237,7 +262,7 @@ bool UBLMeshToolsClass::validate() {
237262
}
238263
}
239264

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
241266
float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
242267
if (v_min > 3e+10F) v_min = 0.0000001;
243268
if (v_max > 3e+10F) v_max = 0.0000001;
@@ -255,6 +280,7 @@ bool UBLMeshToolsClass::validate() {
255280
ui.set_status(msg);
256281
drawing_mesh = false;
257282
}
258-
#endif
259283

260-
#endif // DWIN_LCD_PROUI && AUTO_BED_LEVELING_UBL
284+
#endif // USE_UBL_VIEWER
285+
286+
#endif // DWIN_LCD_PROUI && HAS_LEVELING
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/**
2-
* UBL Tools and Mesh Viewer for Pro UI
3-
* Version: 1.0.0
4-
* Date: 2022/04/13
1+
/*
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
54
*
6-
* Original Author: Henri-J-Norden (https://github.com/Henri-J-Norden)
7-
* Original Source: https://github.com/Jyers/Marlin/pull/135
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
87
*
98
* This program is free software: you can redistribute it and/or modify
109
* it under the terms of the GNU General Public License as published by
@@ -20,22 +19,37 @@
2019
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2120
*
2221
*/
22+
23+
/**
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
28+
*
29+
* Based on the original work of: Henri-J-Norden
30+
* https://github.com/Jyers/Marlin/pull/126
31+
*/
32+
2333
#pragma once
2434

2535
#include "../../../inc/MarlinConfigPre.h"
2636

27-
//#define USE_UBL_VIEWER 1
37+
#if ENABLED(AUTO_BED_LEVELING_UBL)
38+
//#define USE_UBL_VIEWER 1
39+
#endif
2840

29-
#define UBL_Z_OFFSET_MIN -3.0
30-
#define UBL_Z_OFFSET_MAX 3.0
41+
#define MESH_Z_OFFSET_MIN -3.0
42+
#define MESH_Z_OFFSET_MAX 3.0
3143

32-
class UBLMeshToolsClass {
44+
class BedLevelToolsClass {
3345
public:
34-
#if ENABLED(USE_UBL_VIEWER)
46+
#if USE_UBL_VIEWER
3547
static bool viewer_asymmetric_range;
3648
static bool viewer_print_value;
3749
#endif
3850
static bool goto_mesh_value;
51+
static uint8_t mesh_x;
52+
static uint8_t mesh_y;
3953
static uint8_t tilt_grid;
4054

4155
#if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -45,15 +59,19 @@ class UBLMeshToolsClass {
4559
static void manual_value_update(const uint8_t mesh_x, const uint8_t mesh_y);
4660
#endif
4761
static void manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove=false);
62+
static void MoveToXYZ();
63+
static void MoveToXY();
64+
static void MoveToZ();
65+
static void ProbeXY();
4866
static float get_max_value();
4967
static float get_min_value();
50-
static bool validate();
51-
#if ENABLED(USE_UBL_VIEWER)
68+
static bool meshvalidate();
69+
#if USE_UBL_VIEWER
5270
static void 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);
5371
static void Set_Mesh_Viewer_Status();
5472
#endif
5573
};
5674

57-
extern UBLMeshToolsClass ubl_tools;
75+
extern BedLevelToolsClass BedLevelTools;
5876

5977
void Goto_MeshViewer();

0 commit comments

Comments
 (0)