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

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

@ -22,11 +22,13 @@ is also possible to use a custom color instead of the white default.
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-ActiveModColor.h> #include <Kaleidoscope-LED-ActiveModColor.h>
void setup () { KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
Kaleidoscope.use(&ActiveModColorEffect); ActiveModColorEffect);
void setup () {
Kaleidoscope.setup (); Kaleidoscope.setup ();
ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff); ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff);

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers * Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,6 +17,7 @@
*/ */
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-ActiveModColor.h> #include <Kaleidoscope-LED-ActiveModColor.h>
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
@ -39,9 +40,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip), Key_skip),
}; };
void setup() { KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
Kaleidoscope.use(&ActiveModColorEffect); ActiveModColorEffect);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff); ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff);

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers * Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,14 +28,7 @@ cRGB ActiveModColorEffect::highlight_color = (cRGB) {
cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0x00, 0x00); cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0x00, 0x00);
void ActiveModColorEffect::begin(void) { EventHandlerResult ActiveModColorEffect::beforeReportingState() {
Kaleidoscope.useLoopHook(loopHook);
}
void ActiveModColorEffect::loopHook(bool is_post_clear) {
if (is_post_clear)
return;
for (byte r = 0; r < ROWS; r++) { for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) { for (byte c = 0; c < COLS; c++) {
Key k = Layer.lookupOnActiveLayer(r, c); Key k = Layer.lookupOnActiveLayer(r, c);
@ -64,8 +57,25 @@ void ActiveModColorEffect::loopHook(bool is_post_clear) {
} }
} }
} }
return EventHandlerResult::OK;
}
// Legacy API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void ActiveModColorEffect::begin() {
Kaleidoscope.useLoopHook(legacyLoopHook);
} }
void ActiveModColorEffect::legacyLoopHook(bool is_post_clear) {
if (is_post_clear)
return;
::ActiveModColorEffect.beforeReportingState();
}
#endif
} }
kaleidoscope::ActiveModColorEffect ActiveModColorEffect; kaleidoscope::ActiveModColorEffect ActiveModColorEffect;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers * Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,17 +22,20 @@
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace kaleidoscope { namespace kaleidoscope {
class ActiveModColorEffect : public KaleidoscopePlugin { class ActiveModColorEffect : public kaleidoscope::Plugin {
public: public:
ActiveModColorEffect(void) {} ActiveModColorEffect(void) {}
void begin(void) final;
static cRGB highlight_color; static cRGB highlight_color;
static cRGB sticky_color; static cRGB sticky_color;
private: EventHandlerResult beforeReportingState();
static void loopHook(bool is_post_clear);
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
}; };
} }

Loading…
Cancel
Save