diff --git a/src/led_stub.cpp b/src/led_stub.cpp index 88516d4..0f301e9 100644 --- a/src/led_stub.cpp +++ b/src/led_stub.cpp @@ -142,6 +142,35 @@ static uint32_t velocity_to_color(uint8_t velocity) { return launchpad_palette[velocity]; } +static const uint32_t pad_base_colors[10] = { + 0x0000FF, // 0: Blue + 0x0000FF, // 1: Blue + 0xFFAA00, // 2: Orange + 0xFFAA00, // 3: Orange + 0xFFAA00, // 4: Orange + 0xFF0000, // 5: Red + 0xFFFFFF, // 6: White + 0xFFBF00, // 7: Amber + 0xFFFFFF, // 8: White + 0xFFFFFF, // 9: White +}; + +static void apply_pad_color(uint8_t index, uint8_t velocity) { + if (index >= 10) return; + uint32_t base = pad_base_colors[index]; + uint8_t r = (base >> 16) & 0xFF; + uint8_t g = (base >> 8) & 0xFF; + uint8_t b = base & 0xFF; + + if (velocity == 0) { + r = (uint16_t)r * 20 / 255; + g = (uint16_t)g * 20 / 255; + b = (uint16_t)b * 20 / 255; + } + + mux_ptr->set_led_color(index, r, g, b); +} + DefaultLedStub::DefaultLedStub() : initialized(false) { for (int i = 0; i < NUM_LEDS; i++) { led_states[i].active = false; @@ -203,18 +232,14 @@ void DefaultLedStub::begin() { void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity, int8_t led_index) { if (!initialized || !mux_ptr) return; - // Direct index mode (used by CC feedback) + // Direct index mode (used by CC feedback / pad colors) if (led_index >= 0 && led_index < NUM_LEDS) { led_states[led_index].active = (velocity > 0); led_states[led_index].note = note; led_states[led_index].channel = channel; led_states[led_index].velocity = velocity; led_states[led_index].timestamp = millis(); - uint32_t color = velocity_to_color(velocity); - uint8_t r = (color >> 16) & 0xFF; - uint8_t g = (color >> 8) & 0xFF; - uint8_t b = color & 0xFF; - mux_ptr->set_led_color(led_index, r, g, b); + apply_pad_color(led_index, velocity); mux_ptr->show(); Serial.printf("[LED] Set LED %d: note=%d ch=%d vel=%d\n", led_index, note, channel, velocity); return; @@ -265,7 +290,7 @@ void DefaultLedStub::clear_all() { led_states[i].note = 0; led_states[i].channel = 0; led_states[i].timestamp = 0; - mux_ptr->set_led_color(i, 0, 0, 0); + apply_pad_color(i, 0); } mux_ptr->show(); Serial.println("[LED] All cleared");