Add a timer, and expose stepLength

With the recent speedup of the scan cycle, we need some delays for the animation
to look nice.

Fixes #2.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 6497d3ae8f
commit 8aa753fe23

@ -41,6 +41,15 @@ method:
>
> It is recommended to use the `STALKER` macro to declare the effect itself.
### `.stepLength`
> The length - in milliseconds - of each step of the animation. An animation
> lasts 256 steps.
>
> Not a method itself, but a changeable value.
>
> Defaults to 50.
## Plugin helpers
### `STALKER(effect, params...)`

@ -22,6 +22,8 @@ namespace Akela {
namespace LEDEffects {
uint8_t StalkerEffect::map[ROWS][COLS];
StalkerEffect::ColorComputer *StalkerEffect::colorComputer;
uint16_t StalkerEffect::stepLength = 50;
uint32_t StalkerEffect::stepStartTime;
StalkerEffect::StalkerEffect (void) {
}
@ -35,6 +37,7 @@ namespace Akela {
StalkerEffect::begin (void) {
event_handler_hook_use (eventHandlerHook);
loop_hook_use (loopHook);
stepStartTime = millis ();
}
Key
@ -42,8 +45,9 @@ namespace Akela {
if (row >= ROWS || col >= COLS)
return mappedKey;
if (key_is_pressed (keyState))
if (key_is_pressed (keyState)) {
map[row][col] = 0xff;
}
return mappedKey;
}
@ -56,6 +60,8 @@ namespace Akela {
if (!colorComputer)
return;
bool timeOut = (millis () - stepStartTime) >= stepLength;
for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) {
if (map[r][c])
@ -63,19 +69,24 @@ namespace Akela {
bool wasZero = (map[r][c] == 0);
if (map[r][c] >= 0xf0)
map[r][c]--;
else if (map[r][c] >= 0x40)
map[r][c] -= 16;
else if (map[r][c] >= 32)
map[r][c] -= 32;
else
map[r][c] = 0;
if (timeOut) {
if (map[r][c] >= 0xf0)
map[r][c]--;
else if (map[r][c] >= 0x40)
map[r][c] -= 16;
else if (map[r][c] >= 32)
map[r][c] -= 32;
else
map[r][c] = 0;
}
if (!wasZero && !map[r][c])
LEDControl.led_set_crgb_at (r, c, (cRGB){0, 0, 0});
}
}
if (timeOut)
stepStartTime = millis ();
}
namespace Stalker {

@ -34,8 +34,10 @@ namespace Akela {
virtual void begin (void) final;
static void configure (ColorComputer *colorComputer);
static uint16_t stepLength;
private:
static uint32_t stepStartTime;
static ColorComputer *colorComputer;
static uint8_t map[ROWS][COLS];

Loading…
Cancel
Save