New slider signals

This commit is contained in:
Brian Hrebec 2024-04-01 16:39:27 -05:00
parent 4211a85562
commit 9f4634735b
6 changed files with 104 additions and 53 deletions

View file

@ -11,8 +11,12 @@ FilterOnePole breathAltFilter;
FilterOnePole spikeFilter;
FilterOnePole tiltFilter;
FilterOnePole rollFilter;
FilterOnePole sliderFilterExtra;
FilterOnePole sliderFilterPB;
FilterOnePole sliderFilterLever;
Adafruit_MPR121 touchSensorKeys = Adafruit_MPR121();
Adafruit_MPR121 touchSensorRoller = Adafruit_MPR121();
Adafruit_MPR121 touchSensorUtil = Adafruit_MPR121();
Adafruit_MPRLS pressureSensorMain = Adafruit_MPRLS();
Adafruit_MPRLS pressureSensorAlt = Adafruit_MPRLS();
@ -49,6 +53,9 @@ void initHardware() {
tiltFilter.setFilter(LOWPASS, 2, 0.0); // create a one pole (RC) lowpass filter
rollFilter.setFilter(LOWPASS, 2, 0.0); // create a one pole (RC) lowpass filter
icmSensor.begin_I2C(ICM20948_I2CADDR_DEFAULT, &MainI2CBus);
sliderFilterExtra.setFilter(LOWPASS, 1.0, 0.0);
sliderFilterLever.setFilter(LOWPASS, 1.0, 0.0);
sliderFilterPB.setFilter(LOWPASS, 1.0, 0.0);
ledStrip.begin();
@ -57,11 +64,18 @@ void initHardware() {
errorWait();
}
if (!touchSensorUtil.begin(UtilI2CAddr, &MainI2CBus)) {
displayError("Roller/Util touch error");
if (!touchSensorRoller.begin(RollerI2CAddr, &MainI2CBus)) {
displayError("Roller touch error");
errorWait();
}
if (!touchSensorUtil.begin(UtilI2CAddr, &MainI2CBus)) {
displayError("Util touch error");
errorWait();
}
//touchSensorUtil.writeRegister(MPR121_CONFIG1, 0x3f); // default, 16uA charge current
//touchSensorUtil.writeRegister(MPR121_CONFIG2, 0xE0); // 0.5uS encoding, 1ms period
if (!pressureSensorMain.begin(MPRLS_DEFAULT_ADDR, &MainI2CBus)) {
displayError("Main pressure sensor error");
errorWait();
@ -148,6 +162,11 @@ int readKnob(uint8_t n) {
int readTouchKey(uint8_t n) {
return CAP_SENS_ABSOLUTE_MAX - touchSensorKeys.filteredData(n);
}
int readTouchRoller(uint8_t n) {
return CAP_SENS_ABSOLUTE_MAX - touchSensorRoller.filteredData(n);
}
int readTouchUtil(uint8_t n) {
return CAP_SENS_ABSOLUTE_MAX - touchSensorUtil.filteredData(n);
}
@ -157,7 +176,7 @@ uint16_t keysTouched() {
}
uint16_t utilTouched() {
return touchSensorKeys.touched();
return touchSensorUtil.touched();
}
int readSpikePressure() {
@ -173,6 +192,27 @@ int readAltPressure() {
return breathAltFilter.input(pressureSensorAlt.readPressure()) * PRESSURE_SENS_MULTIPLIER;
}
float readSlider(Slider id) {
float diff = 0.0;
float filtered = 0.0;
switch (id) {
case SLIDER_PITCH_BEND:
diff = touchSensorUtil.filteredData(pbSliderPin1) - touchSensorUtil.filteredData(pbSliderPin2);
filtered = sliderFilterPB.input(diff);
break;
case SLIDER_EXTRA:
diff = touchSensorRoller.filteredData(extraSliderPin1) - touchSensorRoller.filteredData(extraSliderPin2);
filtered = sliderFilterExtra.input(diff);
break;
case SLIDER_LEVER:
diff = touchSensorUtil.filteredData(leverSliderPin1) - touchSensorUtil.filteredData(leverSliderPin2);
filtered = sliderFilterLever.input(diff);
break;
}
return filtered;
}
icm_result_t readICM() {
sensors_event_t accel;
sensors_event_t gyro;