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

Loading…
Cancel
Save