Skip to content

Commit 060ddf5

Browse files
thinkyheadratmole
andcommitted
🚸 Support Bed Leveling Mesh > 16x16
Co-Authored-By: raTmole <[email protected]>
1 parent df078ca commit 060ddf5

File tree

13 files changed

+30
-25
lines changed

13 files changed

+30
-25
lines changed

Marlin/src/core/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ typedef float celsius_float_t;
276276
typedef const_float_t const_feedRate_t;
277277
typedef const_float_t const_celsius_float_t;
278278

279+
// Type large enough to count leveling grid points
280+
typedef IF<TERN0(ABL_USES_GRID, (GRID_MAX_POINTS > 255)), uint16_t, uint8_t>::type grid_count_t;
281+
279282
// Conversion macros
280283
#define MMM_TO_MMS(MM_M) feedRate_t(static_cast<float>(MM_M) / 60.0f)
281284
#define MMS_TO_MMM(MM_S) (static_cast<float>(MM_S) * 60.0f)

Marlin/src/feature/bedlevel/ubl/ubl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ struct mesh_index_pair;
4848
typedef struct {
4949
bool C_seen;
5050
int8_t KLS_storage_slot;
51-
uint8_t R_repetition,
52-
V_verbosity,
51+
grid_count_t R_repetition;
52+
uint8_t V_verbosity,
5353
P_phase,
5454
T_map_type;
5555
float B_shim_thickness,

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void unified_bed_leveling::G29() {
351351

352352
// Invalidate one or more nearby mesh points, possibly all.
353353
if (parser.seen('I')) {
354-
uint8_t count = parser.has_value() ? parser.value_byte() : 1;
354+
grid_count_t count = parser.has_value() ? parser.value_ushort() : 1;
355355
bool invalidate_all = count >= GRID_MAX_POINTS;
356356
if (!invalidate_all) {
357357
while (count--) {
@@ -760,14 +760,14 @@ void unified_bed_leveling::shift_mesh_height() {
760760
TERN_(DWIN_LCD_PROUI, DWIN_LevelingStart());
761761

762762
save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
763-
uint8_t count = GRID_MAX_POINTS;
763+
grid_count_t count = GRID_MAX_POINTS;
764764

765765
mesh_index_pair best;
766766
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::G29_START));
767767
do {
768768
if (do_ubl_mesh_map) display_map(param.T_map_type);
769769

770-
const uint8_t point_num = (GRID_MAX_POINTS - count) + 1;
770+
const grid_count_t point_num = (GRID_MAX_POINTS - count) + 1;
771771
SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, ".");
772772
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS)));
773773

@@ -1135,7 +1135,7 @@ bool unified_bed_leveling::G29_parse_parameters() {
11351135
param.R_repetition = 0;
11361136

11371137
if (parser.seen('R')) {
1138-
param.R_repetition = parser.has_value() ? parser.value_byte() : GRID_MAX_POINTS;
1138+
param.R_repetition = parser.has_value() ? parser.value_ushort() : GRID_MAX_POINTS;
11391139
NOMORE(param.R_repetition, GRID_MAX_POINTS);
11401140
if (param.R_repetition < 1) {
11411141
SERIAL_ECHOLNPGM("?(R)epetition count invalid (1+).\n");

Marlin/src/gcode/bedlevel/G26.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void GcodeSuite::G26() {
628628
}
629629

630630
// Get repeat from 'R', otherwise do one full circuit
631-
int16_t g26_repeats;
631+
grid_count_t g26_repeats;
632632
#if HAS_MARLINUI_MENU
633633
g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1);
634634
#else

Marlin/src/gcode/bedlevel/abl/G29.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ class G29_State {
102102
#endif
103103

104104
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
105-
int abl_points;
105+
grid_count_t abl_points;
106106
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
107-
static constexpr int abl_points = 3;
107+
static constexpr grid_count_t abl_points = 3;
108108
#elif ABL_USES_GRID
109-
static constexpr int abl_points = GRID_MAX_POINTS;
109+
static constexpr grid_count_t abl_points = GRID_MAX_POINTS;
110110
#endif
111111

112112
#if ABL_USES_GRID
@@ -132,16 +132,16 @@ class G29_State {
132132

133133
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
134134
int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
135-
float eqnAMatrix[(GRID_MAX_POINTS) * 3], // "A" matrix of the linear system of equations
136-
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
135+
float eqnAMatrix[GRID_MAX_POINTS * 3], // "A" matrix of the linear system of equations
136+
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
137137
mean;
138138
#endif
139139
#endif
140140
};
141141

142142
#if ABL_USES_GRID && EITHER(AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR)
143143
constexpr xy_uint8_t G29_State::grid_points;
144-
constexpr int G29_State::abl_points;
144+
constexpr grid_count_t G29_State::abl_points;
145145
#endif
146146

147147
/**
@@ -677,7 +677,7 @@ G29_TYPE GcodeSuite::G29() {
677677
zig ^= true; // zag
678678

679679
// An index to print current state
680-
uint8_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;
680+
grid_count_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;
681681

682682
// Inner loop is Y with PROBE_Y_FIRST enabled
683683
// Inner loop is X with PROBE_Y_FIRST disabled

Marlin/src/gcode/bedlevel/mbl/G29.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void GcodeSuite::G29() {
173173
SET_SOFT_ENDSTOP_LOOSE(false);
174174
}
175175
// If there's another point to sample, move there with optional lift.
176-
if (mbl_probe_index < (GRID_MAX_POINTS)) {
176+
if (mbl_probe_index < GRID_MAX_POINTS) {
177177
// Disable software endstops to allow manual adjustment
178178
// If G29 is left hanging without completion they won't be re-enabled!
179179
SET_SOFT_ENDSTOP_LOOSE(true);

Marlin/src/inc/SanityCheck.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,8 +1498,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
14981498
#error "AUTO_BED_LEVELING_UBL does not yet support POLAR printers."
14991499
#elif DISABLED(EEPROM_SETTINGS)
15001500
#error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS."
1501-
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 15) || !WITHIN(GRID_MAX_POINTS_Y, 3, 15)
1502-
#error "GRID_MAX_POINTS_[XY] must be a whole number between 3 and 15."
1501+
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 255) || !WITHIN(GRID_MAX_POINTS_Y, 3, 255)
1502+
#error "GRID_MAX_POINTS_[XY] must be between 3 and 255."
15031503
#endif
15041504

15051505
#elif HAS_ABL_NOT_UBL
@@ -1513,6 +1513,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
15131513
*/
15141514
#if IS_SCARA && DISABLED(AUTO_BED_LEVELING_BILINEAR)
15151515
#error "SCARA machines can only use the AUTO_BED_LEVELING_BILINEAR leveling option."
1516+
#elif ABL_USES_GRID && !(WITHIN(GRID_MAX_POINTS_X, 3, 255) && WITHIN(GRID_MAX_POINTS_Y, 3, 255))
1517+
#error "GRID_MAX_POINTS_[XY] must be between 3 and 255."
15161518
#endif
15171519

15181520
#elif ENABLED(MESH_BED_LEVELING)

Marlin/src/lcd/e3v2/jyersui/dwin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ bool livemove = false;
202202
bool liveadjust = false;
203203
uint8_t preheatmode = 0;
204204
float zoffsetvalue = 0;
205-
uint8_t gridpoint;
205+
grid_count_t gridpoint;
206206
float corner_avg;
207207
float corner_pos;
208208

Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ namespace Anycubic {
549549
bool msg_matched = false;
550550

551551
#if HAS_LEVELING
552-
static uint8_t probe_cnt = 0;
552+
static grid_count_t probe_cnt = 0;
553553
#endif
554554

555555
// The only way to get printer status is to parse messages
@@ -564,7 +564,7 @@ namespace Anycubic {
564564
// If probing completes ok save the mesh and park
565565
// Ignore the custom machine name
566566
if (strcmp_P(msg + strlen(MACHINE_NAME), MARLIN_msg_ready) == 0) {
567-
if (probe_cnt == GRID_MAX_POINTS_X * GRID_MAX_POINTS_Y) {
567+
if (probe_cnt == GRID_MAX_POINTS) {
568568
probe_cnt = 0;
569569
injectCommands(F("M500")); // G27 park nozzle
570570
//ChangePageOfTFT(PAGE_PreLEVEL);

Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void DGUSScreenHandlerMKS::LanguageChange(DGUS_VP_Variable &var, void *val_ptr)
415415
}
416416

417417
#if ENABLED(MESH_BED_LEVELING)
418-
uint8_t mesh_point_count = GRID_MAX_POINTS;
418+
grid_count_t mesh_point_count = GRID_MAX_POINTS;
419419
#endif
420420

421421
void DGUSScreenHandlerMKS::Level_Ctrl(DGUS_VP_Variable &var, void *val_ptr) {

0 commit comments

Comments
 (0)