Skip to content

Commit e2d45ec

Browse files
committed
format, clean up
1 parent ab117e4 commit e2d45ec

File tree

7 files changed

+79
-98
lines changed

7 files changed

+79
-98
lines changed

Marlin/Configuration.h

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,32 +2107,35 @@
21072107
//#define AUTO_BED_LEVELING_UBL
21082108
//#define MESH_BED_LEVELING
21092109

2110-
/* When a level probe is fitted but not used for homing, enabling USE_PROBE_FOR_MESH_REF will avoid a level mesh
2111-
* being created with an unwanted offset between the fixed Z endstop/Homing Switch and probe trigger height. The
2110+
/**
2111+
* When a level probe is fitted but not used for homing, enabling USE_PROBE_FOR_MESH_REF will avoid a level mesh
2112+
* being created with an unwanted offset between the fixed Z endstop/Homing Switch and probe trigger height. The
21122113
* probe Z offset menu option is removed from the level sub menu, as entering a Z offset there would shift the mesh
21132114
* and the Homeing position giving confusing status values for Z. It is recomended not to enter a Z offset value in
21142115
* the probe offset section of config.h for the same reason.
2115-
*
2116-
* If no Z offsets are entered elsewhere the status screen will always show the actual Z possition. e.g when homing
2117-
* the Z status will show 0 at the Home position, unless the height of the fixed Z stop/Homeing switch above the bed
2118-
* has been set by the HOME_SWITCH_TO_BED_OFFSET_MENU option while creating a level mesh. In which case the Home
2119-
* position will show as that height. The printer will move down to the print height when printing starts and Z status
2116+
*
2117+
* If no Z offsets are entered elsewhere the status screen will always show the actual Z possition. e.g when homing
2118+
* the Z status will show 0 at the Home position, unless the height of the fixed Z stop/Homeing switch above the bed
2119+
* has been set by the HOME_SWITCH_TO_BED_OFFSET_MENU option while creating a level mesh. In which case the Home
2120+
* position will show as that height. The printer will move down to the print height when printing starts and Z status
21202121
* will show the first layer height. The Nozzle will follow the mesh and baby stepping can be used to temporarily lower
21212122
* or raise the nozzle to adjust first layer squish.
2122-
*
2123+
*
21232124
* If your Z stop/Homeing switch has a fine adjustment capability, the HOME_SWITCH_TO_BED_OFFSET_MENU menu option can be
21242125
* left at zero or disabled. Using the paper pinch test and setting the Z stop/Homeing switch position works just as well.
21252126
*/
2126-
#ifndef USE_PROBE_FOR_Z_HOMING
2127-
#if defined AUTO_BED_LEVELING_BILINEAR || defined AUTO_BED_LEVELING_UBL || defined AUTO_BED_LEVELING_LINEAR || defined AUTO_BED_LEVELING_3POINT
2128-
//#define USE_PROBE_FOR_MESH_REF
2129-
#ifdef USE_PROBE_FOR_MESH_REF
2130-
/*optional HOME_SWITCH_TO_BED_OFFSET_MENU enables a menu option called "Home Offset Z" to adjust the Z offset between
2131-
* the Fixed Z endstop/Homing switch and the bed. This offset is only used to adjust the level mesh down
2132-
* to the Zero plane (Bed) as the mesh is created, so a new level mesh must be created when if it is changed to apply it.*/
2133-
#define HOME_SWITCH_TO_BED_OFFSET_MENU
2134-
#endif
2135-
#endif
2127+
#if DISABLED(USE_PROBE_FOR_Z_HOMING)
2128+
#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
2129+
//#define USE_PROBE_FOR_MESH_REF
2130+
#if ENABLED(USE_PROBE_FOR_MESH_REF)
2131+
/**
2132+
* HOME_SWITCH_TO_BED_OFFSET_MENU enables a menu option called "Home Offset Z" to adjust the Z offset between
2133+
* the Fixed Z endstop/Homing switch and the bed. This offset is only used to adjust the level mesh down
2134+
* to the Zero plane (Bed) as the mesh is created, so a new level mesh must be created when if it is changed to apply it.
2135+
*/
2136+
//#define HOME_SWITCH_TO_BED_OFFSET_MENU
2137+
#endif
2138+
#endif
21362139
#endif
21372140

