Avoid int8_t underflow on filament runout (#13895)
This commit is contained in:
		
				
					committed by
					
						
						Scott Lahteine
					
				
			
			
				
	
			
			
			
						parent
						
							483822f3aa
						
					
				
				
					commit
					24e956d168
				
			@@ -41,6 +41,9 @@
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define FILAMENT_RUNOUT_SENSOR_DEBUG
 | 
					//#define FILAMENT_RUNOUT_SENSOR_DEBUG
 | 
				
			||||||
 | 
					#ifndef FILAMENT_RUNOUT_THRESHOLD
 | 
				
			||||||
 | 
					  #define FILAMENT_RUNOUT_THRESHOLD 5
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FilamentMonitorBase {
 | 
					class FilamentMonitorBase {
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
@@ -337,11 +340,11 @@ class FilamentSensorBase {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  class RunoutResponseDebounced {
 | 
					  class RunoutResponseDebounced {
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
      static constexpr int8_t runout_threshold = 5;
 | 
					      static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD;
 | 
				
			||||||
      static int8_t runout_count;
 | 
					      static int8_t runout_count;
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
      static inline void reset()                                  { runout_count = runout_threshold; }
 | 
					      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 bool has_run_out()                            { return runout_count < 0; }
 | 
				
			||||||
      static inline void block_completed(const block_t* const b)  { UNUSED(b); }
 | 
					      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); }
 | 
					      static inline void filament_present(const uint8_t extruder) { runout_count = runout_threshold; UNUSED(extruder); }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user