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

@ -98,8 +98,7 @@ struct instrument_state_t {
int16_t breathAltSignal = 0;
int16_t biteSignal = 0; // capacitance data from bite sensor, for midi cc and threshold checks
int16_t leverSignal = 0;
int16_t pbUpSignal = 0;
int16_t pbDnSignal = 0;
int16_t pbSignal = 0;
int16_t extraSignal = 0;
int16_t vibSignal = 0;
int16_t avgCTouchSignal = 0;

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;

View file

@ -27,7 +27,8 @@ bool checkButtonState(uint8_t mask); // return true if the given buttons are pre
uint8_t buttonState(); // return true if the given buttons are pressed
int readKnob(uint8_t n);
int readTouchKey(uint8_t n);
int readTouchUtil(uint8_t n);
int readTouchRoller(uint8_t n);
float readSlider(Slider id);
uint16_t keysTouched();
uint16_t utilTouched();
int readPressure();
@ -41,7 +42,8 @@ icm_result_t readICM();
#define MainI2CBus Wire1
#define AuxI2CBus Wire
#define KeysI2CAddr 0x5A
#define UtilI2CAddr 0x5B
#define RollerI2CAddr 0x5B
#define UtilI2CAddr 0x5C
// Digital pins for encoder buttons
#define b1Pin 4
@ -98,9 +100,17 @@ icm_result_t readICM();
// Additional pins
#define bitePin 0
#define extraPin 2
#define pbUpPin 4
#define pbDnPin 5
#define leverPin 3
#define barPin 7
#define pbSliderPin1 11
#define pbSliderPin2 10
#define leverSliderPin1 9
#define leverSliderPin2 8
#define extraSliderPin1 2
#define extraSliderPin2 3
enum Slider : uint8_t {
SLIDER_PITCH_BEND = 0,
SLIDER_EXTRA = 1,
SLIDER_LEVER = 2,
};
#endif

View file

@ -26,14 +26,14 @@ struct calibration_t {
int16_t breathAltMaxValOffset = 1500;
int16_t biteThrVal = 850;
int16_t biteMaxVal = 1000;
int16_t pbDnThrVal = 850;
int16_t pbDnMaxVal = 1000;
int16_t pbUpThrVal = 850;
int16_t pbUpMaxVal = 1000;
int16_t leverThrVal = 850;
int16_t leverMaxVal = 1000;
int16_t extraThrVal = 850;
int16_t extraMaxVal = 1000;
int16_t pbMinVal = -10;
int16_t pbMaxVal = 10;
int16_t pbCenterVal = 0;
int16_t pbDeadzone = 2;
int16_t leverMinVal = -10;
int16_t leverMaxVal = 10;
int16_t extraMinVal = -10;
int16_t extraMaxVal = 10;
int16_t ctouchThrVal = 900;
uint8_t _reserved[24];
};

View file

@ -57,7 +57,7 @@ void handleTestMode(state_t &state) {
Serial.print(">util");
Serial.print(i);
Serial.print(":");
Serial.println(readTouchUtil(i));
Serial.println(readTouchRoller(i));
}
}

View file

