Colormap: Migrate to using `onLayerChange`

Instead of tracking layer changes ourselves, use the new `onLayerChange` event
to do that for us. This makes the code a tiny bit easier to follow.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/363/head
Gergely Nagy 6 years ago
parent 445687634e
commit 7214cc0d47
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -28,7 +28,7 @@ namespace plugin {
uint16_t ColormapEffect::map_base_; uint16_t ColormapEffect::map_base_;
uint8_t ColormapEffect::max_layers_; uint8_t ColormapEffect::max_layers_;
uint8_t ColormapEffect::last_highest_layer_; uint8_t ColormapEffect::top_layer_;
void ColormapEffect::max_layers(uint8_t max_) { void ColormapEffect::max_layers(uint8_t max_) {
if (map_base_ != 0) if (map_base_ != 0)
@ -42,21 +42,20 @@ void ColormapEffect::onActivate(void) {
if (!Kaleidoscope.has_leds) if (!Kaleidoscope.has_leds)
return; return;
last_highest_layer_ = Layer.top(); top_layer_ = Layer.top();
if (last_highest_layer_ <= max_layers_) if (top_layer_ <= max_layers_)
::LEDPaletteTheme.updateHandler(map_base_, last_highest_layer_); ::LEDPaletteTheme.updateHandler(map_base_, top_layer_);
} }
void ColormapEffect::update(void) { void ColormapEffect::refreshAt(byte row, byte col) {
if (!Kaleidoscope.has_leds || Layer.top() == last_highest_layer_) if (top_layer_ <= max_layers_)
return; ::LEDPaletteTheme.refreshAt(map_base_, top_layer_, row, col);
onActivate();
} }
void ColormapEffect::refreshAt(byte row, byte col) { EventHandlerResult ColormapEffect::onLayerChange() {
if (last_highest_layer_ <= max_layers_) if (::LEDControl.get_mode() == this)
::LEDPaletteTheme.refreshAt(map_base_, last_highest_layer_, row, col); onActivate();
return EventHandlerResult::OK;
} }
EventHandlerResult ColormapEffect::onFocusEvent(const char *command) { EventHandlerResult ColormapEffect::onFocusEvent(const char *command) {

@ -28,15 +28,15 @@ class ColormapEffect : public LEDMode {
void max_layers(uint8_t max_); void max_layers(uint8_t max_);
EventHandlerResult onLayerChange();
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
protected: protected:
void onActivate(void) final; void onActivate(void) final;
void update(void) final;
void refreshAt(byte row, byte col) final; void refreshAt(byte row, byte col) final;
private: private:
static uint8_t last_highest_layer_; static uint8_t top_layer_;
static uint8_t max_layers_; static uint8_t max_layers_;
static uint16_t map_base_; static uint16_t map_base_;
}; };

Loading…
Cancel
Save