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

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

@ -18,11 +18,14 @@ To use the plugin, include the header, and tell `Kaleidoscope` to use the plugin
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() {
Kaleidoscope.setup();
}
```
@ -32,55 +35,69 @@ You may also set optional parameters.
### Specify by search key
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
Kaleidoscope.setup();
BootGreetingEffect.search_key = Key_M;
Kaleidoscope.setup();
}
```
### Specify by position
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
Kaleidoscope.setup();
//Butterfly key
BootGreetingEffect.key_col = 7;
BootGreetingEffect.key_row = 3;
Kaleidoscope.setup();
}
```
### Specify longer timeout
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
Kaleidoscope.setup();
//Butterfly key
BootGreetingEffect.timeout = 15000;
Kaleidoscope.setup();
}
```
### Specify different color
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
Kaleidoscope.setup();
//Butterfly key
BootGreetingEffect.hue = 90;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootGreeting -- Small greeting at boot time
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* 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
@ -36,11 +36,6 @@ BootGreetingEffect::BootGreetingEffect(byte pos_row, byte pos_col) {
key_col = pos_col;
}
void BootGreetingEffect::begin(void) {
//Use the loop hook
Kaleidoscope.useLoopHook(loopHook);
}
void BootGreetingEffect::findLed(void) {
// Find the LED key.
for (uint8_t r = 0; r < ROWS; r++) {
@ -63,10 +58,10 @@ void BootGreetingEffect::findLed(void) {
done_ = true;
}
void BootGreetingEffect::loopHook(const bool post_clear) {
EventHandlerResult BootGreetingEffect::afterEachCycle() {
//If already done or we're not in a ready state, bail
if (!post_clear || done_) {
return;
if (done_) {
return EventHandlerResult::OK;
}
//If the start time isn't set, set the start time and
@ -75,19 +70,35 @@ void BootGreetingEffect::loopHook(const bool post_clear) {
start_time = millis();
findLed();
//the first time, don't do anything.
return;
return EventHandlerResult::OK;
}
//Only run for 'timeout' milliseconds
if ((millis() - start_time) > timeout) {
done_ = true;
::LEDControl.refreshAt(row_, col_);
return;
return EventHandlerResult::OK;
}
cRGB color = breath_compute(hue);
::LEDControl.setCrgbAt(row_, col_, color);
return EventHandlerResult::OK;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void BootGreetingEffect::begin() {
Kaleidoscope.useLoopHook(legacyLoopHook);
}
void BootGreetingEffect::legacyLoopHook(bool is_post_clear) {
if (!is_post_clear)
return;
::BootGreetingEffect.afterEachCycle();
}
#endif
}
kaleidoscope::BootGreetingEffect BootGreetingEffect;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootGreeting -- Small greeting at boot time
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* 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
@ -21,20 +21,26 @@
#include "Kaleidoscope-LEDControl.h"
namespace kaleidoscope {
class BootGreetingEffect : public KaleidoscopePlugin {
class BootGreetingEffect : public kaleidoscope::Plugin {
public:
BootGreetingEffect(void) {}
BootGreetingEffect(byte, byte);
void begin(void) final;
static byte key_row;
static byte key_col;
static Key search_key;
static uint8_t hue;
static uint16_t timeout;
EventHandlerResult afterEachCycle();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private:
static void loopHook(const bool post_clear);
static void findLed(void);
static bool done_;
static byte row_;

Loading…
Cancel
Save