1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include "animation_engine.h" #include "hal_delay.h" #include "os_malloc.h"
animation_frame_t fire_frames[] = { { { {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 100, 0}, {255, 100, 0}, {255, 100, 0}, {255, 100, 0}, {255, 100, 0}, {255, 0, 0}, {255, 0, 0}, {255, 100, 0}, {255, 150, 0}, {255, 150, 0}, {255, 150, 0}, {255, 150, 0}, {255, 150, 0}, {255, 100, 0}, {255, 0, 0}, {255, 150, 0}, {255, 200, 0}, {255, 200, 0}, {255, 200, 0}, {255, 200, 0}, {255, 200, 0}, {255, 150, 0}, {255, 0, 0}, {255, 200, 0}, {255, 255, 0}, {255, 255, 0}, {255, 255, 0}, {255, 255, 0}, {255, 255, 0}, {255, 200, 0}, {255, 0, 0}, {255, 255, 0}, {255, 255, 100}, {255, 255, 100}, {255, 255, 100}, {255, 255, 100}, {255, 255, 100}, {255, 255, 0}, {255, 0, 0}, {255, 255, 100}, {255, 255, 200}, {255, 255, 200}, {255, 255, 200}, {255, 255, 200}, {255, 255, 200}, {255, 255, 100}, {255, 0, 0}, {255, 255, 200}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 200}, {255, 0, 0} }, 50 }, };
animation_t animation_fire = {fire_frames, sizeof(fire_frames) / sizeof(fire_frames[0])};
animation_frame_t waterfall_frames[] = { { { {0, 0, 255}, {0, 0, 200}, {0, 0, 150}, {0, 0, 100}, {0, 0, 50}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255}, {0, 0, 200}, {0, 0, 150}, {0, 0, 100}, {0, 0, 50}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255}, {0, 0, 200}, {0, 0, 150}, {0, 0, 100}, {0, 0, 50}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255}, {0, 0, 200}, {0, 0, 150}, {0, 0, 100}, {0, 0, 50}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255}, {0, 0, 200}, {0, 0, 150}, {0, 0, 100}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255}, {0, 0, 200}, {0, 0, 150}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255}, {0, 0, 200}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 255} }, 100 }, };
animation_t animation_waterfall = {waterfall_frames, sizeof(waterfall_frames) / sizeof(waterfall_frames[0])};
void animation_play_animation(display_style_t animation_style) { animation_t *current_animation = NULL;
switch (animation_style) { case STYLE_RAINBOW: break; case STYLE_SOLID_COLOR: break; case STYLE_BLINK: break; case STYLE_SCROLL_LEFT: break; default: current_animation = &animation_fire; break; }
if (animation_style == STYLE_RAINBOW) { static uint8_t hue = 0; for (int i = 0; i < ws2812b_get_num_pixels(); i++) { rgb_color_t color; color.r = (uint8_t)(255 * ((hue + i * 4) % 256) / 255.0); color.g = (uint8_t)(255 * ((hue + i * 4 + 85) % 256) / 255.0); color.b = (uint8_t)(255 * ((hue + i * 4 + 170) % 256) / 255.0); ws2812b_set_pixel_color(i, color); } hue++; hal_delay_ms(50); } else if (current_animation != NULL) { for (int i = 0; i < current_animation->num_frames; i++) { for (int pixel_index = 0; pixel_index < ws2812b_get_num_pixels(); pixel_index++) { ws2812b_set_pixel_color(pixel_index, current_animation->frames[i].frame_data[pixel_index]); } ws2812b_show(); hal_delay_ms(current_animation->frames[i].duration_ms); } } }
|