Suppress first rotary encoder event (#3532)

Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
This commit is contained in:
Maurice Makaay 2022-06-07 01:36:54 +02:00 committed by GitHub
parent dd24ffa24e
commit f8969605e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -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;
}

View File

@ -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};