From 7214cc0d4731d77579a3f4cca1c00c1fd60c66df Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 10 Oct 2018 08:31:27 +0200 Subject: [PATCH] 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 --- src/kaleidoscope/plugin/Colormap.cpp | 23 +++++++++++------------ src/kaleidoscope/plugin/Colormap.h | 4 ++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/kaleidoscope/plugin/Colormap.cpp b/src/kaleidoscope/plugin/Colormap.cpp index 57790931..ac7b3144 100644 --- a/src/kaleidoscope/plugin/Colormap.cpp +++ b/src/kaleidoscope/plugin/Colormap.cpp @@ -28,7 +28,7 @@ namespace plugin { uint16_t ColormapEffect::map_base_; uint8_t ColormapEffect::max_layers_; -uint8_t ColormapEffect::last_highest_layer_; +uint8_t ColormapEffect::top_layer_; void ColormapEffect::max_layers(uint8_t max_) { if (map_base_ != 0) @@ -42,21 +42,20 @@ void ColormapEffect::onActivate(void) { if (!Kaleidoscope.has_leds) return; - last_highest_layer_ = Layer.top(); - if (last_highest_layer_ <= max_layers_) - ::LEDPaletteTheme.updateHandler(map_base_, last_highest_layer_); + top_layer_ = Layer.top(); + if (top_layer_ <= max_layers_) + ::LEDPaletteTheme.updateHandler(map_base_, top_layer_); } -void ColormapEffect::update(void) { - if (!Kaleidoscope.has_leds || Layer.top() == last_highest_layer_) - return; - - onActivate(); +void ColormapEffect::refreshAt(byte row, byte col) { + if (top_layer_ <= max_layers_) + ::LEDPaletteTheme.refreshAt(map_base_, top_layer_, row, col); } -void ColormapEffect::refreshAt(byte row, byte col) { - if (last_highest_layer_ <= max_layers_) - ::LEDPaletteTheme.refreshAt(map_base_, last_highest_layer_, row, col); +EventHandlerResult ColormapEffect::onLayerChange() { + if (::LEDControl.get_mode() == this) + onActivate(); + return EventHandlerResult::OK; } EventHandlerResult ColormapEffect::onFocusEvent(const char *command) { diff --git a/src/kaleidoscope/plugin/Colormap.h b/src/kaleidoscope/plugin/Colormap.h index 03ca53d0..7837a8c3 100644 --- a/src/kaleidoscope/plugin/Colormap.h +++ b/src/kaleidoscope/plugin/Colormap.h @@ -28,15 +28,15 @@ class ColormapEffect : public LEDMode { void max_layers(uint8_t max_); + EventHandlerResult onLayerChange(); EventHandlerResult onFocusEvent(const char *command); protected: void onActivate(void) final; - void update(void) final; void refreshAt(byte row, byte col) final; private: - static uint8_t last_highest_layer_; + static uint8_t top_layer_; static uint8_t max_layers_; static uint16_t map_base_; };