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

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2024 Mark Thompson
*
* This file is part of PortaPack.
*
@@ -70,10 +71,15 @@ class EncoderDebounce {
uint8_t state(); // returns debounced phase bits from encoder
uint8_t rotation_rate(); // returns last rotation rate
private:
uint8_t history_{0}; // shift register of previous reads from encoder
uint8_t state_{0}; // actual encoder output state (after debounce logic)
uint8_t last_rotation_rate_{1};
uint8_t rotation_rate_downcounter_{1}; // down-counter to estimate rotation speed
};
#endif /*__DEBOUNCE_H__*/

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2024 Mark Thompson
*
* This file is part of PortaPack.
*
@@ -63,7 +64,7 @@ int_fast8_t Encoder::update(const uint_fast8_t phase_bits) {
// Require 2 state changes in same direction to register movement -- for additional level of contact switch debouncing
if (direction == prev_direction) {
if ((sensitivity_map[portapack::persistent_memory::config_encoder_dial_sensitivity()] & (1 << state)) == 0)
if ((sensitivity_map[portapack::persistent_memory::encoder_dial_sensitivity()] & (1 << state)) == 0)
return 0;
return direction;
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2024 Mark Thompson
*
* This file is part of PortaPack.
*