Skip to content

Commit

Permalink
Implement refreshAt for ActiveLayerKeys
Browse files Browse the repository at this point in the history
Signed-off-by: Evy Bongers <[email protected]>
  • Loading branch information
EvyBongers committed Nov 2, 2023
1 parent d183f49 commit 62d8f2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 62d8f2d

Please sign in to comment.