Fix LED flash/restore logic, heartbeat only on LED 9
- flash_activity: only LED 0, restores properly - flash_sysex: saves ALL LED states, restores all properly - heartbeat: only LED 9, only when no activity flash active - Added sysex_saved arrays to track all LED states
This commit is contained in:
@@ -36,6 +36,8 @@ private:
|
|||||||
bool initialized;
|
bool initialized;
|
||||||
uint32_t activity_off_time = 0;
|
uint32_t activity_off_time = 0;
|
||||||
uint8_t saved_r = 0, saved_g = 0, saved_b = 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;
|
uint32_t heartbeat_time = 0;
|
||||||
uint8_t heartbeat_phase = 0;
|
uint8_t heartbeat_phase = 0;
|
||||||
|
|
||||||
|
|||||||
+37
-12
@@ -277,43 +277,68 @@ void DefaultLedStub::flash_activity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flash ALL LEDs white for SysEx (more visible), LED 0 for regular MIDI
|
// Flash LED 0 white
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
mux_ptr->set_led_color(0, 255, 255, 255);
|
||||||
mux_ptr->set_led_color(i, 255, 255, 255);
|
|
||||||
}
|
|
||||||
mux_ptr->show();
|
mux_ptr->show();
|
||||||
activity_off_time = now + 50;
|
activity_off_time = now + 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultLedStub::flash_sysex() {
|
void DefaultLedStub::flash_sysex() {
|
||||||
if (!initialized || !mux_ptr) return;
|
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++) {
|
for (int i = 0; i < NUM_LEDS; i++) {
|
||||||
mux_ptr->set_led_color(i, 255, 255, 255);
|
mux_ptr->set_led_color(i, 255, 255, 255);
|
||||||
}
|
}
|
||||||
mux_ptr->show();
|
mux_ptr->show();
|
||||||
activity_off_time = millis() + 200;
|
activity_off_time = now + 200;
|
||||||
|
sysex_flash_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultLedStub::update() {
|
void DefaultLedStub::update() {
|
||||||
if (!initialized || !mux_ptr) return;
|
if (!initialized || !mux_ptr) return;
|
||||||
|
|
||||||
// Turn off activity flash
|
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
|
// Turn off activity/SysEx flash
|
||||||
if (activity_off_time > 0 && now >= activity_off_time) {
|
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();
|
mux_ptr->show();
|
||||||
activity_off_time = 0;
|
activity_off_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heartbeat: pulse LED 9 slowly so we know device is alive
|
// Heartbeat: pulse LED 9 slowly (amber)
|
||||||
if (now - heartbeat_time > 2000) {
|
if (now - heartbeat_time > 2000 && !activity_off_time) {
|
||||||
heartbeat_time = now;
|
heartbeat_time = now;
|
||||||
heartbeat_phase = 1;
|
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);
|
uint8_t brightness = (heartbeat_phase < 100) ? (heartbeat_phase * 2) : (400 - heartbeat_phase * 2);
|
||||||
mux_ptr->set_led_color(9, brightness, brightness / 4, 0);
|
if (!led_states[9].active) {
|
||||||
mux_ptr->show();
|
mux_ptr->set_led_color(9, brightness, brightness / 4, 0);
|
||||||
|
mux_ptr->show();
|
||||||
|
}
|
||||||
heartbeat_phase++;
|
heartbeat_phase++;
|
||||||
if (heartbeat_phase > 200) heartbeat_phase = 0;
|
if (heartbeat_phase > 200) heartbeat_phase = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user