diff --git a/config.h b/config.h index a076dec..796ef6f 100644 --- a/config.h +++ b/config.h @@ -11,6 +11,8 @@ #define MAX_MULTI_COLOR_TEXT_NODES_COUNT $ #define MAX_TEXT_NODES_COUNT 4 #define MAX_IMAGES_SAVED 2 +#define MAX_ANIMATION_FRAME_COUNT 32 +#define MAX_ANIMATIONS_COUNT 2 #define SMALL_TEXT_HEIGHT 7 #define SMALL_TEXT_WIDTH 5 diff --git a/ledy.ino b/ledy.ino index 7828a1c..23c8cd4 100644 --- a/ledy.ino +++ b/ledy.ino @@ -29,6 +29,9 @@ Image saved_images[MAX_IMAGES_SAVED] = { {},{} }; +const RGB animation_data[MAX_ANIMATIONS_COUNT][MAX_ANIMATION_FRAME_COUNT][PANEL_PIXEL_COUNT][DISPLAY_MAX_X + 1] = {}; +Animation animations[MAX_ANIMATIONS_COUNT]; + short getTextNodeY2(TextNode *node) { @@ -338,6 +341,62 @@ void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short po } } +void displayAnimationFrame(unsigned char animation_index) +{ + unsigned short frame = animations[animation_index].current_frame; + + for (unsigned char y = 0; y < PANEL_PIXEL_COUNT; y++) + { + for (unsigned char x = 0; x <= DISPLAY_MAX_X; x++) + { + const RGB& px = animation_data[animation_index][frame][y][x]; + setPixel(x, y, pixels.Color(px.r * brightness / 100, px.g * brightness / 100, px.b * brightness / 100)); + } + } +} + +void tickAnimations() +{ + for (unsigned char i = 0; i < MAX_ANIMATIONS_COUNT; i++) + { + if (!animations[i].is_playing) continue; + + animations[i].frame_progress++; + if (animations[i].frame_progress > animations[i].frame_delay) + { + animations[i].frame_progress = 0; + animations[i].current_frame++; + + if (animations[i].current_frame >= animations[i].frame_count) + { + if (animations[i].is_looping) + { + animations[i].current_frame = 0; + } + else + { + animations[i].current_frame = animations[i].frame_count - 1; + animations[i].is_playing = false; + } + } + } + } +} + +void playAnimation(unsigned char index, unsigned char frame_delay, bool loop) +{ + animations[index].current_frame = 0; + animations[index].frame_progress = 0; + animations[index].frame_delay = frame_delay; + animations[index].is_playing = true; + animations[index].is_looping = loop; +} + +void stopAnimation(unsigned char index) +{ + animations[index].is_playing = false; +} + void handleDisappearTimers() { for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++) @@ -429,7 +488,7 @@ void loop() TextNode* node = nullptr; if (bottom_text_state == 0) { - node = addNewTextNode("Technik informatyk", + node = addNewTextNode("Technik informatyk + ai, robotyka", pixels.Color(0, 0, 50), // blue (dimmed) false, DISPLAY_MAX_X, 9, 1, true, true, -1, false); } diff --git a/prototypes.h b/prototypes.h index c82b37e..b636909 100644 --- a/prototypes.h +++ b/prototypes.h @@ -10,7 +10,12 @@ extern TextNode text_nodes[MAX_TEXT_NODES_COUNT]; extern MultiColorTextNode multi_color_text_node[MAX_TEXT_NODES_COUNT]; extern Cursor cursor; extern unsigned char brightness; +extern Animation animations[MAX_ANIMATIONS_COUNT]; +void displayAnimationFrame(unsigned char animation_index); +void tickAnimations(); +void playAnimation(unsigned char index, unsigned char frame_delay, bool loop); +void stopAnimation(unsigned char index); void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short pos_y, unsigned char brightness = 100); void setPixel(short x, short y, uint32_t color); diff --git a/structs.h b/structs.h index 597137f..93fd79c 100644 --- a/structs.h +++ b/structs.h @@ -92,5 +92,14 @@ struct Image unsigned short height; }; +struct Animation { + unsigned short frame_count; + unsigned short current_frame; + unsigned char frame_delay; + unsigned char frame_progress; + bool is_playing; + bool is_looping; +}; + #endif // STRUCTS_H