Skip to content

Commit

Permalink
Merge pull request #1356 from EvyBongers/feat/ActiveLayerKeys/refreshAt
Browse files Browse the repository at this point in the history
Implement refreshAt for ActiveLayerKeys
  • Loading branch information
obra authored Nov 13, 2023
2 parents 1ebc1a3 + 8dc41a6 commit b01982f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
10 changes: 9 additions & 1 deletion plugins/Kaleidoscope-LED-ActiveLayerKeys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ void setup () {
};

Kaleidoscope.setup();
// By default, only LEDs for keys on the topmost layer are lit.
//LEDActiveLayerKeysEffect.lightLowerLayers(false);
LEDActiveLayerKeysEffect.setColormap(layerColormap);
}
```
## Plugin properties
The plugin provides the `LEDActiveLayerKeysEffect` object, which has the following
method:
methods:
### `.setColormap(colormap)`
Expand All @@ -43,6 +45,12 @@ method:
> same amount of items as there are layers. Any layer that doesn't have a
> matching entry in the array, will have leds turned off.
### `.lightLowerLayers(boolean)`
> By default, this plugin only lights up LEDs keys on the topmost layer. This
> method allows overriding this default, to have the plugin change the leds of
> all non-blocked keys to the color of their respective layers.
## Dependencies
* [Kaleidoscope-LEDControl](Kaleidoscope-LEDControl.md)
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void setup() {

Kaleidoscope.setup();
LEDActiveLayerKeysEffect.setColormap(layerColormap);
// Light up leds of keys on lower layers as well
LEDActiveLayerKeysEffect.lightLowerLayers(true);
LEDActiveLayerKeysEffect.activate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ namespace kaleidoscope {
namespace plugin {

cRGB LEDActiveLayerKeysEffect::default_layer_color_ = CRGB(0, 0, 0);
bool LEDActiveLayerKeysEffect::light_lower_layers = false;

LEDActiveLayerKeysEffect::TransientLEDMode::TransientLEDMode(
const LEDActiveLayerKeysEffect *parent)
: parent_(parent) {}
: parent_(parent),
active_color_{0, 0, 0} {}

cRGB LEDActiveLayerKeysEffect::TransientLEDMode::getLayerColor(uint8_t layer) {
cRGB color;
Expand All @@ -53,16 +55,27 @@ void LEDActiveLayerKeysEffect::TransientLEDMode::onActivate() {
if (!Runtime.has_leds)
return;

uint8_t top_layer = ::Layer.mostRecent();
cRGB active_color_ = getLayerColor(top_layer);
uint8_t top_layer = ::Layer.mostRecent();
active_color_ = getLayerColor(top_layer);

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 if ((light_lower_layers) && (k != Key_Transparent)) {
uint8_t key_layer = Layer.lookupActiveLayer(key_addr);
cRGB layer_color = getLayerColor(key_layer);
::LEDControl.setCrgbAt(KeyAddr(key_addr), layer_color);
} else {
::LEDControl.setCrgbAt(KeyAddr(key_addr), {0, 0, 0});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class LEDActiveLayerKeysEffect : public Plugin,
colormap_ = colormap;
colormap_size_ = _colormap_size;
}
static void lightLowerLayers(bool show) {
light_lower_layers = show;
}
static void setDefaultColor(cRGB color) {
default_layer_color_ = color;
}
Expand All @@ -53,10 +56,13 @@ class LEDActiveLayerKeysEffect : public Plugin,

protected:
void onActivate() final;
void refreshAt(KeyAddr key_addr) final;

private:
const LEDActiveLayerKeysEffect *parent_;

cRGB active_color_;

cRGB getLayerColor(uint8_t layer);

friend class LEDActiveLayerKeysEffect;
Expand All @@ -68,6 +74,7 @@ class LEDActiveLayerKeysEffect : public Plugin,
uint8_t colormap_size_{0};

static cRGB default_layer_color_;
static bool light_lower_layers;
};

} // namespace plugin
Expand Down

0 comments on commit b01982f

Please sign in to comment.