From bd20d1938b2cdb8d942c4046b66008720960a167 Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Wed, 24 Jun 2026 01:28:56 +0000 Subject: [PATCH] Fix duplicate set_led_state, add set_led_brightness to interface --- include/led_stub.h | 2 ++ src/led_stub.cpp | 38 +++++++------------------------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/include/led_stub.h b/include/led_stub.h index b3cf338..4488bca 100644 --- a/include/led_stub.h +++ b/include/led_stub.h @@ -9,6 +9,7 @@ public: virtual void begin() = 0; virtual void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) = 0; virtual void clear_all() = 0; + virtual void set_led_brightness(uint8_t brightness) = 0; virtual uint8_t note_to_index(uint8_t note) { return note; @@ -36,6 +37,7 @@ public: void begin() override; void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) override; void clear_all() override; + void set_led_brightness(uint8_t brightness) override; void set_mux(PixelStompMux* mux); }; diff --git a/src/led_stub.cpp b/src/led_stub.cpp index 3895e18..fdf59ad 100644 --- a/src/led_stub.cpp +++ b/src/led_stub.cpp @@ -163,41 +163,17 @@ void DefaultLedStub::set_led_brightness(uint8_t brightness) { mux_ptr->show(); } -void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) { - if (!initialized || !mux_ptr) return; - - uint8_t led_index = note_to_index(note); - - if (led_index < NUM_LEDS) { - led_states[led_index].note = note; - led_states[led_index].channel = channel; - led_states[led_index].velocity = velocity; - led_states[led_index].active = (velocity > 0); - led_states[led_index].timestamp = millis(); - - if (velocity > 0) { - uint8_t brightness = map(velocity, 1, 127, 50, 255); - mux_ptr->set_led_color(led_index, brightness, brightness, brightness); - } else { - mux_ptr->set_led_color(led_index, 0, 0, 0); - } - mux_ptr->show(); - - Serial.printf("[LED] Note %d -> LED %d Vel %d (%s)\n", - note, led_index, velocity, - velocity > 0 ? "ON" : "OFF"); - } else { - Serial.printf("[LED] Out of range: %d (Note: %d)\n", led_index, note); - } -} - void DefaultLedStub::clear_all() { + if (!initialized || !mux_ptr) return; + for (int i = 0; i < NUM_LEDS; i++) { led_states[i].active = false; led_states[i].velocity = 0; + led_states[i].note = 0; + led_states[i].channel = 0; + led_states[i].timestamp = 0; + mux_ptr->set_led_color(i, 0, 0, 0); } - if (mux_ptr) { - mux_ptr->clear_all(); - } + mux_ptr->show(); Serial.println("[LED] All cleared"); }