queue MIDI sends with delay(1) to avoid race; force legacy advertising

This commit is contained in:
ash
2026-06-30 21:59:55 +00:00
parent 72a10fa13a
commit 2d3a5a9031
3 changed files with 22 additions and 5 deletions
+16 -5
View File
@@ -49,6 +49,13 @@ void AppTask::update() {
last_switch_state[i] = false;
}
}
if (pending_cc) {
pending_cc = false;
delay(1);
usb_midi->send_cc(pending_channel, pending_cc_num, pending_value);
if (ble_midi) ble_midi->send_cc(pending_channel, pending_cc_num, pending_value);
}
}
void AppTask::process_midi_event(const MidiEvent& event) {
@@ -136,14 +143,18 @@ void AppTask::process_switch_event(uint8_t switch_id, bool pressed) {
uint8_t cc_num = cc_map[i];
uint8_t value = pressed ? 127 : 0;
if (pressed) {
usb_midi->send_cc(channel, cc_num, value);
if (ble_midi) ble_midi->send_cc(channel, cc_num, value);
}
Serial.printf("[APP] Switch %d -> Ch%d CC%d Val%d (%s)\n",
switch_id, channel, cc_num, value,
pressed ? "PRESS" : "RELEASE");
if (pressed) {
// Send MIDI via a flag that loop() processes
pending_cc = true;
pending_channel = channel;
pending_cc_num = cc_num;
pending_value = value;
}
break;
}
}