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_;
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) {

@ -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_;
};

Loading…
Cancel
Save