From f9e6f9d47abafa62f0dbbfa6c6ec800251ff2f22 Mon Sep 17 00:00:00 2001 From: skogaby Date: Mon, 19 Oct 2020 20:05:18 -0500 Subject: [PATCH] Improving auto calibration for the slider (only tested 32k): --- Firmware/OpeNITHM/AutoTouchboard.cpp | 12 ++---------- Firmware/OpeNITHM/AutoTouchboard.h | 6 ++---- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Firmware/OpeNITHM/AutoTouchboard.cpp b/Firmware/OpeNITHM/AutoTouchboard.cpp index e577b9b..78c2c7f 100644 --- a/Firmware/OpeNITHM/AutoTouchboard.cpp +++ b/Firmware/OpeNITHM/AutoTouchboard.cpp @@ -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() diff --git a/Firmware/OpeNITHM/AutoTouchboard.h b/Firmware/OpeNITHM/AutoTouchboard.h index 5cb0eaa..7bc306d 100644 --- a/Firmware/OpeNITHM/AutoTouchboard.h +++ b/Firmware/OpeNITHM/AutoTouchboard.h @@ -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: