Fixes; additional input filtering
This commit is contained in:
parent
209959e2de
commit
7740c09375
11 changed files with 802 additions and 513 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include "FilterOnePole.h" // for the breath signal low-pass filtering, from https://github.com/JonHub/Filters
|
||||
FilterOnePole breathFilter;
|
||||
FilterOnePole breathAltFilter;
|
||||
FilterOnePole spikeFilter;
|
||||
|
||||
Adafruit_MPR121 touchSensorKeys = Adafruit_MPR121();
|
||||
Adafruit_MPR121 touchSensorUtil = Adafruit_MPR121();
|
||||
|
|
@ -42,6 +43,7 @@ void initHardware() {
|
|||
|
||||
breathFilter.setFilter(LOWPASS, FILTER_FREQ, 0.0); // create a one pole (RC) lowpass filter
|
||||
breathAltFilter.setFilter(LOWPASS, FILTER_FREQ, 0.0); // create a one pole (RC) lowpass filter
|
||||
spikeFilter.setFilter(HIGHPASS, 200, 0.0); // create a one pole (RC) lowpass filter
|
||||
|
||||
ledStrip.begin();
|
||||
|
||||
|
|
@ -71,6 +73,12 @@ void initHardware() {
|
|||
}
|
||||
}
|
||||
|
||||
void updateFilters(preset_t &preset) {
|
||||
breathFilter.setFrequency(preset.breathFilterFreq);
|
||||
breathAltFilter.setFrequency(preset.breathFilterFreq);
|
||||
spikeFilter.setFrequency(preset.spikeFilterFreq);
|
||||
}
|
||||
|
||||
/*
|
||||
Return true if the given button bitmask is pressed
|
||||
*/
|
||||
|
|
@ -107,16 +115,27 @@ void errorWait() {
|
|||
* Read the knob value accounting for 4x precision - NB this might not work on other kinds of encoder
|
||||
*/
|
||||
int readKnob(uint8_t n) {
|
||||
// Make it temporarily more sensitive when switching directions, the hardware loses a tick frequently
|
||||
static int lastOut = 0;
|
||||
static unsigned long lastOutTime = 0;
|
||||
int out = 0;
|
||||
int32_t val = knobs[n].read();
|
||||
if (val > 4) {
|
||||
if (val > (lastOut < 0) ? 3 : 4) {
|
||||
out = val / 4;
|
||||
} else if (val < -4) {
|
||||
} else if (val < (lastOut > 0) ? -3 : -4) {
|
||||
out = val / 4;
|
||||
}
|
||||
|
||||
if (out != 0) {
|
||||
knobs[n].write(0);
|
||||
unsigned long time = millis();
|
||||
|
||||
knobs[n].write(val - (out * 4));
|
||||
lastOut = out;
|
||||
|
||||
if (time - lastOutTime < KNOB_CURVE_THRESHOLD) {
|
||||
out *= KNOB_CURVE_MULTIPLIER;
|
||||
}
|
||||
lastOutTime = time;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -136,8 +155,15 @@ uint16_t utilTouched() {
|
|||
return touchSensorKeys.touched();
|
||||
}
|
||||
|
||||
int readSpikePressure() {
|
||||
return spikeFilter.input(pressureSensorMain.readPressure()) * PRESSURE_SENS_MULTIPLIER;
|
||||
}
|
||||
|
||||
int readPressure() {
|
||||
return breathFilter.input(pressureSensorMain.readPressure()) * PRESSURE_SENS_MULTIPLIER;
|
||||
float p = pressureSensorMain.readPressure();
|
||||
Serial.print(">raw:");
|
||||
Serial.println(p * PRESSURE_SENS_MULTIPLIER);
|
||||
return breathFilter.input(p) * PRESSURE_SENS_MULTIPLIER;
|
||||
}
|
||||
|
||||
int readAltPressure() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue