New plugin: LEDEffect-BootAnimation

This replaces the former `bootAnimation()` method with a plugin that does
something very similar, without locking up the keyboard for the duration of the
animation, and scans the keymap instead of using hard-coded coordinates.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/386/head
Gergely Nagy 6 years ago
parent 267419e18e
commit 3b3c53bcc0
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -0,0 +1,45 @@
# Kaleidoscope-LEDEffect-BootAnimation
With this plugin enabled, the keyboard will play a little boot animation when
starting up (this animation does not inhibit typing, you can still use the
keyboard while the animation plays).
## Using the plugin
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-BootAnimation.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootAnimationEffect
LEDOff);
void setup() {
Kaleidoscope.setup();
}
```
## Plugin properties
The plugin provides the `BootAnimationEffect` object, with the following
properties:
### `.timeout`
> This property specifies the timeout (in milliseconds) each step of the
> animation is displayed.
>
> Defaults to `1000` ms, or one second.
### `.color`
> This property sets the color the animation is played with.
>
> The default is a red color.
## Dependencies
* [Kaleidoscope-LEDControl](LEDControl.md)

@ -0,0 +1,20 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootAnimation -- Small greeting at boot time
* Copyright (C) 2018 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "kaleidoscope/plugin/LEDEffect-BootAnimation.h"

@ -0,0 +1,91 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootAnimation -- Small greeting at boot time
* Copyright (C) 2018 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Kaleidoscope-LEDEffect-BootAnimation.h"
namespace kaleidoscope {
namespace plugin {
bool BootAnimationEffect::done_ = false;
cRGB BootAnimationEffect::color = CRGB(150, 0, 0);
uint16_t BootAnimationEffect::start_time_ = 0;
uint16_t BootAnimationEffect::timeout = 1000;
uint8_t BootAnimationEffect::current_index_ = 0;
const uint8_t BootAnimationEffect::greeting_[11] PROGMEM = {
Key_K.keyCode,
Key_E.keyCode,
Key_Y.keyCode,
Key_B.keyCode,
Key_O.keyCode,
Key_A.keyCode,
Key_R.keyCode,
Key_D.keyCode,
Key_Period.keyCode,
Key_I.keyCode,
Key_O.keyCode
};
EventHandlerResult BootAnimationEffect::onSetup() {
start_time_ = Kaleidoscope.millisAtCycleStart();
return EventHandlerResult::OK;
}
EventHandlerResult BootAnimationEffect::afterEachCycle() {
//If already done or we're not in a ready state, bail
if (done_) {
return EventHandlerResult::OK;
}
byte row = 255, col = 255;
for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) {
Key k = Layer.lookupOnActiveLayer(r, c);
Key g;
g.flags = 0;
g.keyCode = pgm_read_word(&greeting_[current_index_]);
if (k.raw == g.raw) {
row = r;
col = c;
break;
}
}
}
if ((Kaleidoscope.millisAtCycleStart() - start_time_) > timeout) {
current_index_++;
if (current_index_ == sizeof(greeting_))
done_ = true;
start_time_ = Kaleidoscope.millisAtCycleStart();
if (row != 255 && col != 255)
::LEDControl.refreshAt(row, col);
return EventHandlerResult::OK;
}
if (row != 255 && col != 255) {
::LEDControl.setCrgbAt(row, col, color);
}
return EventHandlerResult::OK;
}
}
}
kaleidoscope::plugin::BootAnimationEffect BootAnimationEffect;

@ -0,0 +1,45 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootAnimation -- Small greeting at boot time
* Copyright (C) 2018 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Kaleidoscope.h"
#include "Kaleidoscope-LEDControl.h"
namespace kaleidoscope {
namespace plugin {
class BootAnimationEffect : public kaleidoscope::Plugin {
public:
BootAnimationEffect(void) {}
static uint16_t timeout;
static cRGB color;
EventHandlerResult afterEachCycle();
EventHandlerResult onSetup();
private:
static const uint8_t greeting_[11];
static bool done_;
static uint16_t start_time_;
static uint8_t current_index_;
};
}
}
extern kaleidoscope::plugin::BootAnimationEffect BootAnimationEffect;
Loading…
Cancel
Save