Add shake emotion with persistent state and calibration
Introduces a new shake emotion animation with a shake-stop transition, including embedded Lottie animation data and a state machine for emotion transitions. Adds a non-volatile storage (NVS) driver for persistent state management, including first-boot detection, boot count, and IMU calibration storage. Updates emotion manager and related headers to support new shake emotion states, and integrates new UI components for calibration and loading animations.
This commit is contained in:
99
main/ui/loading_anim.c
Normal file
99
main/ui/loading_anim.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @file loading_anim.c
|
||||
* @brief Minimalist loading animation implementation
|
||||
*
|
||||
* Uses LVGL animators to create a "breathing" or "bouncing" 3-dot effect.
|
||||
*/
|
||||
|
||||
#include "ui/loading_anim.h"
|
||||
#include "esp_log.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
static const char *TAG = "loading_anim";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Private State
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static lv_obj_t *loadingScreen = NULL;
|
||||
static lv_obj_t *dots[3];
|
||||
static lv_anim_t anims[3];
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Animation Callbacks
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void anim_y_cb(void *var, int32_t v) {
|
||||
lv_obj_set_y((lv_obj_t *)var, v);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Public API Implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void loadingAnimStart(void) {
|
||||
if (loadingScreen != NULL)
|
||||
return;
|
||||
|
||||
ESP_LOGI(TAG, "Starting loading animation");
|
||||
|
||||
// Create opaque black screen
|
||||
loadingScreen = lv_obj_create(NULL);
|
||||
lv_obj_set_style_bg_color(loadingScreen, lv_color_black(), 0);
|
||||
lv_obj_set_style_bg_opa(loadingScreen, LV_OPA_COVER, 0);
|
||||
|
||||
// Create 3 dots
|
||||
// Center is (0,0) for alignment
|
||||
const int32_t dot_size = 20;
|
||||
const int32_t dot_gap = 40;
|
||||
const int32_t base_y = 0;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
dots[i] = lv_obj_create(loadingScreen);
|
||||
lv_obj_set_size(dots[i], dot_size, dot_size);
|
||||
lv_obj_set_style_radius(dots[i], LV_RADIUS_CIRCLE, 0);
|
||||
lv_obj_set_style_bg_color(dots[i], lv_color_white(), 0);
|
||||
lv_obj_set_style_border_width(dots[i], 0, 0);
|
||||
|
||||
// Position centered horizontally with gaps
|
||||
lv_obj_align(dots[i], LV_ALIGN_CENTER, (i - 1) * dot_gap, base_y);
|
||||
|
||||
// Setup bounce animation
|
||||
lv_anim_init(&anims[i]);
|
||||
lv_anim_set_var(&anims[i], dots[i]);
|
||||
lv_anim_set_values(&anims[i], base_y, base_y - 30);
|
||||
lv_anim_set_time(&anims[i], 600);
|
||||
lv_anim_set_playback_time(&anims[i], 600);
|
||||
lv_anim_set_repeat_count(&anims[i], LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_set_path_cb(&anims[i], lv_anim_path_ease_in_out);
|
||||
lv_anim_set_exec_cb(&anims[i], anim_y_cb);
|
||||
|
||||
// Stagger the animations
|
||||
lv_anim_set_delay(&anims[i], i * 200);
|
||||
|
||||
lv_anim_start(&anims[i]);
|
||||
}
|
||||
|
||||
lv_scr_load(loadingScreen);
|
||||
}
|
||||
|
||||
void loadingAnimStop(void) {
|
||||
if (loadingScreen == NULL)
|
||||
return;
|
||||
|
||||
ESP_LOGI(TAG, "Stopping loading animation");
|
||||
|
||||
// LVGL requires a valid active screen at all times. Before deleting the
|
||||
// loading screen, we must create and load a temporary blank screen.
|
||||
// The next UI component (splash screen) will replace this.
|
||||
lv_obj_t *blankScreen = lv_obj_create(NULL);
|
||||
if (blankScreen != NULL) {
|
||||
lv_obj_set_style_bg_color(blankScreen, lv_color_black(), 0);
|
||||
lv_obj_set_style_bg_opa(blankScreen, LV_OPA_COVER, 0);
|
||||
lv_scr_load(blankScreen);
|
||||
}
|
||||
|
||||
// Now safe to delete the loading screen since we have a new active screen
|
||||
lv_obj_del(loadingScreen);
|
||||
loadingScreen = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user