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. > 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 ## Plugin helpers
### `STALKER(effect, params...)` ### `STALKER(effect, params...)`

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

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

Loading…
Cancel
Save