Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement refreshAt for ActiveLayerKeys #1356

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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});
EvyBongers marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
Loading