@ -336,12 +336,12 @@ void pitch_bend() {
instrument.vibThrBiteLo = instrument.vibZeroBite - state.currentPreset->vibSquelch;
// PB calculation
int pbPos = mapConstrain(instrument.pbUpSignal, calibration.pbUpThrVal, calibration.pbUpMaxVal, calculatedPBdepth, 0);
int pbNeg = mapConstrain(instrument.pbDnSignal, calibration.pbDnThrVal, calibration.pbDnMaxVal, calculatedPBdepth, 0);
int pbPos = mapConstrain(instrument.pbSignal, calibration.pbCenterVal, calibration.pbMaxVal, calculatedPBdepth, 0);
int pbNeg = mapConstrain(instrument.pbSignal, calibration.pbCenterVal, calibration.pbMinVal, calculatedPBdepth, 0);
int pbSum = 8193 + pbPos - pbNeg;
int pbDif = abs(pbPos - pbNeg);
if ((instrument.pbUpSignal > calibration.pbUpThrVal || instrument.pbDnSignal > calibration.pbDnThrVal) && state.currentPreset->PBdepth) {
if ((pbPos > calibration.pbDeadzone || pbNeg < calibration.pbDeadzone) && state.currentPreset->PBdepth) {
if (pbDif < 10) {
instrument.pitchBend = 8192;
} else {
@ -390,8 +390,9 @@ void portamento_() {
if (ExtraControl::GLIDE == state.currentPreset->leverControl) {
// Portamento is controlled with thumb lever
if (((3000 - instrument.leverSignal) >= calibration.leverThrVal)) { // if we are enabled and over the threshold, send portamento
portSumCC += mapConstrain((3000 - instrument.leverSignal), calibration.leverThrVal, calibration.leverMaxVal, 0, state.currentPreset->portamentoLimit);
// FIXME: Fix this for new lever signal
if (((3000 - instrument.leverSignal) >= calibration.leverMinVal)) { // if we are enabled and over the threshold, send portamento
portSumCC += mapConstrain((3000 - instrument.leverSignal), calibration.leverMinVal, calibration.leverMaxVal, 0, state.currentPreset->portamentoLimit);
}
}
@ -415,8 +416,9 @@ void sendCC() {
int extraVal = 0;
if (ExtraControl::CC == state.currentPreset->extraControl) {
if (instrument.extraSignal >= calibration.extraThrVal) { // we are over the threshold, calculate CC value
extraVal = mapConstrain(instrument.extraSignal, calibration.extraThrVal, calibration.extraMaxVal, 0, 127);
// FIXME: Fix this for new extra signal
if (instrument.extraSignal >= calibration.extraMinVal) { // we are over the threshold, calculate CC value
extraVal = mapConstrain(instrument.extraSignal, calibration.extraMinVal, calibration.extraMaxVal, 0, 127);
}
if (extraVal != instrument.extraVal) {
@ -472,8 +474,7 @@ void autoCal() {
for (int i = 1; i <= CALIBRATE_SAMPLE_COUNT; ++i) {
bZero += readPressure();
bAltZero += readAltPressure();
instrument.vibZero += readTouchUtil(leverPin);
instrument.vibZeroBite += readTouchUtil(bitePin);
instrument.vibZeroBite += readTouchRoller(bitePin);
}
instrument.breathZero = bZero / CALIBRATE_SAMPLE_COUNT;
@ -494,30 +495,31 @@ void fullAutoCal() {
calibration.breathMaxValOffset = 1500;
autoCal();
// Bite sensor
calRead = readTouchRoller(bitePin);
calibration.biteThrVal = constrain(calRead + 100, BITE_LO_LIMIT, BITE_HI_LIMIT);
calibration.biteMaxVal = constrain(calRead + 300, BITE_LO_LIMIT, BITE_HI_LIMIT);
/*
// Lever
calRead = readTouchUtil(leverPin);
calRead = readTouchRoller(leverPin);
calibration.leverThrVal = constrain(calRead + 100, LEVER_LO_LIMIT, LEVER_HI_LIMIT);
calibration.leverMaxVal = constrain(calRead + 300, LEVER_LO_LIMIT, LEVER_HI_LIMIT);
// Extra
calRead = readTouchUtil(extraPin);
calRead = readTouchRoller(extraPin);
calibration.extraThrVal = constrain(calRead + 100, EXTRA_LO_LIMIT, EXTRA_HI_LIMIT);
calibration.extraMaxVal = constrain(calRead + 300, EXTRA_LO_LIMIT, EXTRA_HI_LIMIT);
// Bite sensor
calRead = readTouchUtil(bitePin);
calibration.biteThrVal = constrain(calRead + 100, BITE_LO_LIMIT, BITE_HI_LIMIT);
calibration.biteMaxVal = constrain(calRead + 300, BITE_LO_LIMIT, BITE_HI_LIMIT);
// PB
calRead = readTouchUtil(pbDnPin);
calRead = readTouchRoller(pbDnPin);
calibration.pbDnThrVal = constrain(calRead + 100, BITE_LO_LIMIT, BITE_HI_LIMIT);
calibration.pbDnMaxVal = constrain(calRead + 300, BITE_LO_LIMIT, BITE_HI_LIMIT);
calRead = readTouchUtil(pbUpPin);
calRead = readTouchRoller(pbUpPin);
calibration.pbUpThrVal = constrain(calRead + 100, BITE_LO_LIMIT, BITE_HI_LIMIT);
calibration.pbUpMaxVal = constrain(calRead + 300, BITE_LO_LIMIT, BITE_HI_LIMIT);
*/
// Touch sensors
calRead = CTOUCH_HI_LIMIT;
for (byte i = 0; i < 12; i++) {
@ -552,12 +554,12 @@ int readOctave() {
bool rollers[6];
uint16_t ctouchThrVal = calibration.ctouchThrVal;
rollers[0] = readTouchUtil(R1Pin) > ctouchThrVal;
rollers[1] = readTouchUtil(R2Pin) > ctouchThrVal;
rollers[2] = readTouchUtil(R3Pin) > ctouchThrVal;
rollers[3] = readTouchUtil(R4Pin) > ctouchThrVal;
rollers[4] = readTouchUtil(R5Pin) > ctouchThrVal;
rollers[5] = readTouchUtil(R6Pin) > ctouchThrVal;
rollers[0] = readTouchRoller(R1Pin) > ctouchThrVal;
rollers[1] = readTouchRoller(R2Pin) > ctouchThrVal;
rollers[2] = readTouchRoller(R3Pin) > ctouchThrVal;
rollers[3] = readTouchRoller(R4Pin) > ctouchThrVal;
rollers[4] = readTouchRoller(R5Pin) > ctouchThrVal;
rollers[5] = readTouchRoller(R6Pin) > ctouchThrVal;
int offset = 0;
int octaveR = 0;
@ -796,7 +798,7 @@ void changeNote(int fingeredNote, int activeNote, int fingeredNote2, int activeN
noteOn(fingeredNote, instrument.breathSignal, 0);
}
if (fingeredNote2 != activeNote && fingeredNote2 != activeNote2) {
if (fingeredNote2 != fingeredNote && fingeredNote2 != activeNote && fingeredNote2 != activeNote2) {
noteOn(fingeredNote2, instrument.breathSignal, 0);
}
@ -807,7 +809,7 @@ void changeNote(int fingeredNote, int activeNote, int fingeredNote2, int activeN
midiSendNoteOff(activeNote);
}
if (activeNote2 != fingeredNote && activeNote2 != fingeredNote2) {
if (activeNote != activeNote2 && activeNote2 != fingeredNote && activeNote2 != fingeredNote2) {
midiSendNoteOff(activeNote2);
}
}
@ -841,11 +843,10 @@ void initState() {
* Read all utility sensors
*/
void readUtil() {
instrument.biteSignal = readTouchUtil(bitePin);
instrument.leverSignal = readTouchUtil(leverPin);
instrument.pbUpSignal = readTouchUtil(pbUpPin); // PCB PIN "Pu"
instrument.pbDnSignal = readTouchUtil(pbDnPin); // PCB PIN "Pd"
instrument.extraSignal = readTouchUtil(extraPin);
instrument.biteSignal = readTouchRoller(bitePin);
instrument.pbSignal = readSlider(SLIDER_PITCH_BEND);
instrument.leverSignal = readSlider(SLIDER_LEVER);
instrument.extraSignal = readSlider(SLIDER_EXTRA);
}
/**
@ -900,7 +901,7 @@ void readBreath() {
if (state.currentPreset->breathMode == BREATH_ACC || state.currentPreset->breathMode == BREATH_ACC_AT) {
int delta = breathSignal - instrument.breathZero;
if (abs(delta) > state.calibration->breathAltThrValOffset) {
instrument.breathSignal = constrain(instrument.breathSignal + delta / 10, instrument.breathZero, instrument.breathMaxVal);
instrument.breathSignal = constrain(instrument.breathSignal + delta / 15, instrument.breathZero, instrument.breathMaxVal);
}
} else {
instrument.breathSignal = breathSignal + (spikeSignal > 0 ? spikeSignal * state.currentPreset->spikeOnFactor : spikeSignal * state.currentPreset->spikeOffFactor);
@ -1040,6 +1041,7 @@ void loop() {
readSwitches();
runStateMachine();
handleCCs();
readSlider(1);
// cvUpdate();
midiDiscardInput();