firmware: Add repeating animations

This commit is contained in:
Jack O'Sullivan 2024-12-14 13:18:17 +00:00
parent 514198d136
commit 4d1074e60c
2 changed files with 34 additions and 1 deletions

View File

@ -14,6 +14,7 @@ static lv_style_t s_hero, s_subtitle;
static lv_obj_t *o_container = NULL; static lv_obj_t *o_container = NULL;
static lv_anim_timeline_t *at_active = NULL; static lv_anim_timeline_t *at_active = NULL;
static lv_anim_timeline_t *at_active_rep = NULL;
static lv_obj_t *o_active = NULL; static lv_obj_t *o_active = NULL;
static bool state_ready = true; static bool state_ready = true;
@ -51,6 +52,10 @@ static void setup_next_state() {
lv_anim_timeline_delete(at_active); lv_anim_timeline_delete(at_active);
at_active = NULL; at_active = NULL;
} }
if (at_active_rep) {
lv_anim_timeline_delete(at_active_rep);
at_active_rep = NULL;
}
if (o_active) { if (o_active) {
lv_obj_delete(o_active); lv_obj_delete(o_active);
o_active = NULL; o_active = NULL;
@ -63,6 +68,8 @@ static void setup_next_state() {
lv_obj_set_size(o_active, lv_pct(100), lv_pct(100)); lv_obj_set_size(o_active, lv_pct(100), lv_pct(100));
at_active = lv_anim_timeline_create(); at_active = lv_anim_timeline_create();
at_active_rep = lv_anim_timeline_create();
lv_anim_timeline_set_repeat_count(at_active_rep, LV_ANIM_REPEAT_INFINITE);
} }
bool val_ui_state_ready() { bool val_ui_state_ready() {
@ -70,6 +77,7 @@ bool val_ui_state_ready() {
} }
static void anim_state_ready_cb(lv_anim_t *anim) { static void anim_state_ready_cb(lv_anim_t *anim) {
lv_anim_timeline_start(at_active_rep);
state_ready = true; state_ready = true;
} }
static void anim_x_cb(void *var, int32_t v) { static void anim_x_cb(void *var, int32_t v) {
@ -194,6 +202,32 @@ void val_ui_menu(bool was_idle) {
lv_anim_timeline_add(at_active, 0, &a_title); lv_anim_timeline_add(at_active, 0, &a_title);
lv_anim_timeline_add(at_active, 0, &a_sub); lv_anim_timeline_add(at_active, 0, &a_sub);
// Repeating loop swing back and forth
lv_anim_t a_title_swing;
lv_anim_init(&a_title_swing);
lv_anim_set_early_apply(&a_title_swing, false);
lv_anim_set_var(&a_title_swing, l_main);
lv_anim_set_exec_cb(&a_title_swing, anim_x_cb);
// Left
lv_anim_set_path_cb(&a_title_swing, lv_anim_path_ease_out);
lv_anim_set_values(&a_title_swing, 0, -10);
lv_anim_set_duration(&a_title_swing, 500);
lv_anim_timeline_add(at_active_rep, 0, &a_title_swing);
// Left to right
lv_anim_set_path_cb(&a_title_swing, lv_anim_path_ease_in_out);
lv_anim_set_values(&a_title_swing, -10, 10);
lv_anim_set_duration(&a_title_swing, 1000);
lv_anim_timeline_add(at_active_rep, 500, &a_title_swing);
// Right to centre
lv_anim_set_path_cb(&a_title_swing, lv_anim_path_ease_in);
lv_anim_set_values(&a_title_swing, 10, 0);
lv_anim_set_duration(&a_title_swing, 500);
lv_anim_timeline_add(at_active_rep, 1500, &a_title_swing);
lv_anim_timeline_start(at_active); lv_anim_timeline_start(at_active);
} }

View File

@ -21,7 +21,6 @@ CONFIG_ESP_WIFI_DPP_SUPPORT=y
CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_HZ=1000
CONFIG_TINYUSB_DEBUG_LEVEL=0 CONFIG_TINYUSB_DEBUG_LEVEL=0
CONFIG_TINYUSB_HID_COUNT=1 CONFIG_TINYUSB_HID_COUNT=1
CONFIG_LV_DEF_REFR_PERIOD=24
CONFIG_LV_USE_LOG=y CONFIG_LV_USE_LOG=y
CONFIG_LV_LOG_PRINTF=y CONFIG_LV_LOG_PRINTF=y
CONFIG_LV_FONT_MONTSERRAT_24=y CONFIG_LV_FONT_MONTSERRAT_24=y