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
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

@ -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();
}

@ -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;
};
}
}

Loading…
Cancel
Save