diff --git a/include/led_stub.h b/include/led_stub.h index 4ee0b3e..3c543fc 100644 --- a/include/led_stub.h +++ b/include/led_stub.h @@ -36,6 +36,8 @@ private: bool initialized; uint32_t activity_off_time = 0; uint8_t saved_r = 0, saved_g = 0, saved_b = 0; + uint8_t sysex_saved_r[10] = {0}, sysex_saved_g[10] = {0}, sysex_saved_b[10] = {0}; + bool sysex_flash_active = false; uint32_t heartbeat_time = 0; uint8_t heartbeat_phase = 0; diff --git a/src/led_stub.cpp b/src/led_stub.cpp index 654c812..1acbfb2 100644 --- a/src/led_stub.cpp +++ b/src/led_stub.cpp @@ -277,43 +277,68 @@ void DefaultLedStub::flash_activity() { } } - // Flash ALL LEDs white for SysEx (more visible), LED 0 for regular MIDI - for (int i = 0; i < NUM_LEDS; i++) { - mux_ptr->set_led_color(i, 255, 255, 255); - } + // Flash LED 0 white + mux_ptr->set_led_color(0, 255, 255, 255); mux_ptr->show(); activity_off_time = now + 50; } void DefaultLedStub::flash_sysex() { if (!initialized || !mux_ptr) return; + + // Save all LED states + for (int i = 0; i < NUM_LEDS; i++) { + if (led_states[i].active) { + uint32_t color = launchpad_palette[led_states[i].velocity]; + sysex_saved_r[i] = (color >> 16) & 0xFF; + sysex_saved_g[i] = (color >> 8) & 0xFF; + sysex_saved_b[i] = color & 0xFF; + } else { + sysex_saved_r[i] = 0; + sysex_saved_g[i] = 0; + sysex_saved_b[i] = 0; + } + } + + // Flash ALL LEDs white for (int i = 0; i < NUM_LEDS; i++) { mux_ptr->set_led_color(i, 255, 255, 255); } mux_ptr->show(); - activity_off_time = millis() + 200; + activity_off_time = now + 200; + sysex_flash_active = true; } void DefaultLedStub::update() { if (!initialized || !mux_ptr) return; - // Turn off activity flash uint32_t now = millis(); + + // Turn off activity/SysEx flash if (activity_off_time > 0 && now >= activity_off_time) { - mux_ptr->set_led_color(0, saved_r, saved_g, saved_b); + if (sysex_flash_active) { + for (int i = 0; i < NUM_LEDS; i++) { + mux_ptr->set_led_color(i, sysex_saved_r[i], sysex_saved_g[i], sysex_saved_b[i]); + } + sysex_flash_active = false; + } else { + mux_ptr->set_led_color(0, saved_r, saved_g, saved_b); + } mux_ptr->show(); activity_off_time = 0; } - // Heartbeat: pulse LED 9 slowly so we know device is alive - if (now - heartbeat_time > 2000) { + // Heartbeat: pulse LED 9 slowly (amber) + if (now - heartbeat_time > 2000 && !activity_off_time) { heartbeat_time = now; heartbeat_phase = 1; } - if (heartbeat_phase) { + if (heartbeat_phase && !activity_off_time) { uint8_t brightness = (heartbeat_phase < 100) ? (heartbeat_phase * 2) : (400 - heartbeat_phase * 2); - mux_ptr->set_led_color(9, brightness, brightness / 4, 0); - mux_ptr->show(); + if (!led_states[9].active) { + mux_ptr->set_led_color(9, brightness, brightness / 4, 0); + mux_ptr->show(); + } heartbeat_phase++; if (heartbeat_phase > 200) heartbeat_phase = 0; }