mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Suppress first rotary encoder event (#3532)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
This commit is contained in:
		| @@ -103,7 +103,7 @@ void IRAM_ATTR HOT RotaryEncoderSensorStore::gpio_intr(RotaryEncoderSensorStore | ||||
|     rotation_dir = -1; | ||||
|   } | ||||
|  | ||||
|   if (rotation_dir != 0) { | ||||
|   if (rotation_dir != 0 && !arg->first_read) { | ||||
|     auto *first_zero = std::find(arg->rotation_events.begin(), arg->rotation_events.end(), 0);  // find first zero | ||||
|     if (first_zero == arg->rotation_events.begin()  // are we at the start (first event this loop iteration) | ||||
|         || std::signbit(*std::prev(first_zero)) != | ||||
| @@ -119,6 +119,7 @@ void IRAM_ATTR HOT RotaryEncoderSensorStore::gpio_intr(RotaryEncoderSensorStore | ||||
|       *std::prev(first_zero) += rotation_dir;  // store the rotation into the previous slot | ||||
|     } | ||||
|   } | ||||
|   arg->first_read = false; | ||||
|  | ||||
|   arg->state = new_state; | ||||
| } | ||||
|   | ||||
| @@ -34,6 +34,7 @@ struct RotaryEncoderSensorStore { | ||||
|   int32_t max_value{INT32_MAX}; | ||||
|   int32_t last_read{0}; | ||||
|   uint8_t state{0}; | ||||
|   bool first_read{true}; | ||||
|  | ||||
|   std::array<int8_t, 8> rotation_events{}; | ||||
|   bool rotation_events_overflow{false}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user