Set per-pad LED colors with dim off state

- Pad 0-1: Blue, 2-4: Orange, 5: Red, 6: White, 7: Amber, 8-9: White
- Off state (velocity=0): dim at ~8% brightness instead of black
- On state: full brightness of assigned color
- clear_all() sets dim colors instead of off
This commit is contained in:
ash
2026-07-02 06:45:42 +00:00
parent 4ddb9a00bf
commit 66058a6722
+32 -7
View File
@@ -142,6 +142,35 @@ static uint32_t velocity_to_color(uint8_t velocity) {
return launchpad_palette[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) { DefaultLedStub::DefaultLedStub() : initialized(false) {
for (int i = 0; i < NUM_LEDS; i++) { for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].active = false; 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) { void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity, int8_t led_index) {
if (!initialized || !mux_ptr) return; 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) { if (led_index >= 0 && led_index < NUM_LEDS) {
led_states[led_index].active = (velocity > 0); led_states[led_index].active = (velocity > 0);
led_states[led_index].note = note; led_states[led_index].note = note;
led_states[led_index].channel = channel; led_states[led_index].channel = channel;
led_states[led_index].velocity = velocity; led_states[led_index].velocity = velocity;
led_states[led_index].timestamp = millis(); led_states[led_index].timestamp = millis();
uint32_t color = velocity_to_color(velocity); apply_pad_color(led_index, 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);
mux_ptr->show(); mux_ptr->show();
Serial.printf("[LED] Set LED %d: note=%d ch=%d vel=%d\n", led_index, note, channel, velocity); Serial.printf("[LED] Set LED %d: note=%d ch=%d vel=%d\n", led_index, note, channel, velocity);
return; return;
@@ -265,7 +290,7 @@ void DefaultLedStub::clear_all() {
led_states[i].note = 0; led_states[i].note = 0;
led_states[i].channel = 0; led_states[i].channel = 0;
led_states[i].timestamp = 0; led_states[i].timestamp = 0;
mux_ptr->set_led_color(i, 0, 0, 0); apply_pad_color(i, 0);
} }
mux_ptr->show(); mux_ptr->show();
Serial.println("[LED] All cleared"); Serial.println("[LED] All cleared");