Extract a couple methods and rename a variable

Signed-off-by: Jesse Vincent <jesse@keyboard.io>
pull/365/head
Jesse Vincent 6 years ago
parent 380a2e8a28
commit b491146f33

@ -36,32 +36,30 @@ static bool getNumlockState() {
} }
static void syncNumlock(bool state) { static void syncNumlock(bool state) {
bool numState = getNumlockState(); bool numLockLEDState = getNumlockState();
if (numState != state) { if (numLockLEDState != state) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock); kaleidoscope::hid::pressKey(Key_KeypadNumLock);
} }
} }
kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() {
if (!Layer.isOn(numPadLayer)) {
bool numState = getNumlockState(); void NumPad_::cleanupNumlockState() {
bool numLockLEDState = getNumlockState();
if (!cleanupDone) { if (!cleanupDone) {
LEDControl.set_mode(LEDControl.get_mode_index()); LEDControl.set_mode(LEDControl.get_mode_index());
if (!originalNumLockState) { if (!originalNumLockState) {
syncNumlock(false); syncNumlock(false);
numState = false; numLockLEDState = false;
} }
cleanupDone = true; cleanupDone = true;
} }
originalNumLockState = numState; originalNumLockState = numLockLEDState;
return kaleidoscope::EventHandlerResult::OK;
} }
cleanupDone = false; void NumPad_::setKeyboardLEDColors(void) {
syncNumlock(true);
LEDControl.set_mode(LEDControl.get_mode_index()); LEDControl.set_mode(LEDControl.get_mode_index());
for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t r = 0; r < ROWS; r++) {
@ -82,12 +80,28 @@ kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() {
} }
} }
if ((numpad_lock_key_row > ROWS) || (numpad_lock_key_col > COLS)) { if ((numpad_lock_key_row <= ROWS) && (numpad_lock_key_col <= COLS)) {
return kaleidoscope::EventHandlerResult::OK;
cRGB lock_color = breath_compute(lock_hue);
LEDControl.setCrgbAt(numpad_lock_key_row, numpad_lock_key_col, lock_color); LEDControl.setCrgbAt(numpad_lock_key_row, numpad_lock_key_col, lock_color);
}
}
kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() {
if (!Layer.isOn(numPadLayer)) {
cleanupNumlockState();
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
} }
cleanupDone = false;
syncNumlock(true);
setKeyboardLEDColors();
return kaleidoscope::EventHandlerResult::OK;
}
NumPad_ NumPad; NumPad_ NumPad;

@ -32,6 +32,10 @@ class NumPad_ : public kaleidoscope::Plugin {
kaleidoscope::EventHandlerResult afterEachCycle(); kaleidoscope::EventHandlerResult afterEachCycle();
private: private:
void cleanupNumlockState(void);
void setKeyboardLEDColors(void);
static uint8_t numpad_lock_key_row; static uint8_t numpad_lock_key_row;
static uint8_t numpad_lock_key_col; static uint8_t numpad_lock_key_col;
static bool cleanupDone; static bool cleanupDone;

Loading…
Cancel
Save