From 118899357d995c58de2089abb5f5da2d186aebe9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 1 Mar 2018 02:10:43 -0600 Subject: [PATCH] Add sanity checks to Linear Advance 1.5 (#9873) --- Marlin/src/gcode/feature/advance/M900.cpp | 19 ++++++++++++------- Marlin/src/inc/SanityCheck.h | 10 ++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Marlin/src/gcode/feature/advance/M900.cpp b/Marlin/src/gcode/feature/advance/M900.cpp index 4f95ee8859..e9d5360a97 100644 --- a/Marlin/src/gcode/feature/advance/M900.cpp +++ b/Marlin/src/gcode/feature/advance/M900.cpp @@ -34,14 +34,19 @@ * K Set advance K factor */ void GcodeSuite::M900() { - stepper.synchronize(); - - const float newK = parser.floatval('K', -1); - if (newK >= 0) planner.extruder_advance_K = newK; - + if (parser.seenval('K')) { + const float newK = parser.floatval('K'); + if (WITHIN(newK, 0, 10)) { + stepper.synchronize(); + planner.extruder_advance_K = newK; + } + else + SERIAL_PROTOCOLLNPGM("?K value out of range (0-10)."); + } + else { SERIAL_ECHO_START(); - SERIAL_ECHOPAIR("Advance K=", planner.extruder_advance_K); - SERIAL_EOL(); + SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K); + } } #endif // LIN_ADVANCE diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index af79dad8d3..ea56c3227c 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -554,6 +554,16 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE, #endif #endif +/** + * Linear Advance 1.5 - Check K value range + */ +#if ENABLED(LIN_ADVANCE) + static_assert( + WITHIN(LIN_ADVANCE_K, 0, 10), + "LIN_ADVANCE_K must be a value from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9)." + ); +#endif + /** * Parking Extruder requirements */