From ed92d5109c64574b42d3a4ec6d3dfbc0ebed0ced Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 27 Jan 2017 12:00:53 +0100 Subject: [PATCH] Fix the LED mode handling First of all, to disallow switching to LEDNumlock, we need to do the check in the `.init()` method, not in `.setup()`. Second, tracking the previous LED mode can be done a lot simpler - and a lot reliably. With these changes, the NumLock LED effect works as it is expected to. Signed-off-by: Gergely Nagy --- src/Keyboardio-LEDEffect-Numlock.cpp | 16 ++++++---------- src/Keyboardio-LEDEffect-Numlock.h | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Keyboardio-LEDEffect-Numlock.cpp b/src/Keyboardio-LEDEffect-Numlock.cpp index 0b707eb1..6468fd78 100644 --- a/src/Keyboardio-LEDEffect-Numlock.cpp +++ b/src/Keyboardio-LEDEffect-Numlock.cpp @@ -18,9 +18,9 @@ LEDNumlock::begin (void) { } void -LEDNumlock::setup (void) { +LEDNumlock::init (void) { if (!Layer.isOn (numpadIndex)) { - LEDControl.next_mode (); + LEDControl.next_mode(); } } @@ -42,15 +42,11 @@ LEDNumlock::loopHook (bool postClear) { if (!postClear) return; - if (Layer.isOn (numpadIndex)) { - if (storedLEDMode != us) { + if (!Layer.isOn (numpadIndex)) { + if (LEDControl.get_mode () != us) storedLEDMode = LEDControl.get_mode (); - } - LEDControl.set_mode (us); - } - - if (!Layer.isOn (numpadIndex) && - LEDControl.get_mode () == us) { LEDControl.set_mode (storedLEDMode); + } else { + LEDControl.set_mode (us); } } diff --git a/src/Keyboardio-LEDEffect-Numlock.h b/src/Keyboardio-LEDEffect-Numlock.h index 14521096..46ea71d7 100644 --- a/src/Keyboardio-LEDEffect-Numlock.h +++ b/src/Keyboardio-LEDEffect-Numlock.h @@ -10,7 +10,7 @@ class LEDNumlock : LEDMode { virtual void begin (void) final; virtual void update (void) final; - virtual void setup (void) final; + virtual void init (void) final; private: static void loopHook (bool postClear);