Merge pull request #12 from keyboardio/f/numlock-sync

Sync the NUMPAD layer state with the host
pull/365/head
Jesse Vincent 7 years ago committed by GitHub
commit 45a71751e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,15 +5,29 @@
byte NumLock_::row = 255, NumLock_::col = 255;
uint8_t NumLock_::numPadLayer;
bool NumLock_::isOn;
cRGB numpad_color = CRGB(255, 0, 0);
void NumLock_::begin(void) {
Kaleidoscope.useLoopHook(loopHook);
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void NumLock_::loopHook(bool postClear) {
if (!postClear || !Layer.isOn(numPadLayer))
if (!postClear)
return;
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
if (numState != isOn) {
isOn = numState;
if (isOn) {
Layer.on(numPadLayer);
} else {
Layer.off(numPadLayer);
LEDControl.set_mode(LEDControl.get_mode_index());
}
}
if (!isOn)
return;
for (uint8_t r = 0; r < ROWS; r++) {
@ -36,21 +50,4 @@ void NumLock_::loopHook(bool postClear) {
LEDControl.setCrgbAt(row, col, color);
}
Key NumLock_::eventHandlerHook(Key key, byte row, byte col, uint8_t key_state) {
if (key != Key_KeypadNumLock)
return key;
if (!keyToggledOn(key_state))
return key;
if (Layer.isOn(numPadLayer)) {
Layer.off(numPadLayer);
LEDControl.set_mode(LEDControl.get_mode_index());
} else {
Layer.on(numPadLayer);
}
return key;
}
NumLock_ NumLock;

@ -14,9 +14,9 @@ class NumLock_ : public KaleidoscopePlugin {
private:
static void loopHook(const bool postClear);
static Key eventHandlerHook(Key key, byte row, byte col, uint8_t key_state);
static byte row, col;
static bool isOn;
};
extern NumLock_ NumLock;

Loading…
Cancel
Save