From aefb2184bf8ac5d2ce8cafabd1f190cfa4a4dded Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 18 Jul 2022 22:58:14 -0400 Subject: [PATCH] Set up different animation speeds per light --- lantern/main.c | 88 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/lantern/main.c b/lantern/main.c index ac07def..8ebab8d 100644 --- a/lantern/main.c +++ b/lantern/main.c @@ -28,7 +28,6 @@ You should have received a copy of the GNU General Public License along with thi #define PULSE_ON_COUNT 5 typedef enum { - test, normal, spooky, eerie, @@ -121,48 +120,36 @@ lantern_t lantern_new(sk9822_t lights) { }; } -void lantern_start_test(lantern_t *self) { - animation_begin( - &self->animations[0], - 255, - 0, - 0, - 5); - animation_begin( - &self->animations[1], - 0, - 255, - 0, - 5); - animation_begin( - &self->animations[2], - 0, - 0, - 255, - 5); -} - -void lantern_start_normal(lantern_t *self, rng_t *rng) { - animation_begin( - &self->animations[0], - random_step(self->animations[0].color.r, 180, 255, rng), - random_step(self->animations[0].color.g, 20, 50, rng), - 0, - 5); - animation_begin( - &self->animations[1], - random_step(self->animations[1].color.r, 160, 230, rng), - random_step(self->animations[1].color.g, 10, 30, rng), - 0, - 5); - animation_begin( - &self->animations[2], - random_step(self->animations[2].color.r, 140, 170, rng), - random_step(self->animations[2].color.g, 0, 10, rng), - 0, - 5); +void lantern_start_normal(lantern_t *self, rng_t *rng, int light_idx) { + switch (light_idx) { + case 0: + animation_begin( + &self->animations[0], + random_step(self->animations[0].color.r, 180, 255, rng), + random_step(self->animations[0].color.g, 20, 50, rng), + 0, + 5); + break; + case 1: + animation_begin( + &self->animations[1], + random_step(self->animations[1].color.r, 160, 230, rng), + random_step(self->animations[1].color.g, 10, 30, rng), + 0, + 15); + break; + case 2: + animation_begin( + &self->animations[2], + random_step(self->animations[2].color.r, 140, 170, rng), + random_step(self->animations[2].color.g, 0, 10, rng), + 0, + 30); + break; + } } +/* void lantern_start_spooky(lantern_t *self, rng_t *rng) { animation_begin( &self->animations[0], @@ -204,12 +191,14 @@ void lantern_start_eerie(lantern_t *self, rng_t *rng) { random_step(self->animations[2].color.g, 20, 40, rng), 15); } +*/ void lantern_set_mode(lantern_t *self, color_scheme_e scheme) { self->color_scheme = scheme; } void lantern_step(lantern_t *self, display_t *display, rng_t *rng, rgb_t colors[LIGHT_COUNT]) { + /* if (!animation_running(&self->animations[0])) { // display_lantern(display, self); switch (self->color_scheme) { @@ -229,8 +218,23 @@ void lantern_step(lantern_t *self, display_t *display, rng_t *rng, rgb_t colors[ break; } } + */ for (int i = 0; i < LIGHT_COUNT; i++) { + if (!animation_running(&self->animations[i])) { + switch (self->color_scheme) { + case normal: + lantern_start_normal(self, rng, i); + break; + case spooky: + break; + case eerie: + break; + case flash: + break; + } + } + animation_step(&self->animations[i]); colors[i] = self->animations[i].color; } @@ -301,7 +305,7 @@ int main(void) { rgb_t colors[LIGHT_COUNT]; lantern_t lantern = lantern_new(lights); - lantern_set_mode(&lantern, eerie); + lantern_set_mode(&lantern, normal); rng_t rng = rng_new(15);