Skip to content

Commit 502e7b3

Browse files
committed
Adjust axis homed / trusted methods (MarlinFirmware#20323)
1 parent 1f6ba0c commit 502e7b3

22 files changed

+118
-149
lines changed

Marlin/src/gcode/calibrate/G28.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,14 @@ void GcodeSuite::G28() {
319319

320320
#endif
321321

322-
const float z_homing_height =
323-
ENABLED(UNKNOWN_Z_NO_RAISE) && !TEST(axis_known_position, Z_AXIS)
324-
? 0
325-
: (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT);
322+
const float z_homing_height = TERN1(UNKNOWN_Z_NO_RAISE, axis_is_trusted(Z_AXIS))
323+
? (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
324+
: 0;
326325

327326
if (z_homing_height && (doX || doY || TERN0(Z_SAFE_HOMING, doZ))) {
328327
// Raise Z before homing any other axes and z is not already high enough (never lower z)
329328
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) by ", z_homing_height);
330-
do_z_clearance(z_homing_height, true, DISABLED(UNKNOWN_Z_NO_RAISE));
329+
do_z_clearance(z_homing_height, axis_is_trusted(Z_AXIS), DISABLED(UNKNOWN_Z_NO_RAISE));
331330
}
332331

333332
#if ENABLED(QUICK_HOME)

Marlin/src/gcode/calibrate/G34.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
void GcodeSuite::G34() {
4040

4141
// Home before the alignment procedure
42-
if (!all_axes_known()) home_all_axes();
42+
if (!all_axes_trusted()) home_all_axes();
4343

4444
SET_SOFT_ENDSTOP_LOOSE(true);
4545
TEMPORARY_BED_LEVELING_STATE(false);

Marlin/src/gcode/calibrate/G34_M422.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void GcodeSuite::G34() {
167167
);
168168

169169
// Home before the alignment procedure
170-
if (!all_axes_known()) home_all_axes();
170+
if (!all_axes_trusted()) home_all_axes();
171171

172172
// Move the Z coordinate realm towards the positive - dirty trick
173173
current_position.z += z_probe * 0.5f;

Marlin/src/gcode/feature/pause/M600.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void GcodeSuite::M600() {
102102

103103
#if ENABLED(HOME_BEFORE_FILAMENT_CHANGE)
104104
// If needed, home before parking for filament change
105-
if (!all_axes_known()) home_all_axes();
105+
if (!all_axes_trusted()) home_all_axes();
106106
#endif
107107

108108
#if HAS_MULTI_EXTRUDER

Marlin/src/gcode/feature/pause/M701_M702.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@
5959
void GcodeSuite::M701() {
6060
xyz_pos_t park_point = NOZZLE_PARK_POINT;
6161

62-
#if ENABLED(NO_MOTION_BEFORE_HOMING)
63-
// Don't raise Z if the machine isn't homed
64-
if (axes_should_home()) park_point.z = 0;
65-
#endif
62+
// Don't raise Z if the machine isn't homed
63+
if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;
6664

6765
#if ENABLED(MIXING_EXTRUDER)
6866
const int8_t target_e_stepper = get_target_e_stepper_from_command();
@@ -147,10 +145,8 @@ void GcodeSuite::M701() {
147145
void GcodeSuite::M702() {
148146
xyz_pos_t park_point = NOZZLE_PARK_POINT;
149147

150-
#if ENABLED(NO_MOTION_BEFORE_HOMING)
151-
// Don't raise Z if the machine isn't homed
152-
if (axes_should_home()) park_point.z = 0;
153-
#endif
148+
// Don't raise Z if the machine isn't homed
149+
if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;
154150

155151
#if ENABLED(MIXING_EXTRUDER)
156152
const uint8_t old_mixing_tool = mixer.get_current_vtool();

Marlin/src/lcd/HD44780/marlinui_HD44780.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -506,18 +506,12 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
506506
lcd_put_wchar('X' + uint8_t(axis));
507507
if (blink)
508508
lcd_put_u8str(value);
509-
else {
510-
if (!TEST(axis_homed, axis))
511-
while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
512-
else {
513-
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
514-
if (!TEST(axis_known_position, axis))
515-
lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
516-
else
517-
#endif
518-
lcd_put_u8str(value);
519-
}
520-
}
509+
else if (axis_should_home(axis))
510+
while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
511+
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
512+
lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
513+
else
514+
lcd_put_u8str(value);
521515
}
522516

523517
FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char prefix, const bool blink) {

Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,12 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
422422
lcd.write('X' + uint8_t(axis));
423423
if (blink)
424424
lcd.print(value);
425-
else {
426-
if (!TEST(axis_homed, axis))
427-
while (const char c = *value++) lcd.write(c <= '.' ? c : '?');
428-
else {
429-
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
430-
if (!TEST(axis_known_position, axis))
431-
lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
432-
else
433-
#endif
434-
lcd_put_u8str(value);
435-
}
436-
}
425+
else if (axis_should_home(axis))
426+
while (const char c = *value++) lcd.write(c <= '.' ? c : '?');
427+
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
428+
lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
429+
else
430+
lcd_put_u8str(value);
437431
}
438432

439433
FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *prefix, const bool blink) {

Marlin/src/lcd/dogm/status_screen_DOGM.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -384,18 +384,12 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
384384

385385
if (blink)
386386
lcd_put_u8str(value);
387-
else {
388-
if (!TEST(axis_homed, axis))
389-
while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
390-
else {
391-
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
392-
if (!TEST(axis_known_position, axis))
393-
lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
394-
else
395-
#endif
396-
lcd_put_u8str(value);
397-
}
398-
}
387+
else if (axis_should_home(axis))
388+
while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
389+
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
390+
lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
391+
else
392+
lcd_put_u8str(value);
399393
}
400394

401395
/**

Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,13 @@ void ST7920_Lite_Status_Screen::draw_status_message() {
659659
#endif
660660
}
661661

662-
void ST7920_Lite_Status_Screen::draw_position(const xyze_pos_t &pos, const bool position_known) {
662+
void ST7920_Lite_Status_Screen::draw_position(const xyze_pos_t &pos, const bool position_trusted) {
663663
char str[7];
664664
set_ddram_address(DDRAM_LINE_4);
665665
begin_data();
666666

667667
// If position is unknown, flash the labels.
668-
const unsigned char alt_label = position_known ? 0 : (ui.get_blink() ? ' ' : 0);
668+
const unsigned char alt_label = position_trusted ? 0 : (ui.get_blink() ? ' ' : 0);
669669

670670
if (TERN1(LCD_SHOW_E_TOTAL, !printingIsActive())) {
671671
write_byte(alt_label ? alt_label : 'X');
@@ -831,9 +831,8 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
831831
}
832832
}
833833

834-
if (countdown == 0 && (forceUpdate || position_changed()
835-
|| TERN(DISABLE_REDUCED_ACCURACY_WARNING, 0, blink_changed())
836-
)) draw_position(current_position, TERN(DISABLE_REDUCED_ACCURACY_WARNING, 1, all_axes_known()));
834+
if (countdown == 0 && (forceUpdate || position_changed() || TERN(DISABLE_REDUCED_ACCURACY_WARNING, 0, blink_changed())))
835+
draw_position(current_position, TERN(DISABLE_REDUCED_ACCURACY_WARNING, 1, all_axes_trusted()));
837836
#endif
838837
}
839838

@@ -855,7 +854,7 @@ void ST7920_Lite_Status_Screen::update_progress(const bool forceUpdate) {
855854

856855
UNUSED(forceUpdate);
857856

858-
#endif // LCD_SET_PROGRESS_MANUALLY || SDSUPPORT
857+
#endif
859858
}
860859

861860
void ST7920_Lite_Status_Screen::update(const bool forceUpdate) {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,7 @@ void HMI_Move_Z() {
12811281
last_zoffset = dwin_zoffset;
12821282
dwin_zoffset = HMI_ValueStruct.offset_value / 100.0f;
12831283
#if EITHER(BABYSTEP_ZPROBE_OFFSET, JUST_BABYSTEP)
1284-
if ( (ENABLED(BABYSTEP_WITHOUT_HOMING) || all_axes_known()) && (ENABLED(BABYSTEP_ALWAYS_AVAILABLE) || printer_busy()) )
1285-
babystep.add_mm(Z_AXIS, dwin_zoffset - last_zoffset);
1284+
if (BABYSTEP_ALLOWED()) babystep.add_mm(Z_AXIS, dwin_zoffset - last_zoffset);
12861285
#endif
12871286
DWIN_Draw_Signed_Float(font8x16, Select_Color, 2, 2, 202, MBASE(zoff_line), HMI_ValueStruct.offset_value);
12881287
DWIN_UpdateLCD();

Marlin/src/lcd/extui/ui_api.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ namespace ExtUI {
356356
bool canMove(const axis_t axis) {
357357
switch (axis) {
358358
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
359-
case X: return TEST(axis_homed, X_AXIS);
360-
case Y: return TEST(axis_homed, Y_AXIS);
361-
case Z: return TEST(axis_homed, Z_AXIS);
359+
case X: return axis_should_home(X_AXIS);
360+
case Y: return axis_should_home(Y_AXIS);
361+
case Z: return axis_should_home(Z_AXIS);
362362
#else
363363
case X: case Y: case Z: return true;
364364
#endif
@@ -889,9 +889,9 @@ namespace ExtUI {
889889

890890
bool commandsInQueue() { return (planner.movesplanned() || queue.has_commands_queued()); }
891891

892-
bool isAxisPositionKnown(const axis_t axis) { return TEST(axis_known_position, axis); }
893-
bool isAxisPositionKnown(const extruder_t) { return TEST(axis_known_position, E_AXIS); }
894-
bool isPositionKnown() { return all_axes_known(); }
892+
bool isAxisPositionKnown(const axis_t axis) { return axis_is_trusted((AxisEnum)axis); }
893+
bool isAxisPositionKnown(const extruder_t) { return axis_is_trusted(E_AXIS); }
894+
bool isPositionKnown() { return all_axes_trusted(); }
895895
bool isMachineHomed() { return all_axes_homed(); }
896896

897897
PGM_P getFirmwareName_str() {

Marlin/src/lcd/menu/menu.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
188188
doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
189189
}
190190
else if (screen == status_screen && currentScreen == menu_main && PENDING(millis(), doubleclick_expire_ms)) {
191-
if ( (ENABLED(BABYSTEP_WITHOUT_HOMING) || all_axes_known())
192-
&& (ENABLED(BABYSTEP_ALWAYS_AVAILABLE) || printer_busy()) )
191+
if (BABYSTEP_ALLOWED())
193192
screen = TERN(BABYSTEP_ZPROBE_OFFSET, lcd_babystep_zoffset, lcd_babystep_z);
194193
else {
195194
#if ENABLED(MOVE_Z_WHEN_IDLE)

Marlin/src/lcd/menu/menu_bed_corners.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static inline void _lcd_level_bed_corners_homing() {
230230

231231
void _lcd_level_bed_corners() {
232232
ui.defer_status_screen();
233-
if (!all_axes_known()) {
233+
if (!all_axes_trusted()) {
234234
set_all_unhomed();
235235
queue.inject_P(G28_STR);
236236
}

Marlin/src/lcd/menu/menu_bed_leveling.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
* Save Settings (Req: EEPROM_SETTINGS)
238238
*/
239239
void menu_bed_leveling() {
240-
const bool is_homed = all_axes_known(),
240+
const bool is_homed = all_axes_trusted(),
241241
is_valid = leveling_is_valid();
242242

243243
START_MENU();

Marlin/src/lcd/menu/menu_configuration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void menu_advanced_settings();
164164
void menu_tool_offsets() {
165165

166166
auto _recalc_offsets = []{
167-
if (active_extruder && all_axes_known()) { // For the 2nd extruder re-home so the next tool-change gets the new offsets.
167+
if (active_extruder && all_axes_trusted()) { // For the 2nd extruder re-home so the next tool-change gets the new offsets.
168168
queue.inject_P(G28_STR); // In future, we can babystep the 2nd extruder (if active), making homing unnecessary.
169169
active_extruder = 0;
170170
}

Marlin/src/lcd/menu/menu_ubl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ void _ubl_map_screen_homing() {
524524
*/
525525
void _ubl_goto_map_screen() {
526526
if (planner.movesplanned()) return; // The ACTION_ITEM will do nothing
527-
if (!all_axes_known()) {
527+
if (!all_axes_trusted()) {
528528
set_all_unhomed();
529529
queue.inject_P(G28_STR);
530530
}

Marlin/src/lcd/tft/ui_320x240.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -257,42 +257,37 @@ void MarlinUI::draw_status_screen() {
257257
tft.set_background(COLOR_BACKGROUND);
258258
tft.add_rectangle(0, 0, 312, 24, COLOR_AXIS_HOMED);
259259

260-
uint16_t color;
261-
uint16_t offset;
262-
bool is_homed;
263-
264260
tft.add_text( 10, 3, COLOR_AXIS_HOMED , "X");
265261
tft.add_text(127, 3, COLOR_AXIS_HOMED , "Y");
266262
tft.add_text(219, 3, COLOR_AXIS_HOMED , "Z");
267263

268-
is_homed = TEST(axis_homed, X_AXIS);
269-
tft_string.set(blink & !is_homed ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
270-
tft.add_text( 68 - tft_string.width(), 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
264+
bool not_homed = axis_should_home(X_AXIS);
265+
tft_string.set(blink && not_homed ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
266+
tft.add_text( 68 - tft_string.width(), 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
271267

272-
is_homed = TEST(axis_homed, Y_AXIS);
273-
tft_string.set(blink & !is_homed ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
274-
tft.add_text(185 - tft_string.width(), 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
268+
not_homed = axis_should_home(Y_AXIS);
269+
tft_string.set(blink && not_homed ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
270+
tft.add_text(185 - tft_string.width(), 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
275271

276-
is_homed = TEST(axis_homed, Z_AXIS);
277-
if (blink & !is_homed) {
272+
not_homed = axis_should_home(Z_AXIS);
273+
uint16_t offset = 25;
274+
if (blink && not_homed)
278275
tft_string.set("?");
279-
offset = 25; // ".00"
280-
}
281276
else {
282277
const float z = LOGICAL_Z_POSITION(current_position.z);
283278
tft_string.set(ftostr52sp((int16_t)z));
284279
tft_string.rtrim();
285-
offset = tft_string.width();
280+
offset += tft_string.width();
286281

287282
tft_string.set(ftostr52sp(z));
288-
offset += 25 - tft_string.width();
283+
offset -= tft_string.width();
289284
}
290-
tft.add_text(301 - tft_string.width() - offset, 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
285+
tft.add_text(301 - tft_string.width() - offset, 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
291286

292287
// feed rate
293288
tft.canvas(70, 136, 80, 32);
294289
tft.set_background(COLOR_BACKGROUND);
295-
color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
290+
uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
296291
tft.add_image(0, 0, imgFeedRate, color);
297292
tft_string.set(i16tostr3rj(feedrate_percentage));
298293
tft_string.add('%');

Marlin/src/lcd/tft/ui_480x320.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -262,43 +262,38 @@ void MarlinUI::draw_status_screen() {
262262
tft.set_background(COLOR_BACKGROUND);
263263
tft.add_rectangle(0, 0, TFT_WIDTH - 8, 34, COLOR_AXIS_HOMED);
264264

265-
uint16_t color;
266-
uint16_t offset;
267-
bool is_homed;
268-
269265
tft.add_text( 16, 3, COLOR_AXIS_HOMED , "X");
270266
tft.add_text(192, 3, COLOR_AXIS_HOMED , "Y");
271267
tft.add_text(330, 3, COLOR_AXIS_HOMED , "Z");
272268

273-
is_homed = TEST(axis_homed, X_AXIS);
274-
tft_string.set(blink & !is_homed ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
275-
tft.add_text(102 - tft_string.width(), 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
269+
bool not_homed = axis_should_home(X_AXIS);
270+
tft_string.set(blink && not_homed ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
271+
tft.add_text(102 - tft_string.width(), 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
276272

277-
is_homed = TEST(axis_homed, Y_AXIS);
278-
tft_string.set(blink & !is_homed ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
279-
tft.add_text(280 - tft_string.width(), 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
273+
not_homed = axis_should_home(Y_AXIS);
274+
tft_string.set(blink && not_homed ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
275+
tft.add_text(280 - tft_string.width(), 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
280276

281-
is_homed = TEST(axis_homed, Z_AXIS);
282-
if (blink & !is_homed) {
277+
uint16_t offset = 32;
278+
not_homed = axis_should_home(Z_AXIS);
279+
if (blink && not_homed)
283280
tft_string.set("?");
284-
offset = 32; // ".00"
285-
}
286281
else {
287282
const float z = LOGICAL_Z_POSITION(current_position.z);
288283
tft_string.set(ftostr52sp((int16_t)z));
289284
tft_string.rtrim();
290-
offset = tft_string.width();
285+
offset += tft_string.width();
291286

292287
tft_string.set(ftostr52sp(z));
293-
offset += 32 - tft_string.width();
288+
offset -= tft_string.width();
294289
}
295-
tft.add_text(455 - tft_string.width() - offset, 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
290+
tft.add_text(455 - tft_string.width() - offset, 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
296291
TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 4, 132, TFT_WIDTH - 8, 34));
297292

298293
// feed rate
299294
tft.canvas(96, 180, 100, 32);
300295
tft.set_background(COLOR_BACKGROUND);
301-
color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
296+
uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
302297
tft.add_image(0, 0, imgFeedRate, color);
303298
tft_string.set(i16tostr3rj(feedrate_percentage));
304299
tft_string.add('%');

0 commit comments

Comments
 (0)