Fix USB MIDI, add LED startup animation, improve logging

- Use ArduinoUSBMIDI library for proper USB MIDI device recognition
- Add LED startup colour cycle (red, green, blue, yellow, magenta, cyan, white)
- Add comprehensive console logging for all MIDI in/out and switch events
- Log unmapped MIDI messages
This commit is contained in:
2026-06-23 13:06:57 +00:00
parent c1b163c8b8
commit 4d81386f78
6 changed files with 130 additions and 98 deletions
+8 -6
View File
@@ -4,7 +4,6 @@
AppTask::AppTask(LedStub* led, SwitchStub* sw, UsbMidiTransport* midi)
: led_driver(led), switch_driver(sw), midi_transport(midi) {
// Default pad mapping
for (uint8_t i = 0; i < NUM_PADS; i++) {
pad_mapping[i].physical_switch = i;
pad_mapping[i].midi_channel = 1;
@@ -15,23 +14,25 @@ AppTask::AppTask(LedStub* led, SwitchStub* sw, UsbMidiTransport* midi)
}
void AppTask::begin() {
Serial.println("[APP] Controller task started");
Serial.println("[APP] Registering MIDI callbacks...");
// Register MIDI callback
midi_transport->on_midi_receive([this](const MidiEvent& event) {
process_midi_event(event);
});
Serial.println("[APP] Controller ready");
}
void AppTask::update() {
// Poll switches
for (uint8_t i = 0; i < NUM_PADS; i++) {
bool is_pressed = switch_driver->is_pressed(i);
if (is_pressed && !last_switch_state[i]) {
Serial.printf("[APP] Switch %d pressed\n", i);
process_switch_event(i, true);
last_switch_state[i] = true;
} else if (!is_pressed && last_switch_state[i]) {
Serial.printf("[APP] Switch %d released\n", i);
process_switch_event(i, false);
last_switch_state[i] = false;
}
@@ -44,7 +45,6 @@ void AppTask::process_midi_event(const MidiEvent& event) {
uint8_t midi_note = event.data1;
uint8_t midi_velocity = event.data2;
// Find matching LED index from pad mapping
for (uint8_t i = 0; i < NUM_PADS; i++) {
if (pad_mapping[i].midi_channel == midi_channel &&
pad_mapping[i].midi_note == midi_note) {
@@ -62,11 +62,13 @@ void AppTask::process_midi_event(const MidiEvent& event) {
Serial.printf("[APP] MIDI -> LED: Ch%d Note%d Vel%d -> LED%d\n",
midi_channel, midi_note, midi_velocity, led_index);
} else {
Serial.printf("[APP] MIDI Ch%d Note%d Vel%d - no LED mapping\n",
midi_channel, midi_note, midi_velocity);
}
}
void AppTask::process_switch_event(uint8_t switch_id, bool pressed) {
// Find mapping for this switch
for (uint8_t i = 0; i < NUM_PADS; i++) {
if (pad_mapping[i].physical_switch == switch_id) {
uint8_t channel = pad_mapping[i].midi_channel;