From f2d3d91a733a10c83c4ae89c279bb942a8cf0fd9 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 2 Jul 2017 22:40:01 +0200 Subject: [PATCH] Simplify the API Instead of requiring the NumLock key row and column, and the numpad layer index to be passed to `NumLock.toggle` on every call, derive the first two from Macros.row and Macros.col respectively, and the latter from a new class variable, which should be set in the `setup()` method of the sketch. This way, `NumLock.toggle()` becomes argument-less. Signed-off-by: Gergely Nagy --- src/Kaleidoscope-Numlock.cpp | 12 +++++------- src/Kaleidoscope-Numlock.h | 5 +++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Kaleidoscope-Numlock.cpp b/src/Kaleidoscope-Numlock.cpp index e5e19f4b..decee6d9 100644 --- a/src/Kaleidoscope-Numlock.cpp +++ b/src/Kaleidoscope-Numlock.cpp @@ -3,11 +3,10 @@ #include "Kaleidoscope.h" #include "layers.h" -bool NumLock_::isActive; byte NumLock_::row = 255, NumLock_::col = 255; +uint8_t NumLock_::numPadLayer; cRGB numpad_color = CRGB(255, 0, 0); - NumLock_::NumLock_(void) { } @@ -16,7 +15,7 @@ void NumLock_::begin(void) { } void NumLock_::loopHook(bool postClear) { - if (!postClear || !isActive) + if (!postClear || !Layer.isOn(numPadLayer)) return; for (uint8_t r = 0; r < ROWS; r++) { @@ -37,9 +36,9 @@ void NumLock_::loopHook(bool postClear) { LEDControl.led_set_crgb_at(row, col, color); } -const macro_t *NumLock_::toggle(byte row_, byte col_, uint8_t numPadLayer) { - row = row_; - col = col_; +const macro_t *NumLock_::toggle() { + row = Macros.row; + col = Macros.col; if (Layer.isOn(numPadLayer)) { Layer.off(numPadLayer); @@ -47,7 +46,6 @@ const macro_t *NumLock_::toggle(byte row_, byte col_, uint8_t numPadLayer) { } else { Layer.on(numPadLayer); } - isActive = Layer.isOn(numPadLayer); return MACRO(T(KeypadNumLock), END); } diff --git a/src/Kaleidoscope-Numlock.h b/src/Kaleidoscope-Numlock.h index 47b2a77e..1c9ebee4 100644 --- a/src/Kaleidoscope-Numlock.h +++ b/src/Kaleidoscope-Numlock.h @@ -13,11 +13,12 @@ class NumLock_ : public KaleidoscopePlugin { void begin(void) final; - static const macro_t *toggle(byte row, byte col, uint8_t numPadLayer); + static const macro_t *toggle(); static void loopHook(const bool postClear); + static uint8_t numPadLayer; + private: - static bool isActive; static byte row, col; };