diff --git a/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.cpp b/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.cpp index 85c5c941d6..8b4b569f7b 100644 --- a/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.cpp +++ b/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.cpp @@ -33,11 +33,14 @@ cRGB LEDActiveLayerKeysEffect::default_layer_color_ = CRGB(0, 0, 0); LEDActiveLayerKeysEffect::TransientLEDMode::TransientLEDMode( const LEDActiveLayerKeysEffect *parent) - : parent_(parent) {} + : parent_(parent), + active_color_{0, 0, 0} {} -cRGB LEDActiveLayerKeysEffect::TransientLEDMode::getLayerColor(uint8_t layer) { +cRGB LEDActiveLayerKeysEffect::TransientLEDMode::getActiveColor() { cRGB color; + uint8_t layer = ::Layer.mostRecent(); + if (layer < parent_->colormap_size_) { color.r = pgm_read_byte(&(parent_->colormap_[layer].r)); color.g = pgm_read_byte(&(parent_->colormap_[layer].g)); @@ -53,16 +56,22 @@ void LEDActiveLayerKeysEffect::TransientLEDMode::onActivate() { if (!Runtime.has_leds) return; - uint8_t top_layer = ::Layer.mostRecent(); - cRGB active_color_ = getLayerColor(top_layer); + active_color_ = getActiveColor(); for (auto key_addr : KeyAddr::all()) { - Key k = Layer.lookupOnActiveLayer(key_addr); - Key layer_key = Layer.getKey(top_layer, key_addr); + refreshAt(key_addr); + } +} - if ((k == layer_key) && (k != Key_NoKey) && (k != Key_Transparent)) { - ::LEDControl.setCrgbAt(KeyAddr(key_addr), active_color_); - } +void LEDActiveLayerKeysEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) { + uint8_t top_layer = ::Layer.mostRecent(); + Key k = Layer.lookupOnActiveLayer(key_addr); + Key layer_key = Layer.getKey(top_layer, key_addr); + + if ((k == layer_key) && (k != Key_NoKey) && (k != Key_Transparent)) { + ::LEDControl.setCrgbAt(KeyAddr(key_addr), active_color_); + } else { + ::LEDControl.setCrgbAt(KeyAddr(key_addr), {0, 0, 0}); } } diff --git a/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h b/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h index ab909f7597..4381c1a9de 100644 --- a/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h +++ b/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h @@ -53,11 +53,14 @@ class LEDActiveLayerKeysEffect : public Plugin, protected: void onActivate() final; + void refreshAt(KeyAddr key_addr) final; private: const LEDActiveLayerKeysEffect *parent_; - cRGB getLayerColor(uint8_t layer); + cRGB active_color_; + + cRGB getActiveColor(); friend class LEDActiveLayerKeysEffect; };