From 951b65c2de4263a85fbcc8af14704be53a8c310a Mon Sep 17 00:00:00 2001 From: Sebastianv650 Date: Thu, 1 Mar 2018 09:10:39 +0100 Subject: [PATCH] Add sanity checks to Linear Advance 1.5 (#9859) --- Marlin/Marlin_main.cpp | 21 +++++++++++++-------- Marlin/SanityCheck.h | 10 ++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 0df7b68af..ae9d86b2a 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -10469,14 +10469,19 @@ inline void gcode_M502() { * K Set advance K factor */ inline void gcode_M900() { - stepper.synchronize(); - - const float newK = parser.floatval('K', -1); - if (newK >= 0) planner.extruder_advance_K = newK; - - SERIAL_ECHO_START(); - SERIAL_ECHOPAIR("Advance K=", planner.extruder_advance_K); - SERIAL_EOL(); + 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_ECHOLNPAIR("Advance K=", planner.extruder_advance_K); + } } #endif // LIN_ADVANCE diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h index 38cfaaa82..4c4ae2447 100644 --- a/Marlin/SanityCheck.h +++ b/Marlin/SanityCheck.h @@ -527,6 +527,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 */