diff --git a/animation/animation.c b/animation/animation.c index 60a9c3e..d4d4562 100644 --- a/animation/animation.c +++ b/animation/animation.c @@ -39,7 +39,7 @@ int time_line_next(time_line_t *self) { } } else { while (error < 0) { - self->y -= self->inc; + self->y += self->inc; error += 2 * self->dt; } } diff --git a/animation/animation.h b/animation/animation.h index 0bb3385..0833738 100644 --- a/animation/animation.h +++ b/animation/animation.h @@ -1,6 +1,14 @@ #ifndef __ANIMATION_H__ #define __ANIMATION_H__ +#ifdef __AVR__ +#include +#else + +typedef int uint8_t; + +#endif + // line_t provides a simplified implementation of Bresenham's line drawing // technique. At this time, it assumes a transition of x = 0 -> 60, and a dy // between -59 and 59. I am not sure I understand Bresenham's algorithm yet, @@ -23,6 +31,6 @@ time_line_t time_line_new(int, int, int, int); int time_line_next(time_line_t *); // Diagnostic printout of the current state of line_t. -// void line_print(line_t *line); +void time_line_print(time_line_t *); #endif diff --git a/lantern/main.c b/lantern/main.c index 072e06e..01ff068 100644 --- a/lantern/main.c +++ b/lantern/main.c @@ -18,7 +18,9 @@ You should have received a copy of the GNU General Public License along with thi #include #include #include +#include +#define ANIMATION_FRAMES 5 #define FPS 15 #define FRAME_DELAY_MS 1000 / FPS // #define FRAME_DELAY_MS 1000 @@ -42,16 +44,18 @@ uint8_t bound_uint8(int value, uint8_t min, uint8_t max) { } } -uint8_t random_step(uint8_t value, uint8_t min, uint8_t max, rng_t *rng) { - int8_t step = (rng_sample(rng) % 20) - 10; +uint8_t random_step(display_t *display, uint8_t value, uint8_t min, uint8_t max, rng_t *rng) { + // int8_t step = (rng_sample(rng) % 40) - 20; + int8_t step = (rand() % 40) - 20; int new_value = value + step; - if (new_value > max) { - return max; - } else if (new_value < min) { - return min; - } else { - return new_value; - } + + // char msg[20]; + // snprintf(msg, 20, "[%x] %x -> %x", step, value, new_value); + // display_clear(display); + // display_write_message(display, msg); + // _delay_ms(1000); + + return bound_uint8(new_value, min, max); } typedef struct { @@ -108,6 +112,7 @@ typedef struct { animation_t animations[LIGHT_COUNT]; } lantern_t; +void display_lantern(display_t *display, lantern_t *lantern); lantern_t lantern_new(sk9822_t lights) { sk9822_init(&lights); @@ -128,38 +133,38 @@ void lantern_start_test(lantern_t *self) { 255, 0, 0, - 15); + ANIMATION_FRAMES); animation_begin( &self->animations[1], 0, 255, 0, - 15); + ANIMATION_FRAMES); animation_begin( &self->animations[2], 0, 0, 255, - 15); + ANIMATION_FRAMES); } -void lantern_start_normal(lantern_t *self, rng_t *rng) { +void lantern_start_normal(display_t *display, 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), + random_step(display, self->animations[0].color.r, 180, 255, rng), + random_step(display, self->animations[0].color.g, 20, 50, rng), 0, FPS); 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), + random_step(display, self->animations[1].color.r, 160, 230, rng), + random_step(display, self->animations[1].color.g, 10, 30, rng), 0, FPS); 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), + random_step(display, self->animations[2].color.r, 140, 170, rng), + random_step(display, self->animations[2].color.g, 0, 10, rng), 0, FPS); } @@ -168,14 +173,15 @@ void lantern_set_mode(lantern_t *self, color_scheme_e scheme) { self->color_scheme = scheme; } -void lantern_step(lantern_t *self, 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])) { + // display_lantern(display, self); switch (self->color_scheme) { case test: lantern_start_test(self); break; case normal: - lantern_start_normal(self, rng); + lantern_start_normal(display, self, rng); break; case creepy: break; @@ -253,21 +259,17 @@ int main(void) { rng_t rng = rng_new(15); - display_clear(&display); - display_write_message(&display, "ready"); + // display_clear(&display); + // display_write_message(&display, "ready"); - _delay_ms(5000); + // _delay_ms(5000); - display_lantern(&display, &lantern); - _delay_ms(1000); - - lantern_step(&lantern, &rng, colors); + lantern_step(&lantern, &display, &rng, colors); sk9822_send(&lights, colors, LIGHT_COUNT); while(1) { - lantern_step(&lantern, &rng, colors); + lantern_step(&lantern, &display, &rng, colors); sk9822_send(&lights, colors, LIGHT_COUNT); - display_lantern(&display, &lantern); _delay_ms(FRAME_DELAY_MS); }