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
+5
View File
@@ -38,6 +38,11 @@ private:
uint8_t sysex_len = 0;
bool sysex_active = false;
bool pending_cc = false;
uint8_t pending_channel = 0;
uint8_t pending_cc_num = 0;
uint8_t pending_value = 0;
void process_switch_event(uint8_t switch_id, bool pressed);
void run_palette_test();
void handle_sysex(const uint8_t* data, uint8_t len);
+1
View File
@@ -18,6 +18,7 @@ build_flags =
-DARDUINO_USB_CDC_ON_BOOT=1
-DUSE_TINYUSB=1
-Wno-macro-redefined
-DMYNEWT_VAL_BLE_EXT_ADV=0
monitor_speed = 115200
+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;
}
}