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

@ -4,17 +4,22 @@
#include "Kaleidoscope-Macros.h" #include "Kaleidoscope-Macros.h"
#include "LEDUtils.h" #include "LEDUtils.h"
class NumPad_ : public KaleidoscopePlugin { class NumPad_ : public kaleidoscope::Plugin {
public: public:
NumPad_(void) {} NumPad_(void) {}
void begin(void) final;
static uint8_t numPadLayer; static uint8_t numPadLayer;
private: kaleidoscope::EventHandlerResult onSetup(void);
static void loopHook(const bool postClear); 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 byte row, col;
static bool cleanupDone; static bool cleanupDone;
static bool originalNumLockState; static bool originalNumLockState;

Loading…
Cancel
Save