mirror of
https://github.com/skogaby/OpeNITHM.git
synced 2026-09-22 22:58:16 +03:00
Improving auto calibration for the slider (only tested 32k):
This commit is contained in:
@@ -99,16 +99,9 @@ KeyState AutoTouchboard::update(int key)
|
||||
if (states[key] == UNPRESSED) {
|
||||
// new press detected
|
||||
if (pressure > triggerThresholdsDouble[key]) {
|
||||
lastTriggerTimes[key] = currMillis;
|
||||
states[key] = DOUBLE_PRESS;
|
||||
} else if (pressure > triggerThresholdsSingle[key]) {
|
||||
lastTriggerTimes[key] = currMillis;
|
||||
states[key] = SINGLE_PRESS;
|
||||
// the key hasn't been triggered, so we'll check how long it's been since
|
||||
// the last trigger. if it's been more than the configured period, re-establish
|
||||
// baselines for thresholds
|
||||
} else if (currMillis - lastTriggerTimes[key] > CALIBRATION_PERIOD) {
|
||||
calcThresholds(key, pressure);
|
||||
}
|
||||
// new release detected
|
||||
} else if (states[key] != UNPRESSED) {
|
||||
@@ -137,9 +130,8 @@ void AutoTouchboard::calcThresholds(int key, int pressure)
|
||||
{
|
||||
triggerThresholdsSingle[key] = pressure + deltaThreshold;
|
||||
releaseThresholdsSingle[key] = pressure + (deltaThreshold * releaseThreshold);
|
||||
triggerThresholdsDouble[key] = triggerThresholdsSingle[key] + (0.8 * deltaThreshold);
|
||||
releaseThresholdsDouble[key] = triggerThresholdsSingle[key] + (0.8 * deltaThreshold * releaseThreshold);
|
||||
lastTriggerTimes[key] = millis();
|
||||
triggerThresholdsDouble[key] = triggerThresholdsSingle[key] + (deltaThreshold);
|
||||
releaseThresholdsDouble[key] = triggerThresholdsSingle[key] + (deltaThreshold * releaseThreshold);
|
||||
}
|
||||
|
||||
AutoTouchboard::AutoTouchboard()
|
||||
|
||||
@@ -25,14 +25,12 @@ extern CRGB leds[16];
|
||||
extern CRGB leds[31];
|
||||
#endif
|
||||
|
||||
#define CALIBRATION_PERIOD 15000
|
||||
|
||||
class AutoTouchboard
|
||||
{
|
||||
private:
|
||||
// these will be tunable / need to be experimented with
|
||||
#if NUM_SENSORS == 32
|
||||
int deltaThreshold = 4;
|
||||
int deltaThreshold = 5;
|
||||
double releaseThreshold = 0.8;
|
||||
#else
|
||||
int deltaThreshold = 6;
|
||||
@@ -45,7 +43,7 @@ class AutoTouchboard
|
||||
int releaseThresholdsSingle[NUM_SENSORS];
|
||||
int triggerThresholdsDouble[NUM_SENSORS];
|
||||
int releaseThresholdsDouble[NUM_SENSORS];
|
||||
unsigned long lastTriggerTimes[NUM_SENSORS];
|
||||
|
||||
void calcThresholds(int key, int pressure);
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user