Encoder rotation rate multiplier support (#1876)

This commit is contained in:
Mark Thompson 2024-02-10 02:32:03 -06:00 committed by GitHub
parent 367479d163
commit 46d9e02684
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 73 additions and 18 deletions

View file

@ -24,6 +24,9 @@
#include "utility.hpp"
#include "portapack.hpp"
#include "portapack_persistent_memory.hpp"
uint8_t Debounce::state() {
uint8_t v = state_to_report_;
simulated_pulse_ = false;
@ -154,6 +157,10 @@ uint8_t EncoderDebounce::state() {
return state_;
}
uint8_t EncoderDebounce::rotation_rate() {
return last_rotation_rate_;
}
// Returns TRUE if encoder position phase bits changed (after debouncing)
bool EncoderDebounce::feed(const uint8_t phase_bits) {
history_ = (history_ << 2) | phase_bits;
@ -164,14 +171,21 @@ bool EncoderDebounce::feed(const uint8_t phase_bits) {
// But, checking for equal seems to cause issues with at least 1 user's encoder, so we're treating the input
// as "stable" if at least ONE input bit is consistent for 4 ticks...
uint8_t diff = (history_ ^ expected_stable_history);
if ((diff == 0) || ((diff & 0b01010101) == 0) || ((diff & 0b10101010) == 0)) {
if (((diff & 0b01010101) == 0) || ((diff & 0b10101010) == 0)) {
// Has the debounced input value changed?
if (state_ != phase_bits) {
state_ = phase_bits;
// Rate multiplier is for larger delta increments when dial is rotated rapidly.
last_rotation_rate_ = rotation_rate_downcounter_;
rotation_rate_downcounter_ = portapack::persistent_memory::encoder_rate_multiplier();
return true;
}
}
// Unstable input, or no change
// Unstable input, or no change.
// Decrement rotation rate detector once per timer tick.
if (rotation_rate_downcounter_ > 1)
rotation_rate_downcounter_--;
return false;
}