From b6461e5f40b50f43e522dffd12113edeca7532ff Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 2 Jul 2017 18:37:54 +0200 Subject: [PATCH] Add LEDControl.init_mode() The new `init_mode()` method simply (re-)inits the current mode. Useful when a plugin that changes LEDs outside of LED modes wants to reset the active LED mode. Doubly useful when the active LED mode does all the work in its `init()` method. Signed-off-by: Gergely Nagy --- src/Kaleidoscope-LEDControl.cpp | 6 ++++++ src/Kaleidoscope-LEDControl.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index bdc76ba4..2cd78393 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -51,6 +51,12 @@ LEDControl_::update(void) { previousMode = mode; } +void +LEDControl_::init_mode(void) { + if (modes[mode]) + (modes[mode]->init)(); +} + void LEDControl_::set_mode(uint8_t mode_) { if (mode_ < LED_MAX_MODES) diff --git a/src/Kaleidoscope-LEDControl.h b/src/Kaleidoscope-LEDControl.h index 6dbf92f7..528e147d 100644 --- a/src/Kaleidoscope-LEDControl.h +++ b/src/Kaleidoscope-LEDControl.h @@ -28,6 +28,7 @@ class LEDControl_ : public KaleidoscopePlugin { static void update(void); static void set_mode(uint8_t mode); static uint8_t get_mode(); + static void init_mode(void); static int8_t mode_add(LEDMode *mode);