Browse Source

Avoid int8_t underflow on filament runout (#13895)

Tanguy Pruvot 6 years ago
parent
commit
24e956d168
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      Marlin/src/feature/runout.h

+ 5
- 2
Marlin/src/feature/runout.h View File

@@ -41,6 +41,9 @@
41 41
 #endif
42 42
 
43 43
 //#define FILAMENT_RUNOUT_SENSOR_DEBUG
44
+#ifndef FILAMENT_RUNOUT_THRESHOLD
45
+  #define FILAMENT_RUNOUT_THRESHOLD 5
46
+#endif
44 47
 
45 48
 class FilamentMonitorBase {
46 49
   public:
@@ -337,11 +340,11 @@ class FilamentSensorBase {
337 340
 
338 341
   class RunoutResponseDebounced {
339 342
     private:
340
-      static constexpr int8_t runout_threshold = 5;
343
+      static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD;
341 344
       static int8_t runout_count;
342 345
     public:
343 346
       static inline void reset()                                  { runout_count = runout_threshold; }
344
-      static inline void run()                                    { runout_count--; }
347
+      static inline void run()                                    { if (runout_count >= 0) runout_count--; }
345 348
       static inline bool has_run_out()                            { return runout_count < 0; }
346 349
       static inline void block_completed(const block_t* const b)  { UNUSED(b); }
347 350
       static inline void filament_present(const uint8_t extruder) { runout_count = runout_threshold; UNUSED(extruder); }

Loading…
Cancel
Save