Merge pull request #575 from keyboardio/numist/numpad-avoids-numlock

Remove numlock state management logic from NumPad plugin
pull/601/head
Gergely Nagy 6 years ago committed by GitHub
commit 3ccaf187a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,7 @@
# Kaleidoscope-NumPad # Kaleidoscope-NumPad
This is a plugin for [Kaleidoscope][fw], that adds a NumPad-specific LED 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 ## Using the extension

@ -19,45 +19,19 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
byte NumPad::numpadLayerToggleKeyRow = 255, NumPad::numpadLayerToggleKeyCol = 255; // public:
uint8_t NumPad::numPadLayer; uint8_t NumPad::numPadLayer;
bool NumPad::numlockUnsynced = false;
bool NumPad::originalNumLockState = false;
cRGB NumPad::color = CRGB(160, 0, 0); cRGB NumPad::color = CRGB(160, 0, 0);
uint8_t NumPad::lock_hue = 170; uint8_t NumPad::lock_hue = 170;
// private:
byte NumPad::numpadLayerToggleKeyRow = 255, NumPad::numpadLayerToggleKeyCol = 255;
bool NumPad::numpadActive = false;
EventHandlerResult NumPad::onSetup(void) { EventHandlerResult NumPad::onSetup(void) {
originalNumLockState = getNumlockState();
return EventHandlerResult::OK; 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) { void NumPad::setKeyboardLEDColors(void) {
::LEDControl.set_mode(::LEDControl.get_mode_index()); ::LEDControl.set_mode(::LEDControl.get_mode_index());
@ -87,12 +61,13 @@ void NumPad::setKeyboardLEDColors(void) {
EventHandlerResult NumPad::afterEachCycle() { EventHandlerResult NumPad::afterEachCycle() {
if (!Layer.isActive(numPadLayer)) { if (!Layer.isActive(numPadLayer)) {
cleanupNumlockState(); if (numpadActive) {
::LEDControl.set_mode(::LEDControl.get_mode_index());
numpadActive = false;
}
} else { } else {
if (numlockUnsynced) { if (!numpadActive) {
// If it's the first time we're in this loop after toggling the Numpad mode on numpadActive = true;
syncNumlockState(true);
numlockUnsynced = false;
} }
setKeyboardLEDColors(); setKeyboardLEDColors();
} }

@ -34,15 +34,11 @@ class NumPad : public kaleidoscope::Plugin {
private: private:
void cleanupNumlockState(void);
void setKeyboardLEDColors(void); void setKeyboardLEDColors(void);
bool getNumlockState(void);
void syncNumlockState(bool);
static uint8_t numpadLayerToggleKeyRow; static uint8_t numpadLayerToggleKeyRow;
static uint8_t numpadLayerToggleKeyCol; static uint8_t numpadLayerToggleKeyCol;
static bool numlockUnsynced; static bool numpadActive;
static bool originalNumLockState;
}; };
} }
} }

Loading…
Cancel
Save