Merge pull request #8 from keyboardio/f/plugin-v2

Updated to use the new plugin APIs
pull/365/head
Gergely Nagy 7 years ago committed by GitHub
commit 2bdc07b7bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,9 +9,9 @@ bool NumPad_::cleanupDone = true;
bool NumPad_::originalNumLockState = false;
cRGB numpad_color = CRGB(255, 0, 0);
void NumPad_::begin(void) {
Kaleidoscope.useLoopHook(loopHook);
kaleidoscope::EventHandlerResult NumPad_::onSetup(void) {
originalNumLockState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
return kaleidoscope::EventHandlerResult::OK;
}
static void syncNumlock(bool state) {
@ -21,10 +21,7 @@ static void syncNumlock(bool state) {
}
}
void NumPad_::loopHook(bool postClear) {
if (!postClear)
return;
kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() {
if (!Layer.isOn(numPadLayer)) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
if (!cleanupDone) {
@ -38,7 +35,8 @@ void NumPad_::loopHook(bool postClear) {
}
}
originalNumLockState = numState;
return;
return kaleidoscope::EventHandlerResult::OK;
}
cleanupDone = false;
@ -65,10 +63,26 @@ void NumPad_::loopHook(bool postClear) {
}
if (row > ROWS || col > COLS)
return;
return kaleidoscope::EventHandlerResult::OK;
cRGB color = breath_compute();
LEDControl.setCrgbAt(row, col, color);
return kaleidoscope::EventHandlerResult::OK;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void NumPad_::begin() {
onSetup();
Kaleidoscope.useLoopHook(legacyLoopHook);
}
void NumPad_::legacyLoopHook(bool is_post_clear) {
if (!is_post_clear)
return;
NumPad.afterEachCycle();
}
#endif
NumPad_ NumPad;

@ -4,17 +4,22 @@
#include "Kaleidoscope-Macros.h"
#include "LEDUtils.h"
class NumPad_ : public KaleidoscopePlugin {
class NumPad_ : public kaleidoscope::Plugin {
public:
NumPad_(void) {}
void begin(void) final;
static uint8_t numPadLayer;
private:
static void loopHook(const bool postClear);
kaleidoscope::EventHandlerResult onSetup(void);
kaleidoscope::EventHandlerResult afterEachCycle();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private:
static byte row, col;
static bool cleanupDone;
static bool originalNumLockState;

Loading…
Cancel
Save