Set up different animation speeds per light

This commit is contained in:
Savanni D'Gerinel 2022-07-18 22:58:14 -04:00
parent ca0847c73d
commit aefb2184bf
1 changed files with 46 additions and 42 deletions

View File

@ -28,7 +28,6 @@ You should have received a copy of the GNU General Public License along with thi
#define PULSE_ON_COUNT 5 #define PULSE_ON_COUNT 5
typedef enum { typedef enum {
test,
normal, normal,
spooky, spooky,
eerie, eerie,
@ -121,48 +120,36 @@ lantern_t lantern_new(sk9822_t lights) {
}; };
} }
void lantern_start_test(lantern_t *self) { void lantern_start_normal(lantern_t *self, rng_t *rng, int light_idx) {
animation_begin( switch (light_idx) {
&self->animations[0], case 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( animation_begin(
&self->animations[0], &self->animations[0],
random_step(self->animations[0].color.r, 180, 255, rng), random_step(self->animations[0].color.r, 180, 255, rng),
random_step(self->animations[0].color.g, 20, 50, rng), random_step(self->animations[0].color.g, 20, 50, rng),
0, 0,
5); 5);
break;
case 1:
animation_begin( animation_begin(
&self->animations[1], &self->animations[1],
random_step(self->animations[1].color.r, 160, 230, rng), random_step(self->animations[1].color.r, 160, 230, rng),
random_step(self->animations[1].color.g, 10, 30, rng), random_step(self->animations[1].color.g, 10, 30, rng),
0, 0,
5); 15);
break;
case 2:
animation_begin( animation_begin(
&self->animations[2], &self->animations[2],
random_step(self->animations[2].color.r, 140, 170, rng), random_step(self->animations[2].color.r, 140, 170, rng),
random_step(self->animations[2].color.g, 0, 10, rng), random_step(self->animations[2].color.g, 0, 10, rng),
0, 0,
5); 30);
break;
}
} }
/*
void lantern_start_spooky(lantern_t *self, rng_t *rng) { void lantern_start_spooky(lantern_t *self, rng_t *rng) {
animation_begin( animation_begin(
&self->animations[0], &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), random_step(self->animations[2].color.g, 20, 40, rng),
15); 15);
} }
*/
void lantern_set_mode(lantern_t *self, color_scheme_e scheme) { void lantern_set_mode(lantern_t *self, color_scheme_e scheme) {
self->color_scheme = scheme; self->color_scheme = scheme;
} }
void lantern_step(lantern_t *self, display_t *display, rng_t *rng, rgb_t colors[LIGHT_COUNT]) { void lantern_step(lantern_t *self, display_t *display, rng_t *rng, rgb_t colors[LIGHT_COUNT]) {
/*
if (!animation_running(&self->animations[0])) { if (!animation_running(&self->animations[0])) {
// display_lantern(display, self); // display_lantern(display, self);
switch (self->color_scheme) { switch (self->color_scheme) {
@ -229,8 +218,23 @@ void lantern_step(lantern_t *self, display_t *display, rng_t *rng, rgb_t colors[
break; break;
} }
} }
*/
for (int i = 0; i < LIGHT_COUNT; i++) { 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]); animation_step(&self->animations[i]);
colors[i] = self->animations[i].color; colors[i] = self->animations[i].color;
} }
@ -301,7 +305,7 @@ int main(void) {
rgb_t colors[LIGHT_COUNT]; rgb_t colors[LIGHT_COUNT];
lantern_t lantern = lantern_new(lights); lantern_t lantern = lantern_new(lights);
lantern_set_mode(&lantern, eerie); lantern_set_mode(&lantern, normal);
rng_t rng = rng_new(15); rng_t rng = rng_new(15);