Improving auto calibration for the slider (only tested 32k):

This commit is contained in:
skogaby
2020-10-19 20:05:18 -05:00
parent f729a681c2
commit f9e6f9d47a
2 changed files with 4 additions and 14 deletions
+2 -10
View File
@@ -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()
+2 -4
View File
@@ -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: