Skip to content

Commit 019353d

Browse files
committed
Correct ADC values and added support for patch slot 0 for loaded patches
1 parent a65e674 commit 019353d

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

DaisyPod/Src/DaisyPod.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,8 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
9898
// with 64.5 cycles sample time, 30 MHz ADC clock, and ClockPrescaler = 32
9999
extern uint16_t adc_values[NOF_ADC_VALUES];
100100
for (size_t i = 0; i < NOF_ADC_VALUES; i++) {
101-
// IIR exponential filter with lambda 0.75: y[n] = 0.75*y[n-1] +
102-
// 0.25*x[n] We include offset to match 0 point too, but it may differ
103-
// between devices CV is bipolar
104-
// smooth_adc_values[i] = __SSAT(
105-
// (smooth_adc_values[i] * 3 + 4095 + 121 - 2 * adc_values[i]) >> 2, 13);
106-
// i++;
107-
// Knobs are unipolar
108-
smooth_adc_values[i] = __USAT(
109-
(smooth_adc_values[i] * 3 + 4095 + 132 - 2 * adc_values[i]) >> 2, 12);
110-
// i++;
101+
// IIR exponential filter with lambda 0.75: y[n] = 0.75*y[n-1] + 0.25*x[n]
102+
smooth_adc_values[i] = (smooth_adc_values[i]*3 + adc_values[i]) >> 2;
111103
}
112104
}
113105
}
@@ -252,7 +244,15 @@ static void updatePreset() {
252244
break;
253245
case CONFIGURE_MODE:
254246
if (is_patch_selection) {
255-
if (counter < PATCH_RESET_COUNTER / 2 && registry.hasPatch(patchselect)) {
247+
bool has_patch = false;
248+
if (patchselect == 0) {
249+
// Dynamically loaded patch is valid only
250+
has_patch = program.getProgramIndex() == 0;
251+
}
252+
else {
253+
has_patch = registry.hasPatch(patchselect);
254+
}
255+
if (counter < PATCH_RESET_COUNTER / 2 && has_patch) {
256256
uint8_t bank = patchselect / 8;
257257
uint8_t slot = patchselect - bank * 8;
258258
setLed(0, (uint32_t)colours[bank]);
@@ -265,7 +265,7 @@ static void updatePreset() {
265265
if (encoder.isRisingEdge()) {
266266
setLed(0, 0);
267267
setLed(1, 0);
268-
if (registry.hasPatch(patchselect)) {
268+
if (patchselect > 0 && registry.hasPatch(patchselect)) {
269269
program.loadProgram(patchselect);
270270
program.resetProgram(false);
271271
}
@@ -277,7 +277,7 @@ static void updatePreset() {
277277
if (new_enc_value > enc_value) {
278278
patchselect++;
279279
if (patchselect >= registry.getNumberOfPatches())
280-
patchselect = 0;
280+
patchselect = program.getProgramIndex() == 0 ? 0 : 1;
281281
enc_value = new_enc_value;
282282
}
283283
else if (new_enc_value < enc_value) {
@@ -332,7 +332,8 @@ static void updatePreset() {
332332
void onChangeMode(OperationMode new_mode, OperationMode old_mode) {
333333
counter = 0;
334334
enc_value = encoder.getValue();
335-
patchselect = settings.program_index;
335+
//patchselect = settings.program_index;
336+
patchselect = program.getProgramIndex();
336337
setLed(0, 0);
337338
setLed(1, 0);
338339
/*

0 commit comments

Comments
 (0)