diff --git a/doc/plugin/NumPad.md b/doc/plugin/NumPad.md index 83bc5629..a724cf38 100644 --- a/doc/plugin/NumPad.md +++ b/doc/plugin/NumPad.md @@ -1,7 +1,7 @@ # Kaleidoscope-NumPad This is a plugin for [Kaleidoscope][fw], that adds a NumPad-specific LED -effect, along with a way to toggle to a numpad layer, and apply the effect. +effect and applies it when the numpad layer is active. ## Using the extension diff --git a/src/kaleidoscope/plugin/NumPad.cpp b/src/kaleidoscope/plugin/NumPad.cpp index 64257af7..61900bdb 100644 --- a/src/kaleidoscope/plugin/NumPad.cpp +++ b/src/kaleidoscope/plugin/NumPad.cpp @@ -19,45 +19,19 @@ namespace kaleidoscope { namespace plugin { -byte NumPad::numpadLayerToggleKeyRow = 255, NumPad::numpadLayerToggleKeyCol = 255; +// public: uint8_t NumPad::numPadLayer; -bool NumPad::numlockUnsynced = false; -bool NumPad::originalNumLockState = false; cRGB NumPad::color = CRGB(160, 0, 0); uint8_t NumPad::lock_hue = 170; +// private: +byte NumPad::numpadLayerToggleKeyRow = 255, NumPad::numpadLayerToggleKeyCol = 255; +bool NumPad::numpadActive = false; + EventHandlerResult NumPad::onSetup(void) { - originalNumLockState = getNumlockState(); return EventHandlerResult::OK; } -bool NumPad::getNumlockState() { - return !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); -} - -void NumPad::syncNumlockState(bool state) { - bool numLockLEDState = getNumlockState(); - if (numLockLEDState != state) { - kaleidoscope::hid::pressKey(Key_KeypadNumLock); - } -} - - - -void NumPad::cleanupNumlockState() { - if (!numlockUnsynced) { - bool numLockLEDState = getNumlockState(); - ::LEDControl.set_mode(::LEDControl.get_mode_index()); - if (!originalNumLockState) { - syncNumlockState(false); - numLockLEDState = false; - } - originalNumLockState = numLockLEDState; - numlockUnsynced = true; - } - -} - void NumPad::setKeyboardLEDColors(void) { ::LEDControl.set_mode(::LEDControl.get_mode_index()); @@ -87,12 +61,13 @@ void NumPad::setKeyboardLEDColors(void) { EventHandlerResult NumPad::afterEachCycle() { if (!Layer.isActive(numPadLayer)) { - cleanupNumlockState(); + if (numpadActive) { + ::LEDControl.set_mode(::LEDControl.get_mode_index()); + numpadActive = false; + } } else { - if (numlockUnsynced) { - // If it's the first time we're in this loop after toggling the Numpad mode on - syncNumlockState(true); - numlockUnsynced = false; + if (!numpadActive) { + numpadActive = true; } setKeyboardLEDColors(); } diff --git a/src/kaleidoscope/plugin/NumPad.h b/src/kaleidoscope/plugin/NumPad.h index 8735cd84..0a5b8643 100644 --- a/src/kaleidoscope/plugin/NumPad.h +++ b/src/kaleidoscope/plugin/NumPad.h @@ -34,15 +34,11 @@ class NumPad : public kaleidoscope::Plugin { private: - void cleanupNumlockState(void); void setKeyboardLEDColors(void); - bool getNumlockState(void); - void syncNumlockState(bool); static uint8_t numpadLayerToggleKeyRow; static uint8_t numpadLayerToggleKeyCol; - static bool numlockUnsynced; - static bool originalNumLockState; + static bool numpadActive; }; } }