From 24e956d16839d7b7515d1139cb2a432b1e82aaf8 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 7 May 2019 20:58:10 +0200 Subject: [PATCH] Avoid int8_t underflow on filament runout (#13895) --- Marlin/src/feature/runout.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h index eccc7ab93..7e39f90c9 100644 --- a/Marlin/src/feature/runout.h +++ b/Marlin/src/feature/runout.h @@ -41,6 +41,9 @@ #endif //#define FILAMENT_RUNOUT_SENSOR_DEBUG +#ifndef FILAMENT_RUNOUT_THRESHOLD + #define FILAMENT_RUNOUT_THRESHOLD 5 +#endif class FilamentMonitorBase { public: @@ -337,11 +340,11 @@ class FilamentSensorBase { class RunoutResponseDebounced { private: - static constexpr int8_t runout_threshold = 5; + static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD; static int8_t runout_count; public: static inline void reset() { runout_count = runout_threshold; } - static inline void run() { runout_count--; } + static inline void run() { if (runout_count >= 0) runout_count--; } static inline bool has_run_out() { return runout_count < 0; } static inline void block_completed(const block_t* const b) { UNUSED(b); } static inline void filament_present(const uint8_t extruder) { runout_count = runout_threshold; UNUSED(extruder); }