From 68f6f149d02025414c24858b84d7c5b8b90449a4 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 24 May 2015 20:18:02 -0700 Subject: [PATCH] Reduce code size with out_of_range_error function - Affects code size when automatic bed leveling is enabled --- Marlin/Marlin_main.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e164618fe..2a8d954bc 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2444,6 +2444,12 @@ inline void gcode_G28() { #elif defined(ENABLE_AUTO_BED_LEVELING) + void out_of_range_error(const char *edge) { + char msg[40]; + sprintf_P(msg, PSTR("?Probe %s position out of range.\n"), edge); + SERIAL_PROTOCOL(msg); + } + /** * G29: Detailed Z-Probe, probes the bed at 3 or more points. * Will fail if the printer has not been homed with G28. @@ -2539,19 +2545,19 @@ inline void gcode_G28() { if (left_out || right_out || front_out || back_out) { if (left_out) { - SERIAL_PROTOCOLPGM("?Probe (L)eft position out of range.\n"); + out_of_range_error(PSTR("(L)eft")); left_probe_bed_position = left_out_l ? MIN_PROBE_X : right_probe_bed_position - MIN_PROBE_EDGE; } if (right_out) { - SERIAL_PROTOCOLPGM("?Probe (R)ight position out of range.\n"); + out_of_range_error(PSTR("(R)ight")); right_probe_bed_position = right_out_r ? MAX_PROBE_X : left_probe_bed_position + MIN_PROBE_EDGE; } if (front_out) { - SERIAL_PROTOCOLPGM("?Probe (F)ront position out of range.\n"); + out_of_range_error(PSTR("(F)ront")); front_probe_bed_position = front_out_f ? MIN_PROBE_Y : back_probe_bed_position - MIN_PROBE_EDGE; } if (back_out) { - SERIAL_PROTOCOLPGM("?Probe (B)ack position out of range.\n"); + out_of_range_error(PSTR("(B)ack")); back_probe_bed_position = back_out_b ? MAX_PROBE_Y : front_probe_bed_position + MIN_PROBE_EDGE; } return; @@ -3170,7 +3176,7 @@ inline void gcode_M42() { if (code_seen('X') || code_seen('x')) { X_probe_location = code_value() - X_PROBE_OFFSET_FROM_EXTRUDER; if (X_probe_location < X_MIN_POS || X_probe_location > X_MAX_POS) { - SERIAL_PROTOCOLPGM("?X position out of range.\n"); + out_of_range_error(PSTR("X")); return; } } @@ -3178,7 +3184,7 @@ inline void gcode_M42() { if (code_seen('Y') || code_seen('y')) { Y_probe_location = code_value() - Y_PROBE_OFFSET_FROM_EXTRUDER; if (Y_probe_location < Y_MIN_POS || Y_probe_location > Y_MAX_POS) { - SERIAL_PROTOCOLPGM("?Y position out of range.\n"); + out_of_range_error(PSTR("Y")); return; } }