21382141
/**

Marlin/src/feature/bedlevel/bedlevel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
bool g29_in_progress = false;
3636
#endif
3737

38+
#if ENABLED(USE_PROBE_FOR_MESH_REF)
39+
float mesh_zero_ref_offset = 0; // declared in gcode.h as external so it can be set in menu_probe_level.cpp
40+
#endif
41+
3842
#if ENABLED(LCD_BED_LEVELING)
3943
#include "../../lcd/marlinui.h"
4044
#endif

Marlin/src/feature/bedlevel/bedlevel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
constexpr bool g29_in_progress = false;
3434
#endif
3535

36+
#if ENABLED(USE_PROBE_FOR_MESH_REF)
37+
extern float mesh_zero_ref_offset;
38+
#endif
39+
3640
bool leveling_is_valid();
3741
void set_bed_leveling_enabled(const bool enable=true);
3842
void reset_bed_level();

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

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@
7474
#define SIZE_OF_LITTLE_RAISE 1
7575
#define BIG_RAISE_NOT_NEEDED 0
7676

77-
#ifdef USE_PROBE_FOR_MESH_REF
78-
float mesh_zero_ref_offset = 0; // declared in gcode.h as external so it can be set in menu_probe_level.cpp
79-
#endif
80-
8177
/**
8278
* G29: Unified Bed Leveling by Roxy
8379
*
@@ -325,28 +321,26 @@ void unified_bed_leveling::G29() {
325321
if (may_move) {
326322
planner.synchronize();
327323

328-
#ifdef USE_PROBE_FOR_MESH_REF
329-
// Send 'N' to force homing before G29 (internal only)
330-
if (axes_should_home() || parser.seen_test('N')){
331-
gcode.home_all_axes();
332-
}
333-
else {
334-
gcode.process_subcommands_now(F("G28L0 X Y")); // Home X and Y only
335-
}
336-
// Set the probe trigger height as Z home before leveling
337-
probe.probe_at_point(current_position, PROBE_PT_NONE,0 ,false ,true, Z_PROBE_LOW_POINT, Z_TWEEN_SAFE_CLEARANCE, false);
338-
set_axis_is_at_home(Z_AXIS);
339-
sync_plan_position();
340-
#else
341-
#if ALL(DWIN_LCD_PROUI, ZHOME_BEFORE_LEVELING)
342-
save_ubl_active_state_and_disable();
343-
gcode.process_subcommands_now(F("G28Z"));
344-
restore_ubl_active_state(false); // ...without telling ExtUI "done"
345-
#else
346-
// Send 'N' to force homing before G29 (internal only)
347-
if (axes_should_home() || parser.seen_test('N')) gcode.home_all_axes();
348-
#endif
349-
#endif
324+
#if ENABLED(USE_PROBE_FOR_MESH_REF)
325+
// Send 'N' to force homing before G29 (internal only)
326+
if (axes_should_home() || parser.seen_test('N')) {
327+
gcode.home_all_axes();
328+
}
329+
else {
330+
gcode.process_subcommands_now(F("G28L0 X Y")); // Home X and Y only
331+
}
332+
// Set the probe trigger height as Z home before leveling
333+
probe.probe_at_point(current_position, PROBE_PT_NONE,0 ,false ,true, Z_PROBE_LOW_POINT, Z_TWEEN_SAFE_CLEARANCE, false);
334+
set_axis_is_at_home(Z_AXIS);
335+
sync_plan_position();
336+
#elif ALL(DWIN_LCD_PROUI, ZHOME_BEFORE_LEVELING)
337+
save_ubl_active_state_and_disable();
338+
gcode.process_subcommands_now(F("G28Z"));
339+
restore_ubl_active_state(false); // ...without telling ExtUI "done"
340+
#else
341+
// Send 'N' to force homing before G29 (internal only)
342+
if (axes_should_home() || parser.seen_test('N')) gcode.home_all_axes();
343+
#endif
350344

351345
probe.use_probing_tool();
352346

@@ -827,11 +821,7 @@ void unified_bed_leveling::shift_mesh_height() {
827821

828822
if (best.pos.x >= 0) { // mesh point found and is reachable by probe
829823
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::G29_POINT_START));
830-
#ifdef USE_PROBE_FOR_MESH_REF // adjust the mesh point value
831-
const float measured_z = probe.probe_at_point(best.meshpos(), stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, param.V_verbosity) - mesh_zero_ref_offset;
832-
#else
833-
const float measured_z = probe.probe_at_point(best.meshpos(), stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, param.V_verbosity);
834-
#endif
824+
const float measured_z = DIFF_TERN(USE_PROBE_FOR_MESH_REF, probe.probe_at_point(best.meshpos(), stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, param.V_verbosity), mesh_zero_ref_offset);
835825
z_values[best.pos.x][best.pos.y] = isnan(measured_z) ? HUGE_VALF : measured_z; // Mark invalid point already probed with HUGE_VALF to omit it in the next loop
836826
#if ENABLED(EXTENSIBLE_UI)
837827
ExtUI::onMeshUpdate(best.pos, ExtUI::G29_POINT_FINISH);

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

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@
7777
#endif
7878
#endif
7979

80-
#ifdef USE_PROBE_FOR_MESH_REF
81-
float mesh_zero_ref_offset = 0; // declared in gcode.h as external so it can be set in menu_probe_level.cpp
82-
#endif
83-
8480
/**
8581
* @brief Do some things before returning from G29.
8682
* @param retry : true if the G29 can and should be retried. false if the failure is too serious.
@@ -141,7 +137,7 @@ class G29_State {
141137
#endif
142138

143139
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
144-
float Z_offset;
140+
float z_offset;
145141
bed_mesh_t z_values;
146142
#endif
147143

@@ -267,13 +263,13 @@ G29_TYPE GcodeSuite::G29() {
267263
G29_RETURN(false, false);
268264
}
269265

270-
#ifdef USE_PROBE_FOR_MESH_REF
266+
#if ENABLED(USE_PROBE_FOR_MESH_REF)
271267
// Send 'N' to force homing before G29 (internal only)
272268
if (parser.seen_test('N')){
273-
process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
274-
}
269+
process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
270+
}
275271
else {
276-
process_subcommands_now(F("G28L0 X Y")); // Home X and Y only
272+
process_subcommands_now(F("G28L0 X Y")); // Home X and Y only
277273
}
278274
// Set the probe trigger height as Z home before leveling
279275
probe.probe_at_point(current_position, PROBE_PT_NONE,0 ,false ,true, Z_PROBE_LOW_POINT, Z_TWEEN_SAFE_CLEARANCE, false);
@@ -282,8 +278,8 @@ G29_TYPE GcodeSuite::G29() {
282278
#else
283279
// Send 'N' to force homing before G29 (internal only)
284280
if (parser.seen_test('N')){
285-
process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
286-
}
281+
process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
282+
}
287283
#endif
288284

289285
// Don't allow auto-leveling without homing first
@@ -418,7 +414,7 @@ G29_TYPE GcodeSuite::G29() {
418414

419415
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
420416

421-
abl.Z_offset = parser.linearval('Z');
417+
abl.z_offset = parser.linearval('Z');
422418

423419
#endif
424420

@@ -611,19 +607,11 @@ G29_TYPE GcodeSuite::G29() {
611607

612608
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
613609

614-
#ifdef USE_PROBE_FOR_MESH_REF
615-
const float newz = abl.measured_z + mesh_zero_ref_offset;
616-
#else
617-
const float newz = abl.measured_z + abl.Z_offset;
618-
#endif
610+
const float newz = abl.measured_z + TERN(USE_PROBE_FOR_MESH_REF, mesh_zero_ref_offset, abl.z_offset);
619611
abl.z_values[abl.meshCount.x][abl.meshCount.y] = newz;
620612
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, newz));
621613

622-
#ifdef USE_PROBE_FOR_MESH_REF
623-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM_P(PSTR("Save X"), abl.meshCount.x, SP_Y_STR, abl.meshCount.y, SP_Z_STR, abl.measured_z + mesh_zero_ref_offset);
624-
#else
625-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM_P(PSTR("Save X"), abl.meshCount.x, SP_Y_STR, abl.meshCount.y, SP_Z_STR, abl.measured_z + abl.Z_offset);
626-
#endif
614+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM_P(PSTR("Save X"), abl.meshCount.x, SP_Y_STR, abl.meshCount.y, SP_Z_STR, newz);
627615

628616
#endif
629617
}
@@ -825,11 +813,7 @@ G29_TYPE GcodeSuite::G29() {
825813

826814
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
827815

828-
#ifdef USE_PROBE_FOR_MESH_REF
829-
const float z = abl.measured_z + mesh_zero_ref_offset;
830-
#else
831-
const float z = abl.measured_z + abl.Z_offset;
832-
#endif
816+
const float z = abl.measured_z + TERN(USE_PROBE_FOR_MESH_REF, mesh_zero_ref_offset, abl.z_offset);
833817

834818
abl.z_values[abl.meshCount.x][abl.meshCount.y] = z;
835819
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));

Marlin/src/gcode/gcode.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,6 @@ typedef bits_t(NUM_REL_MODES) relative_t;
375375

376376
extern const char G28_STR[];
377377

378-
#ifdef USE_PROBE_FOR_MESH_REF
379-
extern float mesh_zero_ref_offset;
380-
#endif
381-
382378
class GcodeSuite {
383379
public:
384380

Marlin/src/lcd/menu/menu_probe_level.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "../../inc/MarlinConfigPre.h"
2828

29-
#ifdef USE_PROBE_FOR_MESH_REF
29+
#if ENABLED(USE_PROBE_FOR_MESH_REF)
3030
#include "../../gcode/gcode.h"
3131
#endif
3232

@@ -347,24 +347,24 @@ void menu_probe_level() {
347347
//
348348
// Probe Z Offset - Babystep or Edit
349349
//
350-
if (can_babystep_z) {
351-
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
352-
SUBMENU(MSG_BABYSTEP_PROBE_Z, lcd_babystep_zoffset);
353-
#endif
354-
}
355-
else {
356-
#if HAS_BED_PROBE
357-
#ifdef USE_PROBE_FOR_MESH_REF
358-
#ifdef HOME_SWITCH_TO_BED_OFFSET_MENU
359-
// Change the name of the menu option as the offsett relates to the fixed Z stop/Homing switch but
360-
// reduce the range to -1/+1 and use the same offset variable so function stays the same
361-
EDIT_ITEM_N(LCD_Z_OFFSET_TYPE, Z_AXIS, MSG_HOME_OFFSET_Z, &mesh_zero_ref_offset, -1, 0);
362-
#endif
363-
#else
350+
#if HAS_BED_PROBE
351+
352+
if (can_babystep_z) {
353+
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
354+
SUBMENU(MSG_BABYSTEP_PROBE_Z, lcd_babystep_zoffset);
355+
#endif
356+
}
357+
else {
358+
#if DISABLED(USE_PROBE_FOR_MESH_REF)
364359
EDIT_ITEM_N(LCD_Z_OFFSET_TYPE, Z_AXIS, MSG_ZPROBE_OFFSET_N, &probe.offset.z, PROBE_OFFSET_ZMIN, PROBE_OFFSET_ZMAX);
365-
#endif
366-
#endif
367-
}
360+
#elif ENABLED(HOME_SWITCH_TO_BED_OFFSET_MENU)
361+
// Change the name of the menu option as the offsett relates to the fixed Z stop/Homing switch but
362+
// reduce the range to -1/+1 and use the same offset variable so function stays the same
363+
EDIT_ITEM_N(LCD_Z_OFFSET_TYPE, Z_AXIS, MSG_HOME_OFFSET_Z, &mesh_zero_ref_offset, -1, 0);
364+
#endif
365+
}
366+
367+
#endif // HAS_BED_PROBE
368368

369369
//
370370
// Probe Z Offset Wizard

0 commit comments

Comments
 (0)