crawl for 300ms

This commit is contained in:
Priec
2025-11-14 14:24:34 +01:00
parent b147d92423
commit 38b8bb0657

View File

@@ -75,6 +75,8 @@ static bool update_animation(Timer &anim_timer, int &shift, int speed) {
void render_loop(int speed) { void render_loop(int speed) {
Timer msg_timer; Timer msg_timer;
Timer anim_timer; Timer anim_timer;
Timer crawl_timer;
msg_timer.start(); msg_timer.start();
anim_timer.start(); anim_timer.start();
@@ -82,6 +84,10 @@ void render_loop(int speed) {
const char *bg_file = "background_dark_inverted.txt"; const char *bg_file = "background_dark_inverted.txt";
bool need_redraw = false; bool need_redraw = false;
bool crawling = false; // are we in 1s crawl state?
bool crawl_timer_started = false;
const auto CRAWL_DURATION = 300ms;
while (true) { while (true) {
need_redraw = false; need_redraw = false;
@@ -89,17 +95,31 @@ void render_loop(int speed) {
if (uart_state == 1) if (uart_state == 1)
need_redraw = true; need_redraw = true;
bool triggered = (uart_state == 2); if (uart_state == 2) {
// start crawl frame for 1 second
crawling = true;
crawl_timer.reset();
crawl_timer.start();
crawl_timer_started = true;
}
// stop crawling after 1 second
if (crawling && crawl_timer_started &&
crawl_timer.elapsed_time() >= CRAWL_DURATION) {
crawling = false;
crawl_timer.stop();
crawl_timer_started = false;
}
if (update_animation(anim_timer, shift, speed)) if (update_animation(anim_timer, shift, speed))
need_redraw = true; need_redraw = true;
if (need_redraw || triggered) { if (need_redraw || crawling) {
draw_mask(bg_file, shift, message_active ? message : nullptr); draw_mask(bg_file, shift, message_active ? message : nullptr);
static int frame = 0; static int frame = 0;
if (triggered) { if (crawling) {
// Display triggered frame once // Display crawl frame during 1s crawl state
draw_player(18, 13, 2); draw_player(18, 13, 2);
} else { } else {
draw_player(18, 13, frame); draw_player(18, 13, frame);