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:
@@ -3,18 +3,24 @@ idf_component_register(
|
||||
"main.c"
|
||||
"drivers/display_driver.c"
|
||||
"drivers/touch_driver.c"
|
||||
"drivers/nvs_driver.c"
|
||||
"ui/splash_screen.c"
|
||||
"ui/assets/splash_screen/logo_iro.c"
|
||||
"ui/calibration_screen.c"
|
||||
"ui/loading_anim.c"
|
||||
"ui/lottie_player.c"
|
||||
"ui/assets/splash_screen/logo_iro.c"
|
||||
"ui/assets/fonts/Geist.c"
|
||||
"sensors/shake_detector.cpp"
|
||||
"emotion-engine/emotion_manager.c"
|
||||
"emotion-engine/blink/blink_emotion.c"
|
||||
"emotion-engine/shake/shake_emotion.c"
|
||||
INCLUDE_DIRS
|
||||
"."
|
||||
"config"
|
||||
REQUIRES
|
||||
SensorLib
|
||||
json
|
||||
nvs_flash
|
||||
)
|
||||
|
||||
set_source_files_properties(
|
||||
|
||||
184
main/drivers/nvs_driver.c
Normal file
184
main/drivers/nvs_driver.c
Normal file
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* @file nvs_driver.c
|
||||
* @brief Non-Volatile Storage implementation
|
||||
*
|
||||
* Implements persistent state management using ESP-IDF NVS API.
|
||||
*/
|
||||
|
||||
#include "drivers/nvs_driver.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "nvs_driver";
|
||||
static const char *NAMESPACE = "storage";
|
||||
static const char *KEY_PROVISIONED = "is_prov";
|
||||
static const char *KEY_BOOT_COUNT = "boots";
|
||||
|
||||
bool nvsDriverInit(void) {
|
||||
ESP_LOGI(TAG, "Initializing NVS");
|
||||
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
// NVS partition was truncated and needs to be erased
|
||||
// Retry nvs_flash_init
|
||||
ESP_LOGW(TAG, "Erasing NVS partition due to corruption/version mismatch");
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "NVS Init failed: %s", esp_err_to_name(ret));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nvsDriverIsFirstBoot(void) {
|
||||
nvs_handle_t handle;
|
||||
esp_err_t err = nvs_open(NAMESPACE, NVS_READONLY, &handle);
|
||||
if (err != ESP_OK) {
|
||||
// If namespace doesn't exist, it's definitely first boot
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t provisioned = 0;
|
||||
err = nvs_get_u8(handle, KEY_PROVISIONED, &provisioned);
|
||||
nvs_close(handle);
|
||||
|
||||
// If key not found (ESP_ERR_NVS_NOT_FOUND), it's first boot
|
||||
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (provisioned == 0);
|
||||
}
|
||||
|
||||
bool nvsDriverMarkProvisioned(void) {
|
||||
nvs_handle_t handle;
|
||||
esp_err_t err = nvs_open(NAMESPACE, NVS_READWRITE, &handle);
|
||||
if (err != ESP_OK)
|
||||
return false;
|
||||
|
||||
err = nvs_set_u8(handle, KEY_PROVISIONED, 1);
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_commit(handle);
|
||||
}
|
||||
nvs_close(handle);
|
||||
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Device marked as provisioned");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to write provision flag: %s", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
return (err == ESP_OK);
|
||||
}
|
||||
|
||||
uint32_t nvsDriverGetBootCount(void) {
|
||||
nvs_handle_t handle;
|
||||
if (nvs_open(NAMESPACE, NVS_READONLY, &handle) != ESP_OK)
|
||||
return 1;
|
||||
|
||||
uint32_t count = 0;
|
||||
esp_err_t err = nvs_get_u32(handle, KEY_BOOT_COUNT, &count);
|
||||
nvs_close(handle);
|
||||
|
||||
return (err == ESP_OK) ? count : 1;
|
||||
}
|
||||
|
||||
void nvsDriverIncrementBootCount(void) {
|
||||
nvs_handle_t handle;
|
||||
if (nvs_open(NAMESPACE, NVS_READWRITE, &handle) != ESP_OK)
|
||||
return;
|
||||
|
||||
uint32_t count = 0;
|
||||
nvs_get_u32(handle, KEY_BOOT_COUNT, &count);
|
||||
count++;
|
||||
|
||||
nvs_set_u32(handle, KEY_BOOT_COUNT, count);
|
||||
nvs_commit(handle);
|
||||
nvs_close(handle);
|
||||
|
||||
ESP_LOGI(TAG, "Boot count updated: %ld", (long)count);
|
||||
}
|
||||
|
||||
// IMU calibration keys
|
||||
static const char *KEY_IMU_CAL_X = "imu_cal_x";
|
||||
static const char *KEY_IMU_CAL_Y = "imu_cal_y";
|
||||
static const char *KEY_IMU_CAL_Z = "imu_cal_z";
|
||||
|
||||
bool nvsDriverSaveImuCalibration(float x, float y, float z) {
|
||||
nvs_handle_t handle;
|
||||
esp_err_t err = nvs_open(NAMESPACE, NVS_READWRITE, &handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to open NVS for calibration save");
|
||||
return false;
|
||||
}
|
||||
|
||||
// NVS doesn't have native float support, so we store as blobs
|
||||
bool success = true;
|
||||
if (nvs_set_blob(handle, KEY_IMU_CAL_X, &x, sizeof(float)) != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
if (nvs_set_blob(handle, KEY_IMU_CAL_Y, &y, sizeof(float)) != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
if (nvs_set_blob(handle, KEY_IMU_CAL_Z, &z, sizeof(float)) != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
err = nvs_commit(handle);
|
||||
if (err != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
|
||||
if (success) {
|
||||
ESP_LOGI(TAG, "IMU calibration saved: x=%.3f y=%.3f z=%.3f", x, y, z);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to save IMU calibration");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool nvsDriverLoadImuCalibration(float *x, float *y, float *z) {
|
||||
if (!x || !y || !z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nvs_handle_t handle;
|
||||
esp_err_t err = nvs_open(NAMESPACE, NVS_READONLY, &handle);
|
||||
if (err != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = sizeof(float);
|
||||
bool success = true;
|
||||
|
||||
if (nvs_get_blob(handle, KEY_IMU_CAL_X, x, &size) != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
size = sizeof(float);
|
||||
if (nvs_get_blob(handle, KEY_IMU_CAL_Y, y, &size) != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
size = sizeof(float);
|
||||
if (nvs_get_blob(handle, KEY_IMU_CAL_Z, z, &size) != ESP_OK) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
|
||||
if (success) {
|
||||
ESP_LOGI(TAG, "IMU calibration loaded: x=%.3f y=%.3f z=%.3f", *x, *y, *z);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
84
main/drivers/nvs_driver.h
Normal file
84
main/drivers/nvs_driver.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file nvs_driver.h
|
||||
* @brief Non-Volatile Storage abstraction for persistent state
|
||||
*
|
||||
* Handles reading and writing system state to flash memory.
|
||||
* Used for tracking first-boot status and other persistent flags.
|
||||
*/
|
||||
|
||||
#ifndef NVS_DRIVER_H
|
||||
#define NVS_DRIVER_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize NVS flash
|
||||
*
|
||||
* Must be called before any other NVS operations.
|
||||
* Handles partition initialization and potential recovery.
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool nvsDriverInit(void);
|
||||
|
||||
/**
|
||||
* @brief Check if this is the device's first boot
|
||||
*
|
||||
* Checks for the existence of a "provisioned" flag.
|
||||
*
|
||||
* @return true if first boot (flag not found), false otherwise
|
||||
*/
|
||||
bool nvsDriverIsFirstBoot(void);
|
||||
|
||||
/**
|
||||
* @brief Mark the device as provisioned (not first boot)
|
||||
*
|
||||
* Writes the persistent flag to storage.
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool nvsDriverMarkProvisioned(void);
|
||||
|
||||
/**
|
||||
* @brief Get the total boot count
|
||||
*
|
||||
* @return Number of times device has booted (defaults to 1 if read fails)
|
||||
*/
|
||||
uint32_t nvsDriverGetBootCount(void);
|
||||
|
||||
/**
|
||||
* @brief Increment the total boot count
|
||||
*/
|
||||
void nvsDriverIncrementBootCount(void);
|
||||
|
||||
/**
|
||||
* @brief Save IMU calibration data to NVS
|
||||
*
|
||||
* @param x X-axis baseline value
|
||||
* @param y Y-axis baseline value
|
||||
* @param z Z-axis baseline value
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool nvsDriverSaveImuCalibration(float x, float y, float z);
|
||||
|
||||
/**
|
||||
* @brief Load IMU calibration data from NVS
|
||||
*
|
||||
* @param x Pointer to store X-axis baseline
|
||||
* @param y Pointer to store Y-axis baseline
|
||||
* @param z Pointer to store Z-axis baseline
|
||||
* @return true if calibration data exists and was loaded, false otherwise
|
||||
*/
|
||||
bool nvsDriverLoadImuCalibration(float *x, float *y, float *z);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NVS_DRIVER_H
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "ui/lottie_player.h"
|
||||
|
||||
|
||||
static const char *TAG = "blink_emotion";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -61,15 +60,19 @@ void blinkEmotionPlay(void) {
|
||||
ESP_LOGE(TAG, "Failed to create blink player");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// If player already exists, resume playback and blink timer
|
||||
lottiePlay(blinkPlayer);
|
||||
lottieResumeNaturalBlink(blinkPlayer);
|
||||
}
|
||||
|
||||
// Lottie player auto-starts with natural blink mode
|
||||
ESP_LOGI(TAG, "Blink animation active");
|
||||
}
|
||||
|
||||
void blinkEmotionPause(void) {
|
||||
if (blinkPlayer != NULL) {
|
||||
lottiePause(blinkPlayer);
|
||||
lottiePauseNaturalBlink(blinkPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include "emotion-engine/emotion_manager.h"
|
||||
#include "drivers/display_driver.h"
|
||||
#include "emotion-engine/blink/blink_emotion.h"
|
||||
#include "emotion-engine/shake/shake_emotion.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
|
||||
static const char *TAG = "emotion_manager";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -34,6 +34,12 @@ bool emotionManagerInit(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize shake emotion
|
||||
if (!shakeEmotionInit()) {
|
||||
ESP_LOGE(TAG, "Failed to initialize shake emotion");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Future: Initialize other emotions here
|
||||
// surprisedEmotionInit();
|
||||
// sadEmotionInit();
|
||||
@@ -72,17 +78,27 @@ void emotionManagerSetEmotion(EmotionType emotion) {
|
||||
switch (emotion) {
|
||||
case EMOTION_IDLE:
|
||||
case EMOTION_BLINK:
|
||||
// Play blink animation
|
||||
// Stop any other animations and play blink
|
||||
shakeEmotionStop();
|
||||
blinkEmotionPlay();
|
||||
break;
|
||||
|
||||
case EMOTION_SHAKING:
|
||||
// Stop blink and play shaking animation
|
||||
blinkEmotionPause();
|
||||
shakeEmotionPlay();
|
||||
break;
|
||||
|
||||
case EMOTION_SHAKE_STOPPING:
|
||||
// Begin the shake-stop transition sequence
|
||||
shakeEmotionBeginStop();
|
||||
break;
|
||||
|
||||
case EMOTION_SURPRISED:
|
||||
case EMOTION_SAD:
|
||||
case EMOTION_ANGRY:
|
||||
// Future: Implement other emotion animations
|
||||
// For now, trigger a blink as visual feedback
|
||||
ESP_LOGI(TAG, "Emotion %d not yet implemented, using blink", emotion);
|
||||
blinkEmotionPlay();
|
||||
ESP_LOGI(TAG, "Emotion %d not yet implemented", emotion);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -27,6 +27,8 @@ extern "C" {
|
||||
typedef enum {
|
||||
EMOTION_IDLE = 0, // Default idle state with blink
|
||||
EMOTION_BLINK, // Single blink animation
|
||||
EMOTION_SHAKING, // Currently being shaken
|
||||
EMOTION_SHAKE_STOPPING, // Transition from shaking to idle
|
||||
EMOTION_SURPRISED, // Surprised expression
|
||||
EMOTION_SAD, // Sad expression
|
||||
EMOTION_ANGRY, // Angry expression
|
||||
|
||||
1
main/emotion-engine/shake-stop/shaking-stop.json
Normal file
1
main/emotion-engine/shake-stop/shaking-stop.json
Normal file
File diff suppressed because one or more lines are too long
409
main/emotion-engine/shake/shake_emotion.c
Normal file
409
main/emotion-engine/shake/shake_emotion.c
Normal file
@@ -0,0 +1,409 @@
|
||||
/**
|
||||
* @file shake_emotion.c
|
||||
* @brief Shaking animation implementation with shake-stop transition
|
||||
*
|
||||
* This module manages the shaking Lottie animation that plays when the
|
||||
* device is being continuously shaken, and the shake-stop transition
|
||||
* animation that plays when shaking ends.
|
||||
*
|
||||
* State machine:
|
||||
* 1. IDLE -> shakeEmotionPlay() -> SHAKING (loop)
|
||||
* 2. SHAKING -> shakeEmotionBeginStop() -> FINISHING_LOOP
|
||||
* 3. FINISHING_LOOP -> (current loop ends) -> PLAYING_STOP_ANIM
|
||||
* 4. PLAYING_STOP_ANIM -> (animation ends) -> COMPLETE
|
||||
* 5. shakeEmotionUpdate() returns true when COMPLETE
|
||||
*/
|
||||
|
||||
#include "emotion-engine/shake/shake_emotion.h"
|
||||
#include "drivers/display_driver.h"
|
||||
#include "esp_log.h"
|
||||
#include "ui/lottie_player.h"
|
||||
|
||||
static const char *TAG = "shake_emotion";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Embedded Animation Data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Shaking animation JSON data (minified from shaking.json)
|
||||
static const char *shakingAnimationData =
|
||||
"{\"fr\":60,\"h\":448,\"ip\":0,\"layers\":[{\"ind\":3,\"ty\":4,\"parent\":"
|
||||
"2,"
|
||||
"\"ks\":{},\"ip\":0,\"op\":16,\"st\":0,\"shapes\":[{\"ty\":\"rc\",\"p\":{"
|
||||
"\"a\":0,\"k\":[48.5,68]},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":0,\"k\":["
|
||||
"97,136]}},{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[1,1,1]},\"o\":{\"a\":0,"
|
||||
"\"k\":100}}]},{\"ind\":2,\"ty\":3,\"parent\":1,\"ks\":{\"p\":{\"a\":1,"
|
||||
"\"k\":[{\"t\":0,\"s\":[211,88],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},"
|
||||
"\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":0.696,\"s\":[249.6,88],"
|
||||
"\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":["
|
||||
"0.678,0]}},{\"t\":1.386,\"s\":[268.932,88],\"i\":{\"x\":[0.447,1],\"y\":["
|
||||
"0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":2.772,\"s\":["
|
||||
"259.742,88],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,"
|
||||
"0],\"y\":[0,0]}},{\"t\":4.176,\"s\":[261.2,88],\"i\":{\"x\":[0.446,1],"
|
||||
"\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":5.562,"
|
||||
"\"s\":[260.968,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":7.5,\"s\":[261.002,88],\"h\":1},{\"t\":7.5,\"s\":["
|
||||
"261,88],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],"
|
||||
"\"y\":[0.033,0]}},{\"t\":8.196,\"s\":[183.801,88],\"i\":{\"x\":[0.591,1],"
|
||||
"\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":8.886,"
|
||||
"\"s\":[145.137,88],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":["
|
||||
"0.279,0],\"y\":[0.02,0]}},{\"t\":10.272,\"s\":[163.515,88],\"i\":{\"x\":["
|
||||
"0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":"
|
||||
"11.676,\"s\":[160.601,88],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{"
|
||||
"\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":13.062,\"s\":[161.063,88],\"i\":{"
|
||||
"\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":15,\"s\":"
|
||||
"[160.996,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,"
|
||||
"0]}},{\"t\":15,\"s\":[160.998,88],\"h\":1}]}},\"ip\":0,\"op\":16,\"st\":0}"
|
||||
",{\"ind\":5,\"ty\":4,\"parent\":4,\"ks\":{},\"ip\":0,\"op\":16,\"st\":0,"
|
||||
"\"shapes\":[{\"ty\":\"rc\",\"p\":{\"a\":0,\"k\":[48.5,67.5]},\"r\":{\"a\":"
|
||||
"0,\"k\":20},\"s\":{\"a\":0,\"k\":[97,135]}},{\"ty\":\"fl\",\"c\":{\"a\":0,"
|
||||
"\"k\":[1,1,1]},\"o\":{\"a\":0,\"k\":100}}]},{\"ind\":4,\"ty\":3,\"parent\""
|
||||
":1,\"ks\":{\"a\":{\"a\":0,\"k\":[48.5,67.5]},\"p\":{\"a\":1,\"k\":[{\"t\":"
|
||||
"0,\"s\":[108.5,155.5],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\""
|
||||
":[0.321,0],\"y\":[0.033,0]}},{\"t\":0.696,\"s\":[147.1,155.5],\"i\":{"
|
||||
"\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},"
|
||||
"{\"t\":1.386,\"s\":[166.432,155.5],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]}"
|
||||
",\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":2.772,\"s\":[157.242,"
|
||||
"155.5],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],"
|
||||
"\"y\":[0,0]}},{\"t\":4.176,\"s\":[158.7,155.5],\"i\":{\"x\":[0.446,1],"
|
||||
"\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":5.562,"
|
||||
"\"s\":[158.468,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":7.5,\"s\":[158.502,155.5],\"h\":1},{\"t\":7.5,\"s\":["
|
||||
"158.5,155.5],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,"
|
||||
"0],\"y\":[0.033,0]}},{\"t\":8.196,\"s\":[81.301,155.5],\"i\":{\"x\":["
|
||||
"0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":"
|
||||
"8.886,\"s\":[42.637,155.5],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{"
|
||||
"\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":10.272,\"s\":[61.015,155.5],\"i\":"
|
||||
"{"
|
||||
"\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},"
|
||||
"{\"t\":11.676,\"s\":[58.101,155.5],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]}"
|
||||
",\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":13.062,\"s\":[58.563,"
|
||||
"155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":15,\"s\":[58.496,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},{\"t\":15,\"s\":[58.498,155.5],\"h\":1}]}},"
|
||||
"\"ip\":0,\"op\":16,\"st\":0},{\"ind\":1,\"ty\":3,\"parent\":0,\"ks\":{},"
|
||||
"\"ip\":0,\"op\":16,\"st\":0},{\"ind\":6,\"ty\":4,\"parent\":0,\"ks\":{},"
|
||||
"\"ip\":0,\"op\":16,\"st\":0,\"shapes\":[{\"ty\":\"rc\",\"p\":{\"a\":0,"
|
||||
"\"k\":[184,224]},\"r\":{\"a\":0,\"k\":0},\"s\":{\"a\":0,\"k\":[368,448]}},"
|
||||
"{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[0,0,0]},\"o\":{\"a\":0,\"k\":100}}]},"
|
||||
"{\"ind\":0,\"ty\":3,\"ks\":{},\"ip\":0,\"op\":16,\"st\":0}],\"meta\":{"
|
||||
"\"g\":\"https://jitter.video\"},\"op\":15,\"v\":\"5.7.4\",\"w\":368}";
|
||||
|
||||
// Shake-stop transition animation (embedded from shaking-stop.json)
|
||||
// This is a longer animation (~110 frames at 60fps = ~1.8 seconds)
|
||||
static const char *shakeStopAnimationData =
|
||||
"{\"fr\":60,\"h\":448,\"ip\":0,\"layers\":[{\"ind\":3,\"ty\":4,\"parent\":"
|
||||
"2,\"ks\":{},\"ip\":0,\"op\":110.8,\"st\":0,\"shapes\":[{\"ty\":\"rc\","
|
||||
"\"p\":{\"a\":0,\"k\":[48.5,68]},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":0,"
|
||||
"\"k\":[97,136]}},{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[1,1,1]},\"o\":{"
|
||||
"\"a\":0,\"k\":100}}]},{\"ind\":2,\"ty\":3,\"parent\":1,\"ks\":{\"p\":{"
|
||||
"\"a\":1,\"k\":[{\"t\":0,\"s\":[211,88],\"i\":{\"x\":[0.613,1],\"y\":[0."
|
||||
"589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":0.696,\"s\":[249."
|
||||
"6,88],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],"
|
||||
"\"y\":[0.678,0]}},{\"t\":1.386,\"s\":[268.932,88],\"i\":{\"x\":[0.447,1],"
|
||||
"\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":2.772,"
|
||||
"\"s\":[259.742,88],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":["
|
||||
"0.279,0],\"y\":[0,0]}},{\"t\":4.176,\"s\":[261.2,88],\"i\":{\"x\":[0.446,"
|
||||
"1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":5.562,"
|
||||
"\"s\":[260.968,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":7.5,\"s\":[261.002,88],\"h\":1},{\"t\":7.5,\"s\":["
|
||||
"261,88],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],"
|
||||
"\"y\":[0.033,0]}},{\"t\":8.196,\"s\":[183.801,88],\"i\":{\"x\":[0.591,1],"
|
||||
"\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":8.886,"
|
||||
"\"s\":[145.137,88],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":["
|
||||
"0.279,0],\"y\":[0.02,0]}},{\"t\":10.272,\"s\":[163.515,88],\"i\":{\"x\":["
|
||||
"0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":11."
|
||||
"676,\"s\":[160.601,88],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{"
|
||||
"\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":13.062,\"s\":[161.063,88],\"i\":{"
|
||||
"\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":15,\"s\":"
|
||||
"[160.996,88],\"h\":1},{\"t\":15,\"s\":[161,88],\"i\":{\"x\":[0.613,1],"
|
||||
"\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":16.08,"
|
||||
"\"s\":[238.199,88],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":["
|
||||
"0.319,0],\"y\":[0.678,0]}},{\"t\":17.16,\"s\":[276.863,88],\"i\":{\"x\":["
|
||||
"0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":"
|
||||
"19.326,\"s\":[258.485,88],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{"
|
||||
"\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":21.51,\"s\":[261.399,88],\"i\":{"
|
||||
"\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{"
|
||||
"\"t\":23.676,\"s\":[260.937,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},{\"t\":26.7,\"s\":[261.004,88],\"h\":1},{\"t\":"
|
||||
"26.7,\"s\":[261,88],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":["
|
||||
"0.321,0],\"y\":[0.033,0]}},{\"t\":27.78,\"s\":[183.801,88],\"i\":{\"x\":["
|
||||
"0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":"
|
||||
"28.86,\"s\":[145.137,88],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{"
|
||||
"\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":31.026,\"s\":[163.515,88],\"i\":{"
|
||||
"\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{"
|
||||
"\"t\":33.21,\"s\":[160.601,88],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},"
|
||||
"\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":35.376,\"s\":[161.063,88],"
|
||||
"\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":"
|
||||
"38.4,\"s\":[160.996,88],\"h\":1},{\"t\":38.4,\"s\":[161,88],\"i\":{\"x\":["
|
||||
"0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":"
|
||||
"40.59,\"s\":[238.199,88],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{"
|
||||
"\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":42.78,\"s\":[276.863,88],\"i\":{"
|
||||
"\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{"
|
||||
"\"t\":47.16,\"s\":[258.485,88],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},"
|
||||
"\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":51.594,\"s\":[261.399,88],"
|
||||
"\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0."
|
||||
"02,0]}},{\"t\":55.974,\"s\":[260.937,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},"
|
||||
"\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":62.1,\"s\":[261.004,88],\"h\":1},{"
|
||||
"\"t\":62.1,\"s\":[261,88],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{"
|
||||
"\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":64.29,\"s\":[183.801,88],\"i\":{"
|
||||
"\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},"
|
||||
"{\"t\":66.48,\"s\":[145.137,88],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},"
|
||||
"\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":70.86,\"s\":[163.515,88],"
|
||||
"\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]"
|
||||
"}},{\"t\":75.294,\"s\":[160.601,88],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]"
|
||||
"},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":79.674,\"s\":[161.063,88]"
|
||||
",\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":"
|
||||
"85.8,\"s\":[160.996,88],\"h\":1},{\"t\":85.8,\"s\":[161,88],\"i\":{\"x\":["
|
||||
"0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":"
|
||||
"87.99,\"s\":[199.6,88],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{"
|
||||
"\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":90.18,\"s\":[218.932,88],\"i\":{"
|
||||
"\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{"
|
||||
"\"t\":94.56,\"s\":[209.742,88],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},"
|
||||
"\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":98.994,\"s\":[211.2,88],\"i\":"
|
||||
"{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},"
|
||||
"{\"t\":103.374,\"s\":[210.968,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},{\"t\":109.5,\"s\":[211.002,88],\"h\":1},{\"t\":"
|
||||
"109.5,\"s\":[211,88],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":109.8,\"s\":[211,88],\"h\":1}]}},\"ip\":0,\"op\":110."
|
||||
"8,\"st\":0},{\"ind\":5,\"ty\":4,\"parent\":4,\"ks\":{},\"ip\":0,\"op\":"
|
||||
"110.8,\"st\":0,\"shapes\":[{\"ty\":\"rc\",\"p\":{\"a\":0,\"k\":[48.5,67.5]"
|
||||
"},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":0,\"k\":[97,135]}},{\"ty\":\"fl\","
|
||||
"\"c\":{\"a\":0,\"k\":[1,1,1]},\"o\":{\"a\":0,\"k\":100}}]},{\"ind\":4,"
|
||||
"\"ty\":3,\"parent\":1,\"ks\":{\"a\":{\"a\":0,\"k\":[48.5,67.5]},\"p\":{"
|
||||
"\"a\":1,\"k\":[{\"t\":0,\"s\":[108.5,155.5],\"i\":{\"x\":[0.613,1],\"y\":["
|
||||
"0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":0.696,\"s\":["
|
||||
"147.1,155.5],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,"
|
||||
"0],\"y\":[0.678,0]}},{\"t\":1.386,\"s\":[166.432,155.5],\"i\":{\"x\":[0."
|
||||
"447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":2."
|
||||
"772,\"s\":[157.242,155.5],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{"
|
||||
"\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":4.176,\"s\":[158.7,155.5],\"i\":{"
|
||||
"\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{"
|
||||
"\"t\":5.562,\"s\":[158.468,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},{\"t\":7.5,\"s\":[158.502,155.5],\"h\":1},{"
|
||||
"\"t\":7.5,\"s\":[158.5,155.5],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},"
|
||||
"\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":8.196,\"s\":[81.301,155.5]"
|
||||
",\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0."
|
||||
"678,0]}},{\"t\":8.886,\"s\":[42.637,155.5],\"i\":{\"x\":[0.447,1],\"y\":["
|
||||
"0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":10.272,\"s\":[61."
|
||||
"015,155.5],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],"
|
||||
"\"y\":[0,0]}},{\"t\":11.676,\"s\":[58.101,155.5],\"i\":{\"x\":[0.446,1],"
|
||||
"\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":13.062,"
|
||||
"\"s\":[58.563,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":15,\"s\":[58.496,155.5],\"h\":1},{\"t\":15,\"s\":[58."
|
||||
"5,155.5],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],"
|
||||
"\"y\":[0.033,0]}},{\"t\":16.08,\"s\":[135.699,155.5],\"i\":{\"x\":[0.591,"
|
||||
"1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":17.16,"
|
||||
"\"s\":[174.363,155.5],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{"
|
||||
"\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":19.326,\"s\":[155.985,155.5],"
|
||||
"\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]"
|
||||
"}},{\"t\":21.51,\"s\":[158.899,155.5],\"i\":{\"x\":[0.446,1],\"y\":[0.987,"
|
||||
"1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":23.676,\"s\":[158.437,"
|
||||
"155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{"
|
||||
"\"t\":26.7,\"s\":[158.504,155.5],\"h\":1},{\"t\":26.7,\"s\":[158.5,155.5],"
|
||||
"\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0."
|
||||
"033,0]}},{\"t\":27.78,\"s\":[81.301,155.5],\"i\":{\"x\":[0.591,1],\"y\":["
|
||||
"0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":28.86,\"s\":[42."
|
||||
"637,155.5],\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],"
|
||||
"\"y\":[0.02,0]}},{\"t\":31.026,\"s\":[61.015,155.5],\"i\":{\"x\":[0.442,1]"
|
||||
",\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":33.21,\"s\":"
|
||||
"[58.101,155.5],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0."
|
||||
"281,0],\"y\":[0.02,0]}},{\"t\":35.376,\"s\":[58.563,155.5],\"i\":{\"x\":["
|
||||
"1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":38.4,\"s\":[58."
|
||||
"496,155.5],\"h\":1},{\"t\":38.4,\"s\":[58.5,155.5],\"i\":{\"x\":[0.613,1],"
|
||||
"\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":40.59,"
|
||||
"\"s\":[135.699,155.5],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{"
|
||||
"\"x\":[0.319,0],\"y\":[0.678,0]}},{\"t\":42.78,\"s\":[174.363,155.5],"
|
||||
"\"i\":{\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0."
|
||||
"02,0]}},{\"t\":47.16,\"s\":[155.985,155.5],\"i\":{\"x\":[0.442,1],\"y\":["
|
||||
"0.994,1]},\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":51.594,\"s\":[158."
|
||||
"899,155.5],\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],"
|
||||
"\"y\":[0.02,0]}},{\"t\":55.974,\"s\":[158.437,155.5],\"i\":{\"x\":[1,1],"
|
||||
"\"y\":[1,1]},\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":62.1,\"s\":[158.504,"
|
||||
"155.5],\"h\":1},{\"t\":62.1,\"s\":[158.5,155.5],\"i\":{\"x\":[0.613,1],"
|
||||
"\"y\":[0.589,1]},\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":64.29,"
|
||||
"\"s\":[81.301,155.5],\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":"
|
||||
"[0.319,0],\"y\":[0.678,0]}},{\"t\":66.48,\"s\":[42.637,155.5],\"i\":{"
|
||||
"\"x\":[0.447,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{"
|
||||
"\"t\":70.86,\"s\":[61.015,155.5],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},"
|
||||
"\"o\":{\"x\":[0.279,0],\"y\":[0,0]}},{\"t\":75.294,\"s\":[58.101,155.5],"
|
||||
"\"i\":{\"x\":[0.446,1],\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0."
|
||||
"02,0]}},{\"t\":79.674,\"s\":[58.563,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]}"
|
||||
",\"o\":{\"x\":[0,0],\"y\":[0,0]}},{\"t\":85.8,\"s\":[58.496,155.5],\"h\":"
|
||||
"1},{\"t\":85.8,\"s\":[58.5,155.5],\"i\":{\"x\":[0.613,1],\"y\":[0.589,1]},"
|
||||
"\"o\":{\"x\":[0.321,0],\"y\":[0.033,0]}},{\"t\":87.99,\"s\":[97.1,155.5],"
|
||||
"\"i\":{\"x\":[0.591,1],\"y\":[0.993,1]},\"o\":{\"x\":[0.319,0],\"y\":[0."
|
||||
"678,0]}},{\"t\":90.18,\"s\":[116.432,155.5],\"i\":{\"x\":[0.447,1],\"y\":["
|
||||
"0.987,1]},\"o\":{\"x\":[0.279,0],\"y\":[0.02,0]}},{\"t\":94.56,\"s\":[107."
|
||||
"242,155.5],\"i\":{\"x\":[0.442,1],\"y\":[0.994,1]},\"o\":{\"x\":[0.279,0],"
|
||||
"\"y\":[0,0]}},{\"t\":98.994,\"s\":[108.7,155.5],\"i\":{\"x\":[0.446,1],"
|
||||
"\"y\":[0.987,1]},\"o\":{\"x\":[0.281,0],\"y\":[0.02,0]}},{\"t\":103.374,"
|
||||
"\"s\":[108.468,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":109.5,\"s\":[108.502,155.5],\"h\":1},{\"t\":109.5,"
|
||||
"\"s\":[108.5,155.5],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{\"x\":[0,0],"
|
||||
"\"y\":[0,0]}},{\"t\":109.8,\"s\":[108.5,155.5],\"h\":1}]}},\"ip\":0,"
|
||||
"\"op\":110.8,\"st\":0},{\"ind\":1,\"ty\":3,\"parent\":0,\"ks\":{},\"ip\":"
|
||||
"0,\"op\":110.8,\"st\":0},{\"ind\":6,\"ty\":4,\"parent\":0,\"ks\":{},"
|
||||
"\"ip\":0,\"op\":110.8,\"st\":0,\"shapes\":[{\"ty\":\"rc\",\"p\":{\"a\":0,"
|
||||
"\"k\":[184,224]},\"r\":{\"a\":0,\"k\":0},\"s\":{\"a\":0,\"k\":[368,448]}},"
|
||||
"{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[0,0,0]},\"o\":{\"a\":0,\"k\":100}}]},"
|
||||
"{\"ind\":0,\"ty\":3,\"ks\":{},\"ip\":0,\"op\":110.8,\"st\":0}],\"meta\":{"
|
||||
"\"g\":\"https://jitter.video\"},\"op\":109.8,\"v\":\"5.7.4\",\"w\":368}";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// State Machine
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef enum {
|
||||
SHAKE_STATE_IDLE = 0,
|
||||
SHAKE_STATE_SHAKING,
|
||||
SHAKE_STATE_FINISHING_LOOP,
|
||||
SHAKE_STATE_PLAYING_STOP_ANIM,
|
||||
SHAKE_STATE_COMPLETE
|
||||
} ShakeState;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Private State
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static lottie_player_handle_t shakePlayer = NULL;
|
||||
static lottie_player_handle_t stopPlayer = NULL;
|
||||
static bool initialized = false;
|
||||
static ShakeState state = SHAKE_STATE_IDLE;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Public API Implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool shakeEmotionInit(void) {
|
||||
ESP_LOGI(TAG, "Initializing shake emotion");
|
||||
initialized = true;
|
||||
state = SHAKE_STATE_IDLE;
|
||||
ESP_LOGI(TAG, "Shake emotion initialized (deferred player creation)");
|
||||
return true;
|
||||
}
|
||||
|
||||
void shakeEmotionPlay(void) {
|
||||
if (!initialized) {
|
||||
ESP_LOGE(TAG, "Shake emotion not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create shake player on first play
|
||||
if (shakePlayer == NULL) {
|
||||
ESP_LOGI(TAG, "Creating shake player");
|
||||
|
||||
lv_obj_t *screen = displayDriverGetActiveScreen();
|
||||
if (screen == NULL) {
|
||||
ESP_LOGE(TAG, "No active screen available");
|
||||
return;
|
||||
}
|
||||
|
||||
shakePlayer = lottieCreateFromData(screen, shakingAnimationData);
|
||||
if (shakePlayer == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create shake player");
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable natural blink mode and set native speed
|
||||
lottieDisableNaturalBlink(shakePlayer);
|
||||
lottieSetSpeed(shakePlayer, 1.0f);
|
||||
}
|
||||
|
||||
// Set to loop mode and play
|
||||
lottieSetLoop(shakePlayer, true);
|
||||
lottieSetFrame(shakePlayer, 0);
|
||||
lottiePlay(shakePlayer);
|
||||
state = SHAKE_STATE_SHAKING;
|
||||
|
||||
ESP_LOGI(TAG, "Shake animation started (looping)");
|
||||
}
|
||||
|
||||
void shakeEmotionBeginStop(void) {
|
||||
if (state != SHAKE_STATE_SHAKING) {
|
||||
ESP_LOGW(TAG, "Cannot begin stop - not shaking (state=%d)", state);
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable looping so animation finishes current loop
|
||||
if (shakePlayer != NULL) {
|
||||
lottieSetLoop(shakePlayer, false);
|
||||
}
|
||||
|
||||
state = SHAKE_STATE_FINISHING_LOOP;
|
||||
ESP_LOGI(TAG, "Finishing shake loop before stop animation");
|
||||
}
|
||||
|
||||
bool shakeEmotionUpdate(void) {
|
||||
if (state == SHAKE_STATE_IDLE || state == SHAKE_STATE_SHAKING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state == SHAKE_STATE_FINISHING_LOOP) {
|
||||
// Check if shake animation has completed its loop
|
||||
if (shakePlayer != NULL && !lottieIsPlaying(shakePlayer)) {
|
||||
// Destroy shake player
|
||||
lottieDestroy(shakePlayer);
|
||||
shakePlayer = NULL;
|
||||
|
||||
// Create and play the stop animation
|
||||
lv_obj_t *screen = displayDriverGetActiveScreen();
|
||||
if (screen != NULL) {
|
||||
stopPlayer = lottieCreateFromData(screen, shakeStopAnimationData);
|
||||
if (stopPlayer != NULL) {
|
||||
lottieDisableNaturalBlink(stopPlayer);
|
||||
lottieSetSpeed(stopPlayer, 1.0f);
|
||||
lottieSetLoop(stopPlayer, false);
|
||||
lottieSetFrame(stopPlayer, 0);
|
||||
lottiePlay(stopPlayer);
|
||||
state = SHAKE_STATE_PLAYING_STOP_ANIM;
|
||||
ESP_LOGI(TAG, "Playing shake-stop transition animation");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to create stop animation player");
|
||||
state = SHAKE_STATE_COMPLETE;
|
||||
}
|
||||
} else {
|
||||
state = SHAKE_STATE_COMPLETE;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state == SHAKE_STATE_PLAYING_STOP_ANIM) {
|
||||
// Check if stop animation has completed
|
||||
if (stopPlayer != NULL && !lottieIsPlaying(stopPlayer)) {
|
||||
lottieDestroy(stopPlayer);
|
||||
stopPlayer = NULL;
|
||||
state = SHAKE_STATE_COMPLETE;
|
||||
ESP_LOGI(TAG, "Shake-stop transition complete");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state == SHAKE_STATE_COMPLETE) {
|
||||
state = SHAKE_STATE_IDLE;
|
||||
return true; // Signal ready to return to idle
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void shakeEmotionStop(void) {
|
||||
if (shakePlayer != NULL) {
|
||||
lottiePause(shakePlayer);
|
||||
lottieDestroy(shakePlayer);
|
||||
shakePlayer = NULL;
|
||||
}
|
||||
if (stopPlayer != NULL) {
|
||||
lottiePause(stopPlayer);
|
||||
lottieDestroy(stopPlayer);
|
||||
stopPlayer = NULL;
|
||||
}
|
||||
state = SHAKE_STATE_IDLE;
|
||||
ESP_LOGI(TAG, "Shake animation stopped (immediate)");
|
||||
}
|
||||
|
||||
bool shakeEmotionIsPlaying(void) {
|
||||
return state == SHAKE_STATE_SHAKING || state == SHAKE_STATE_FINISHING_LOOP ||
|
||||
state == SHAKE_STATE_PLAYING_STOP_ANIM;
|
||||
}
|
||||
66
main/emotion-engine/shake/shake_emotion.h
Normal file
66
main/emotion-engine/shake/shake_emotion.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @file shake_emotion.h
|
||||
* @brief Shaking animation controller
|
||||
*
|
||||
* Manages the shaking Lottie animation that plays when the device
|
||||
* is being continuously shaken, and the shake-stop transition animation.
|
||||
*/
|
||||
|
||||
#ifndef SHAKE_EMOTION_H
|
||||
#define SHAKE_EMOTION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize the shake emotion module
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool shakeEmotionInit(void);
|
||||
|
||||
/**
|
||||
* @brief Start playing the shaking animation
|
||||
*
|
||||
* Animation will loop until shakeEmotionBeginStop() is called.
|
||||
*/
|
||||
void shakeEmotionPlay(void);
|
||||
|
||||
/**
|
||||
* @brief Begin stopping the shake animation
|
||||
*
|
||||
* Finishes the current shaking loop, then plays the shake-stop transition.
|
||||
* Call shakeEmotionUpdate() to poll for completion.
|
||||
*/
|
||||
void shakeEmotionBeginStop(void);
|
||||
|
||||
/**
|
||||
* @brief Update the shake stop transition
|
||||
*
|
||||
* Must be called periodically to complete the shake-stop transition.
|
||||
*
|
||||
* @return true if transition is complete and ready for idle, false if still
|
||||
* transitioning
|
||||
*/
|
||||
bool shakeEmotionUpdate(void);
|
||||
|
||||
/**
|
||||
* @brief Stop the shaking animation immediately (for cleanup)
|
||||
*/
|
||||
void shakeEmotionStop(void);
|
||||
|
||||
/**
|
||||
* @brief Check if shaking animation is currently playing
|
||||
*
|
||||
* @return true if playing, false otherwise
|
||||
*/
|
||||
bool shakeEmotionIsPlaying(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SHAKE_EMOTION_H
|
||||
1
main/emotion-engine/shake/shaking.json
Normal file
1
main/emotion-engine/shake/shaking.json
Normal file
@@ -0,0 +1 @@
|
||||
{"fr":60,"h":448,"ip":0,"layers":[{"ind":3,"ty":4,"parent":2,"ks":{},"ip":0,"op":16,"st":0,"shapes":[{"ty":"rc","p":{"a":0,"k":[48.5,68]},"r":{"a":0,"k":20},"s":{"a":0,"k":[97,136]}},{"ty":"fl","c":{"a":0,"k":[1,1,1]},"o":{"a":0,"k":100}}]},{"ind":2,"ty":3,"parent":1,"ks":{"p":{"a":1,"k":[{"t":0,"s":[211,88],"i":{"x":[0.613,1],"y":[0.589,1]},"o":{"x":[0.321,0],"y":[0.033,0]}},{"t":0.696,"s":[249.6,88],"i":{"x":[0.591,1],"y":[0.993,1]},"o":{"x":[0.319,0],"y":[0.678,0]}},{"t":1.386,"s":[268.932,88],"i":{"x":[0.447,1],"y":[0.987,1]},"o":{"x":[0.279,0],"y":[0.02,0]}},{"t":2.772,"s":[259.742,88],"i":{"x":[0.442,1],"y":[0.994,1]},"o":{"x":[0.279,0],"y":[0,0]}},{"t":4.176,"s":[261.2,88],"i":{"x":[0.446,1],"y":[0.987,1]},"o":{"x":[0.281,0],"y":[0.02,0]}},{"t":5.562,"s":[260.968,88],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":7.5,"s":[261.002,88],"h":1},{"t":7.5,"s":[261,88],"i":{"x":[0.613,1],"y":[0.589,1]},"o":{"x":[0.321,0],"y":[0.033,0]}},{"t":8.196,"s":[183.801,88],"i":{"x":[0.591,1],"y":[0.993,1]},"o":{"x":[0.319,0],"y":[0.678,0]}},{"t":8.886,"s":[145.137,88],"i":{"x":[0.447,1],"y":[0.987,1]},"o":{"x":[0.279,0],"y":[0.02,0]}},{"t":10.272,"s":[163.515,88],"i":{"x":[0.442,1],"y":[0.994,1]},"o":{"x":[0.279,0],"y":[0,0]}},{"t":11.676,"s":[160.601,88],"i":{"x":[0.446,1],"y":[0.987,1]},"o":{"x":[0.281,0],"y":[0.02,0]}},{"t":13.062,"s":[161.063,88],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":15,"s":[160.996,88],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":15,"s":[160.998,88],"h":1}]}},"ip":0,"op":16,"st":0},{"ind":5,"ty":4,"parent":4,"ks":{},"ip":0,"op":16,"st":0,"shapes":[{"ty":"rc","p":{"a":0,"k":[48.5,67.5]},"r":{"a":0,"k":20},"s":{"a":0,"k":[97,135]}},{"ty":"fl","c":{"a":0,"k":[1,1,1]},"o":{"a":0,"k":100}}]},{"ind":4,"ty":3,"parent":1,"ks":{"a":{"a":0,"k":[48.5,67.5]},"p":{"a":1,"k":[{"t":0,"s":[108.5,155.5],"i":{"x":[0.613,1],"y":[0.589,1]},"o":{"x":[0.321,0],"y":[0.033,0]}},{"t":0.696,"s":[147.1,155.5],"i":{"x":[0.591,1],"y":[0.993,1]},"o":{"x":[0.319,0],"y":[0.678,0]}},{"t":1.386,"s":[166.432,155.5],"i":{"x":[0.447,1],"y":[0.987,1]},"o":{"x":[0.279,0],"y":[0.02,0]}},{"t":2.772,"s":[157.242,155.5],"i":{"x":[0.442,1],"y":[0.994,1]},"o":{"x":[0.279,0],"y":[0,0]}},{"t":4.176,"s":[158.7,155.5],"i":{"x":[0.446,1],"y":[0.987,1]},"o":{"x":[0.281,0],"y":[0.02,0]}},{"t":5.562,"s":[158.468,155.5],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":7.5,"s":[158.502,155.5],"h":1},{"t":7.5,"s":[158.5,155.5],"i":{"x":[0.613,1],"y":[0.589,1]},"o":{"x":[0.321,0],"y":[0.033,0]}},{"t":8.196,"s":[81.301,155.5],"i":{"x":[0.591,1],"y":[0.993,1]},"o":{"x":[0.319,0],"y":[0.678,0]}},{"t":8.886,"s":[42.637,155.5],"i":{"x":[0.447,1],"y":[0.987,1]},"o":{"x":[0.279,0],"y":[0.02,0]}},{"t":10.272,"s":[61.015,155.5],"i":{"x":[0.442,1],"y":[0.994,1]},"o":{"x":[0.279,0],"y":[0,0]}},{"t":11.676,"s":[58.101,155.5],"i":{"x":[0.446,1],"y":[0.987,1]},"o":{"x":[0.281,0],"y":[0.02,0]}},{"t":13.062,"s":[58.563,155.5],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":15,"s":[58.496,155.5],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":15,"s":[58.498,155.5],"h":1}]}},"ip":0,"op":16,"st":0},{"ind":1,"ty":3,"parent":0,"ks":{},"ip":0,"op":16,"st":0},{"ind":6,"ty":4,"parent":0,"ks":{},"ip":0,"op":16,"st":0,"shapes":[{"ty":"rc","p":{"a":0,"k":[184,224]},"r":{"a":0,"k":0},"s":{"a":0,"k":[368,448]}},{"ty":"fl","c":{"a":0,"k":[0,0,0]},"o":{"a":0,"k":100}}]},{"ind":0,"ty":3,"ks":{},"ip":0,"op":16,"st":0}],"meta":{"g":"https://jitter.video"},"op":15,"v":"5.7.4","w":368}
|
||||
147
main/main.c
147
main/main.c
@@ -21,13 +21,17 @@
|
||||
*/
|
||||
|
||||
#include "drivers/display_driver.h"
|
||||
#include "drivers/nvs_driver.h"
|
||||
#include "drivers/touch_driver.h"
|
||||
#include "emotion-engine/emotion_manager.h"
|
||||
#include "emotion-engine/shake/shake_emotion.h"
|
||||
#include "sensors/shake_detector.h"
|
||||
#include "ui/calibration_screen.h"
|
||||
#include "ui/loading_anim.h"
|
||||
#include "ui/splash_screen.h"
|
||||
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
@@ -36,37 +40,75 @@ static const char *TAG = "main";
|
||||
// ----------------------------------------------------------------------------
|
||||
// Shake Detection Task
|
||||
// Polls the accelerometer for shake events and triggers emotions.
|
||||
// Implements 2-second holdoff after shaking stops before returning to idle.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Holdoff time after shaking stops before transitioning (milliseconds)
|
||||
#define SHAKE_HOLDOFF_MS 500
|
||||
|
||||
static void shakeTask(void *arg) {
|
||||
ESP_LOGI(TAG, "Shake detection task started");
|
||||
|
||||
bool isShakingActive = false;
|
||||
bool isTransitioning = false;
|
||||
uint32_t shakeStoppedTime = 0;
|
||||
|
||||
while (1) {
|
||||
ShakeEvent event = shakeDetectorUpdate();
|
||||
uint32_t now = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
|
||||
if (event != SHAKE_NONE) {
|
||||
// Map shake events to emotions
|
||||
EmotionType emotion = EMOTION_IDLE;
|
||||
switch (event) {
|
||||
case SHAKE_SURPRISED:
|
||||
emotion = EMOTION_SURPRISED;
|
||||
break;
|
||||
case SHAKE_SAD:
|
||||
emotion = EMOTION_SAD;
|
||||
break;
|
||||
case SHAKE_ANGRY:
|
||||
emotion = EMOTION_ANGRY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
// Handle transition completion (polling shakeEmotionUpdate)
|
||||
if (isTransitioning) {
|
||||
bool transitionComplete = false;
|
||||
if (displayDriverLock(100)) {
|
||||
transitionComplete = shakeEmotionUpdate();
|
||||
displayDriverUnlock();
|
||||
}
|
||||
|
||||
if (emotion != EMOTION_IDLE) {
|
||||
// Acquire LVGL lock before modifying emotions
|
||||
if (displayDriverLock(100)) {
|
||||
emotionManagerSetEmotion(emotion);
|
||||
if (transitionComplete) {
|
||||
ESP_LOGI(TAG, "Shake transition complete, returning to idle");
|
||||
if (displayDriverLock(500)) {
|
||||
emotionManagerSetEmotion(EMOTION_IDLE);
|
||||
displayDriverUnlock();
|
||||
}
|
||||
isTransitioning = false;
|
||||
isShakingActive = false;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event == SHAKE_ACTIVE) {
|
||||
// Start or continue shaking animation
|
||||
if (!isShakingActive) {
|
||||
ESP_LOGI(TAG, "Shake event: Starting shaking animation");
|
||||
if (displayDriverLock(500)) {
|
||||
emotionManagerSetEmotion(EMOTION_SHAKING);
|
||||
displayDriverUnlock();
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Failed to acquire lock for SHAKING");
|
||||
}
|
||||
isShakingActive = true;
|
||||
}
|
||||
// Reset stopped time while actively shaking
|
||||
shakeStoppedTime = 0;
|
||||
} else if (event == SHAKE_STOPPED) {
|
||||
// Shaking just stopped, start holdoff timer
|
||||
ESP_LOGI(TAG, "Shake event: Stopped, starting holdoff");
|
||||
shakeStoppedTime = now;
|
||||
} else if (isShakingActive && shakeStoppedTime != 0) {
|
||||
// Check if holdoff period has elapsed
|
||||
if (now - shakeStoppedTime >= SHAKE_HOLDOFF_MS) {
|
||||
ESP_LOGI(TAG, "Holdoff complete, starting shake-stop transition");
|
||||
if (displayDriverLock(500)) {
|
||||
emotionManagerSetEmotion(EMOTION_SHAKE_STOPPING);
|
||||
displayDriverUnlock();
|
||||
isTransitioning = true;
|
||||
shakeStoppedTime = 0;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Failed to acquire lock for SHAKE_STOPPING");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,12 +121,17 @@ static void shakeTask(void *arg) {
|
||||
// Application Entry Point
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void app_main(void) {
|
||||
ESP_LOGI(TAG, "Starting iroBot Display System");
|
||||
// ----------------------------------------------------------------------------
|
||||
// Main UI Task
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void ui_entry_task(void *arg) {
|
||||
ESP_LOGI(TAG, "UI Entry Task started");
|
||||
|
||||
// Initialize display subsystem (I2C, SPI, LCD, LVGL)
|
||||
if (!displayDriverInit()) {
|
||||
ESP_LOGE(TAG, "Display initialization failed");
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -98,7 +145,48 @@ void app_main(void) {
|
||||
ESP_LOGW(TAG, "Shake detector initialization failed (continuing)");
|
||||
}
|
||||
|
||||
// Show splash screen (blocks for SPLASH_SCREEN_DURATION_MS)
|
||||
// Initialize NVS (Critical for first boot check)
|
||||
nvsDriverInit();
|
||||
|
||||
// Check for first boot experience
|
||||
bool isFirstBoot = nvsDriverIsFirstBoot();
|
||||
if (isFirstBoot) {
|
||||
if (displayDriverLock(-1)) {
|
||||
ESP_LOGI(TAG, "First boot detected! Showing loading animation.");
|
||||
loadingAnimStart();
|
||||
displayDriverUnlock();
|
||||
|
||||
// Allow animation to play
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
if (displayDriverLock(-1)) {
|
||||
loadingAnimStop();
|
||||
displayDriverUnlock();
|
||||
}
|
||||
}
|
||||
|
||||
// Show IMU calibration screen
|
||||
if (displayDriverLock(-1)) {
|
||||
ESP_LOGI(TAG, "Showing IMU calibration screen");
|
||||
calibrationScreenShow();
|
||||
displayDriverUnlock();
|
||||
}
|
||||
|
||||
// Mark device as provisioned after successful calibration
|
||||
nvsDriverMarkProvisioned();
|
||||
} else {
|
||||
// Normal boot - load calibration from NVS
|
||||
float calX, calY, calZ;
|
||||
if (nvsDriverLoadImuCalibration(&calX, &calY, &calZ)) {
|
||||
ESP_LOGI(TAG, "Applying stored IMU calibration");
|
||||
shakeDetectorSetBaseline(calX, calY, calZ);
|
||||
} else {
|
||||
ESP_LOGW(TAG,
|
||||
"No stored IMU calibration found, using runtime calibration");
|
||||
}
|
||||
}
|
||||
|
||||
// Show standard splash screen
|
||||
if (displayDriverLock(-1)) {
|
||||
ESP_LOGI(TAG, "Showing splash screen");
|
||||
splashScreenShow();
|
||||
@@ -108,10 +196,11 @@ void app_main(void) {
|
||||
// Initialize emotion engine
|
||||
if (!emotionManagerInit()) {
|
||||
ESP_LOGE(TAG, "Emotion manager initialization failed");
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// Start emotion engine (begins idle animation with natural blink)
|
||||
// Start emotion engine
|
||||
if (displayDriverLock(-1)) {
|
||||
ESP_LOGI(TAG, "Starting emotion engine");
|
||||
emotionManagerStart();
|
||||
@@ -122,4 +211,14 @@ void app_main(void) {
|
||||
xTaskCreate(shakeTask, "shake_task", 4096, NULL, 5, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "iroBot Display System initialized successfully");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
ESP_LOGI(TAG, "Starting iroBot Display System (Main)");
|
||||
|
||||
// Spawn a dedicated task with larger stack for UI/App logic
|
||||
// Default main stack might be too small for LVGL recursive calls
|
||||
// Using 8KB stack size to be safe
|
||||
xTaskCreate(ui_entry_task, "ui_entry", 8192, NULL, 5, NULL);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
static const char *TAG = "shake_detector";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -24,11 +23,14 @@ static const char *TAG = "shake_detector";
|
||||
|
||||
static SensorQMI8658 qmiSensor;
|
||||
|
||||
static uint32_t lastTriggerTime = 0;
|
||||
static float lastAccelX = 0, lastAccelY = 0, lastAccelZ = 0;
|
||||
static float baselineX = 0, baselineY = 0, baselineZ = 0;
|
||||
static bool baselineReady = false;
|
||||
|
||||
// Continuous shake detection state
|
||||
static uint32_t shakeCounter = 0;
|
||||
static bool isShaking = false;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Helper Functions
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -160,37 +162,38 @@ extern "C" ShakeEvent shakeDetectorUpdate(void) {
|
||||
// Periodic logging for monitoring
|
||||
static uint32_t lastLogTime = 0;
|
||||
if (now - lastLogTime > 1000) {
|
||||
ESP_LOGI(TAG, "ACCEL: x=%+.3f y=%+.3f z=%+.3f | deviation=%.3f", x, y, z,
|
||||
deviation);
|
||||
ESP_LOGI(TAG, "ACCEL: dev=%.3f counter=%lu shaking=%d", deviation,
|
||||
(unsigned long)shakeCounter, isShaking);
|
||||
lastLogTime = now;
|
||||
}
|
||||
|
||||
// Debounce check
|
||||
if (now - lastTriggerTime < SHAKE_DEBOUNCE_MS) {
|
||||
return SHAKE_NONE;
|
||||
// Continuous shake detection - track consecutive readings above threshold
|
||||
bool currentlyAboveThreshold = (deviation > SHAKE_ACCEL_THRESHOLD);
|
||||
|
||||
if (currentlyAboveThreshold) {
|
||||
shakeCounter++;
|
||||
|
||||
// If we've hit the threshold for continuous shake, start shaking state
|
||||
if (shakeCounter >= SHAKE_CONTINUOUS_THRESHOLD && !isShaking) {
|
||||
isShaking = true;
|
||||
ESP_LOGI(TAG, "SHAKE STARTED! (counter=%lu)",
|
||||
(unsigned long)shakeCounter);
|
||||
return SHAKE_ACTIVE;
|
||||
}
|
||||
|
||||
// Shake detection
|
||||
if (deviation > SHAKE_ACCEL_THRESHOLD) {
|
||||
ESP_LOGI(TAG, "SHAKE DETECTED! deviation=%.3f > threshold=%.3f", deviation,
|
||||
SHAKE_ACCEL_THRESHOLD);
|
||||
// If already shaking, continue reporting active
|
||||
if (isShaking) {
|
||||
return SHAKE_ACTIVE;
|
||||
}
|
||||
} else {
|
||||
// Below threshold - reset counter
|
||||
shakeCounter = 0;
|
||||
|
||||
lastTriggerTime = now;
|
||||
|
||||
// Random emotion selection
|
||||
int r = rand() % 3;
|
||||
switch (r) {
|
||||
case 0:
|
||||
ESP_LOGI(TAG, "Emotion: SURPRISED");
|
||||
return SHAKE_SURPRISED;
|
||||
case 1:
|
||||
ESP_LOGI(TAG, "Emotion: SAD");
|
||||
return SHAKE_SAD;
|
||||
case 2:
|
||||
ESP_LOGI(TAG, "Emotion: ANGRY");
|
||||
return SHAKE_ANGRY;
|
||||
default:
|
||||
return SHAKE_SURPRISED;
|
||||
// If we were shaking, now we've stopped
|
||||
if (isShaking) {
|
||||
isShaking = false;
|
||||
ESP_LOGI(TAG, "SHAKE STOPPED!");
|
||||
return SHAKE_STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,3 +214,77 @@ extern "C" bool shakeDetectorGetRawAccel(float *x, float *y, float *z) {
|
||||
lastAccelZ = *z;
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" bool shakeDetectorCalibrateBaseline(void) {
|
||||
ESP_LOGI(TAG, "Starting explicit baseline calibration...");
|
||||
|
||||
float sumX = 0, sumY = 0, sumZ = 0;
|
||||
int validSamples = 0;
|
||||
|
||||
// Collect samples for calibration
|
||||
for (int i = 0; i < SHAKE_BASELINE_SAMPLES; i++) {
|
||||
// Wait for data to be ready
|
||||
int retries = 0;
|
||||
while (!qmiSensor.getDataReady() && retries < 50) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
retries++;
|
||||
}
|
||||
|
||||
if (retries >= 50) {
|
||||
ESP_LOGW(TAG, "Timeout waiting for sensor data");
|
||||
continue;
|
||||
}
|
||||
|
||||
float x, y, z;
|
||||
if (qmiSensor.getAccelerometer(x, y, z)) {
|
||||
sumX += x;
|
||||
sumY += y;
|
||||
sumZ += z;
|
||||
validSamples++;
|
||||
ESP_LOGI(TAG, "[%d/%d] x=%+.3f y=%+.3f z=%+.3f", validSamples,
|
||||
SHAKE_BASELINE_SAMPLES, x, y, z);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(50)); // 20Hz sampling
|
||||
}
|
||||
|
||||
if (validSamples < SHAKE_BASELINE_SAMPLES / 2) {
|
||||
ESP_LOGE(TAG, "Calibration failed: only %d valid samples", validSamples);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute and set baseline
|
||||
baselineX = sumX / validSamples;
|
||||
baselineY = sumY / validSamples;
|
||||
baselineZ = sumZ / validSamples;
|
||||
baselineReady = true;
|
||||
|
||||
float magnitude = sqrtf(baselineX * baselineX + baselineY * baselineY +
|
||||
baselineZ * baselineZ);
|
||||
ESP_LOGI(TAG, "Calibration complete: x=%+.3f y=%+.3f z=%+.3f (mag: %.3f)",
|
||||
baselineX, baselineY, baselineZ, magnitude);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" void shakeDetectorSetBaseline(float x, float y, float z) {
|
||||
baselineX = x;
|
||||
baselineY = y;
|
||||
baselineZ = z;
|
||||
baselineReady = true;
|
||||
|
||||
float magnitude = sqrtf(x * x + y * y + z * z);
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"Baseline set from stored values: x=%+.3f y=%+.3f z=%+.3f (mag: %.3f)", x,
|
||||
y, z, magnitude);
|
||||
}
|
||||
|
||||
extern "C" void shakeDetectorGetBaseline(float *x, float *y, float *z) {
|
||||
if (x)
|
||||
*x = baselineX;
|
||||
if (y)
|
||||
*y = baselineY;
|
||||
if (z)
|
||||
*z = baselineZ;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ extern "C" {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Acceleration deviation threshold to detect shake (in G)
|
||||
#define SHAKE_ACCEL_THRESHOLD 0.5f
|
||||
// Set above 1G to account for gravity and require actual vigorous shaking
|
||||
#define SHAKE_ACCEL_THRESHOLD 1.3f
|
||||
|
||||
// Debounce time between shake detections (milliseconds)
|
||||
#define SHAKE_DEBOUNCE_MS 2000
|
||||
// Number of consecutive readings above threshold to confirm shake
|
||||
#define SHAKE_CONTINUOUS_THRESHOLD 10
|
||||
|
||||
// Number of samples to average for baseline calibration
|
||||
#define SHAKE_BASELINE_SAMPLES 10
|
||||
@@ -34,13 +35,12 @@ extern "C" {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Shake event types with associated emotions
|
||||
* @brief Shake event types
|
||||
*/
|
||||
typedef enum {
|
||||
SHAKE_NONE = 0, // No shake detected
|
||||
SHAKE_SURPRISED, // Quick shake - surprised emotion
|
||||
SHAKE_SAD, // Shake detected - sad emotion
|
||||
SHAKE_ANGRY // Shake detected - angry emotion
|
||||
SHAKE_ACTIVE, // Device is currently being shaken
|
||||
SHAKE_STOPPED // Shaking just stopped
|
||||
} ShakeEvent;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -79,6 +79,36 @@ ShakeEvent shakeDetectorUpdate(void);
|
||||
*/
|
||||
bool shakeDetectorGetRawAccel(float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
* @brief Perform immediate baseline calibration
|
||||
*
|
||||
* Collects multiple samples and computes the baseline average.
|
||||
* Should be called when device is on a stable, flat surface.
|
||||
*
|
||||
* @return true on successful calibration, false on failure
|
||||
*/
|
||||
bool shakeDetectorCalibrateBaseline(void);
|
||||
|
||||
/**
|
||||
* @brief Set baseline values directly
|
||||
*
|
||||
* Used to restore calibration from NVS storage.
|
||||
*
|
||||
* @param x X-axis baseline value
|
||||
* @param y Y-axis baseline value
|
||||
* @param z Z-axis baseline value
|
||||
*/
|
||||
void shakeDetectorSetBaseline(float x, float y, float z);
|
||||
|
||||
/**
|
||||
* @brief Get current baseline values
|
||||
*
|
||||
* @param x Pointer to store X-axis baseline
|
||||
* @param y Pointer to store Y-axis baseline
|
||||
* @param z Pointer to store Z-axis baseline
|
||||
*/
|
||||
void shakeDetectorGetBaseline(float *x, float *y, float *z);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
3522
main/ui/assets/fonts/Geist.c
Normal file
3522
main/ui/assets/fonts/Geist.c
Normal file
File diff suppressed because it is too large
Load Diff
25
main/ui/assets/fonts/Geist.h
Normal file
25
main/ui/assets/fonts/Geist.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @file Geist.h
|
||||
* @brief Geist font declaration for LVGL
|
||||
*
|
||||
* 48px Geist Regular font converted for LVGL usage.
|
||||
* Provides a clean, modern typeface for UI text elements.
|
||||
*/
|
||||
|
||||
#ifndef GEIST_H
|
||||
#define GEIST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
// External font declaration - defined in Geist.c
|
||||
extern const lv_font_t Geist;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GEIST_H
|
||||
174
main/ui/calibration_screen.c
Normal file
174
main/ui/calibration_screen.c
Normal file
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* @file calibration_screen.c
|
||||
* @brief IMU calibration screen implementation
|
||||
*
|
||||
* This module provides the first-boot calibration experience. It displays
|
||||
* a full-screen UI with the Geist font prompting the user to place the
|
||||
* device on a flat surface and tap to calibrate. The calibration captures
|
||||
* the IMU baseline and stores it to NVS for persistence.
|
||||
*/
|
||||
|
||||
#include "ui/calibration_screen.h"
|
||||
|
||||
#include "drivers/display_driver.h"
|
||||
#include "drivers/nvs_driver.h"
|
||||
#include "sensors/shake_detector.h"
|
||||
#include "ui/assets/fonts/Geist.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
static const char *TAG = "calibration_screen";
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Private State
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static volatile bool tapDetected = false;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Private Functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Touch event callback for detecting user tap
|
||||
*/
|
||||
static void onScreenTap(lv_event_t *event) {
|
||||
lv_event_code_t code = lv_event_get_code(event);
|
||||
if (code == LV_EVENT_CLICKED) {
|
||||
tapDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Public API Implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool calibrationScreenShow(void) {
|
||||
ESP_LOGI(TAG, "Showing calibration screen");
|
||||
|
||||
tapDetected = false;
|
||||
|
||||
// Create calibration screen
|
||||
lv_obj_t *calibScreen = lv_obj_create(NULL);
|
||||
if (calibScreen == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create calibration screen");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Black background with no border
|
||||
lv_obj_set_style_bg_color(calibScreen, lv_color_black(),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_opa(calibScreen, LV_OPA_COVER,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(calibScreen, 0,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(calibScreen, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
|
||||
// Make the screen clickable to detect taps
|
||||
lv_obj_add_flag(calibScreen, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_add_event_cb(calibScreen, onScreenTap, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
// Main instruction text - minimalist white on black
|
||||
lv_obj_t *mainLabel = lv_label_create(calibScreen);
|
||||
lv_label_set_text(mainLabel, "Place device on\na flat surface");
|
||||
lv_obj_set_style_text_font(mainLabel, &Geist,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_color(mainLabel, lv_color_white(),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_align(mainLabel, LV_TEXT_ALIGN_CENTER,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_line_space(mainLabel, 12,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_align(mainLabel, LV_ALIGN_CENTER, 0, -60);
|
||||
|
||||
// Sub instruction text - subtle gray
|
||||
lv_obj_t *subLabel = lv_label_create(calibScreen);
|
||||
lv_label_set_text(subLabel, "Tap to calibrate");
|
||||
lv_obj_set_style_text_font(subLabel, &Geist, LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_color(subLabel, lv_color_make(100, 100, 100),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_align(subLabel, LV_TEXT_ALIGN_CENTER,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_align(subLabel, LV_ALIGN_CENTER, 0, 80);
|
||||
|
||||
// Load and display the calibration screen
|
||||
lv_scr_load(calibScreen);
|
||||
lv_refr_now(NULL);
|
||||
|
||||
ESP_LOGI(TAG, "Waiting for user tap...");
|
||||
|
||||
// Release the display lock so LVGL timer handler can process touch events
|
||||
displayDriverUnlock();
|
||||
|
||||
// Wait for tap - LVGL timer handler runs in background task
|
||||
while (!tapDetected) {
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
}
|
||||
|
||||
// Reacquire lock for UI updates
|
||||
displayDriverLock(-1);
|
||||
|
||||
ESP_LOGI(TAG, "Tap detected, starting calibration...");
|
||||
|
||||
// Update UI to show calibrating state
|
||||
lv_label_set_text(mainLabel, "Calibrating...");
|
||||
lv_obj_align(mainLabel, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_flag(subLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_refr_now(NULL);
|
||||
|
||||
// Release lock during calibration (sensor reads)
|
||||
displayDriverUnlock();
|
||||
|
||||
// Perform calibration
|
||||
bool calibSuccess = shakeDetectorCalibrateBaseline();
|
||||
|
||||
// Reacquire lock for final UI updates
|
||||
displayDriverLock(-1);
|
||||
|
||||
if (calibSuccess) {
|
||||
// Get the calibrated baseline values
|
||||
float baseX, baseY, baseZ;
|
||||
shakeDetectorGetBaseline(&baseX, &baseY, &baseZ);
|
||||
|
||||
ESP_LOGI(TAG, "Calibration complete: x=%.3f y=%.3f z=%.3f", baseX, baseY,
|
||||
baseZ);
|
||||
|
||||
// Store to NVS
|
||||
if (nvsDriverSaveImuCalibration(baseX, baseY, baseZ)) {
|
||||
ESP_LOGI(TAG, "Calibration saved to NVS");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Failed to save calibration to NVS");
|
||||
}
|
||||
|
||||
// Show success
|
||||
lv_label_set_text(mainLabel, "Done!");
|
||||
lv_refr_now(NULL);
|
||||
|
||||
displayDriverUnlock();
|
||||
vTaskDelay(pdMS_TO_TICKS(800));
|
||||
displayDriverLock(-1);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Calibration failed");
|
||||
lv_label_set_text(mainLabel, "Calibration failed");
|
||||
lv_refr_now(NULL);
|
||||
|
||||
displayDriverUnlock();
|
||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||
displayDriverLock(-1);
|
||||
}
|
||||
|
||||
// Clean up - create blank screen before deleting calibration screen
|
||||
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);
|
||||
}
|
||||
lv_obj_del(calibScreen);
|
||||
|
||||
ESP_LOGI(TAG, "Calibration screen complete");
|
||||
return calibSuccess;
|
||||
}
|
||||
41
main/ui/calibration_screen.h
Normal file
41
main/ui/calibration_screen.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file calibration_screen.h
|
||||
* @brief IMU calibration screen for first-boot experience
|
||||
*
|
||||
* Displays a full-screen UI prompting the user to place the device
|
||||
* on a flat surface and tap to calibrate the IMU. Calibration values
|
||||
* are stored in NVS for use on subsequent boots.
|
||||
*/
|
||||
|
||||
#ifndef CALIBRATION_SCREEN_H
|
||||
#define CALIBRATION_SCREEN_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Public API
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Display the calibration screen and perform IMU calibration
|
||||
*
|
||||
* This is a blocking function that:
|
||||
* 1. Displays instructions to place device on flat surface
|
||||
* 2. Waits for user tap
|
||||
* 3. Performs IMU baseline calibration
|
||||
* 4. Stores calibration data to NVS
|
||||
* 5. Cleans up and returns
|
||||
*
|
||||
* @return true on successful calibration, false on failure
|
||||
*/
|
||||
bool calibrationScreenShow(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CALIBRATION_SCREEN_H
|
||||
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;
|
||||
}
|
||||
42
main/ui/loading_anim.h
Normal file
42
main/ui/loading_anim.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file loading_anim.h
|
||||
* @brief Minimalist loading animation
|
||||
*
|
||||
* Displays a simple 3-dots animation using LVGL primitive objects.
|
||||
* Used primarily for the first-boot experience.
|
||||
*/
|
||||
|
||||
#ifndef LOADING_ANIM_H
|
||||
#define LOADING_ANIM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Public API
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Start the loading animation
|
||||
*
|
||||
* Creates a modal screen with a 3-dot animation.
|
||||
* This function blocks the caller for the specified duration?
|
||||
* No, it typically runs async, but for splash/boot it might be blocking.
|
||||
*
|
||||
* @param duration_ms Time to show the animation (0 for indefinite)
|
||||
*/
|
||||
void loadingAnimStart(void);
|
||||
|
||||
/**
|
||||
* @brief Stop the loading animation and clean up
|
||||
*/
|
||||
void loadingAnimStop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LOADING_ANIM_H
|
||||
@@ -77,6 +77,17 @@ typedef struct {
|
||||
bool valid;
|
||||
} LottieLayer;
|
||||
|
||||
/**
|
||||
* Cached shape bounds for dirty rect optimization
|
||||
*/
|
||||
typedef struct {
|
||||
lv_coord_t x1, y1, x2, y2; // Bounding box corners
|
||||
bool valid;
|
||||
} ShapeBounds;
|
||||
|
||||
// Maximum cached shapes for dirty rect tracking
|
||||
#define LOTTIE_MAX_CACHED_SHAPES (LOTTIE_MAX_LAYERS * LOTTIE_MAX_SHAPES)
|
||||
|
||||
/**
|
||||
* Main player state structure
|
||||
*/
|
||||
@@ -85,6 +96,7 @@ struct lottie_player_t {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
float framerate;
|
||||
float nativeFramerate; // Original framerate from JSON
|
||||
uint32_t totalFrames;
|
||||
uint32_t inPoint;
|
||||
uint32_t outPoint;
|
||||
@@ -107,6 +119,11 @@ struct lottie_player_t {
|
||||
lv_obj_t *canvas;
|
||||
lv_color_t *canvasBuffer;
|
||||
lv_timer_t *animTimer;
|
||||
|
||||
// Dirty rect optimization - cache previous frame shape bounds
|
||||
ShapeBounds prevBounds[LOTTIE_MAX_CACHED_SHAPES];
|
||||
int prevBoundsCount;
|
||||
bool firstRender; // Skip dirty optimization on first frame
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -162,6 +179,8 @@ lottie_player_handle_t lottieCreateFromData(lv_obj_t *parent,
|
||||
handle->playing = false;
|
||||
handle->loop = true;
|
||||
handle->currentFrame = 0;
|
||||
handle->firstRender = true;
|
||||
handle->prevBoundsCount = 0;
|
||||
|
||||
// Parse animation data
|
||||
parseAnimation(handle, root);
|
||||
@@ -262,6 +281,33 @@ void lottieSetLoop(lottie_player_handle_t handle, bool loop) {
|
||||
handle->loop = loop;
|
||||
}
|
||||
|
||||
void lottieDisableNaturalBlink(lottie_player_handle_t handle) {
|
||||
if (!handle)
|
||||
return;
|
||||
|
||||
// Delete the blink timer if it exists
|
||||
if (handle->blinkTimer) {
|
||||
lv_timer_del(handle->blinkTimer);
|
||||
handle->blinkTimer = NULL;
|
||||
}
|
||||
handle->naturalBlinkMode = false;
|
||||
ESP_LOGI(TAG, "Natural blink mode disabled");
|
||||
}
|
||||
|
||||
void lottiePauseNaturalBlink(lottie_player_handle_t handle) {
|
||||
if (!handle || !handle->blinkTimer)
|
||||
return;
|
||||
lv_timer_pause(handle->blinkTimer);
|
||||
ESP_LOGI(TAG, "Natural blink timer paused");
|
||||
}
|
||||
|
||||
void lottieResumeNaturalBlink(lottie_player_handle_t handle) {
|
||||
if (!handle || !handle->blinkTimer)
|
||||
return;
|
||||
lv_timer_resume(handle->blinkTimer);
|
||||
ESP_LOGI(TAG, "Natural blink timer resumed");
|
||||
}
|
||||
|
||||
bool lottieIsPlaying(lottie_player_handle_t handle) {
|
||||
if (!handle)
|
||||
return false;
|
||||
@@ -290,6 +336,15 @@ void lottieSetFrame(lottie_player_handle_t handle, uint32_t frame) {
|
||||
renderFrame(handle);
|
||||
}
|
||||
|
||||
void lottieSetSpeed(lottie_player_handle_t handle, float speed) {
|
||||
if (!handle || speed <= 0)
|
||||
return;
|
||||
// Use native framerate as base and apply speed multiplier
|
||||
handle->framerate = handle->nativeFramerate * speed;
|
||||
ESP_LOGI(TAG, "Playback speed set to %.1fx (%.1f fps)", speed,
|
||||
handle->framerate);
|
||||
}
|
||||
|
||||
void lottieDestroy(lottie_player_handle_t handle) {
|
||||
if (!handle)
|
||||
return;
|
||||
@@ -331,6 +386,8 @@ static void parseAnimation(lottie_player_handle_t handle, const cJSON *root) {
|
||||
item = cJSON_GetObjectItem(root, "fr");
|
||||
if (item && cJSON_IsNumber(item)) {
|
||||
handle->framerate = (float)item->valuedouble;
|
||||
handle->nativeFramerate =
|
||||
handle->framerate; // Store native before any modifications
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(root, "ip");
|
||||
@@ -718,13 +775,143 @@ static void drawRoundedRect(lottie_player_handle_t handle, lv_coord_t x,
|
||||
}
|
||||
|
||||
static void renderFrame(lottie_player_handle_t handle) {
|
||||
static bool firstFrameLogged = false;
|
||||
|
||||
lv_canvas_fill_bg(handle->canvas, lv_color_black(), LV_OPA_COVER);
|
||||
|
||||
float frame = handle->currentFrame + handle->inPoint;
|
||||
|
||||
// Render layers in reverse order (last layer = bottom)
|
||||
// Combined dirty area for partial invalidation
|
||||
lv_area_t dirtyArea;
|
||||
bool hasDirty = false;
|
||||
|
||||
// Helper macro to expand dirty area (parameters named differently to avoid
|
||||
// conflict)
|
||||
#define EXPAND_DIRTY(_ax1, _ay1, _ax2, _ay2) \
|
||||
do { \
|
||||
if (!hasDirty) { \
|
||||
dirtyArea.x1 = (_ax1); \
|
||||
dirtyArea.y1 = (_ay1); \
|
||||
dirtyArea.x2 = (_ax2); \
|
||||
dirtyArea.y2 = (_ay2); \
|
||||
hasDirty = true; \
|
||||
} else { \
|
||||
if ((_ax1) < dirtyArea.x1) \
|
||||
dirtyArea.x1 = (_ax1); \
|
||||
if ((_ay1) < dirtyArea.y1) \
|
||||
dirtyArea.y1 = (_ay1); \
|
||||
if ((_ax2) > dirtyArea.x2) \
|
||||
dirtyArea.x2 = (_ax2); \
|
||||
if ((_ay2) > dirtyArea.y2) \
|
||||
dirtyArea.y2 = (_ay2); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Collect current frame shape bounds
|
||||
ShapeBounds currBounds[LOTTIE_MAX_CACHED_SHAPES];
|
||||
int currCount = 0;
|
||||
|
||||
// First pass: calculate all current shape bounds
|
||||
for (int i = handle->layerCount - 1; i >= 0; i--) {
|
||||
LottieLayer *layer = &handle->layers[i];
|
||||
if (!layer->valid || layer->type != 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float offsetX = 0, offsetY = 0;
|
||||
getLayerTransform(handle, layer, frame, &offsetX, &offsetY);
|
||||
|
||||
for (int s = 0; s < layer->shapeCount; s++) {
|
||||
LottieRoundedRect *rect = &layer->shapes[s];
|
||||
if (!rect->valid || currCount >= LOTTIE_MAX_CACHED_SHAPES)
|
||||
continue;
|
||||
|
||||
float px = interpolateProperty(&rect->position, frame, 0) + offsetX;
|
||||
float py = interpolateProperty(&rect->position, frame, 1) + offsetY;
|
||||
float w = interpolateProperty(&rect->size, frame, 0);
|
||||
float h = interpolateProperty(&rect->size, frame, 1);
|
||||
|
||||
if (w > 0 && h > 0) {
|
||||
currBounds[currCount].x1 = (lv_coord_t)(px - w / 2);
|
||||
currBounds[currCount].y1 = (lv_coord_t)(py - h / 2);
|
||||
currBounds[currCount].x2 = (lv_coord_t)(px + w / 2);
|
||||
currBounds[currCount].y2 = (lv_coord_t)(py + h / 2);
|
||||
currBounds[currCount].valid = true;
|
||||
currCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On first render, do full clear and full invalidate
|
||||
if (handle->firstRender) {
|
||||
lv_canvas_fill_bg(handle->canvas, lv_color_black(), LV_OPA_COVER);
|
||||
handle->firstRender = false;
|
||||
lv_obj_invalidate(handle->canvas);
|
||||
|
||||
// Cache bounds for next frame
|
||||
for (int i = 0; i < currCount && i < LOTTIE_MAX_CACHED_SHAPES; i++) {
|
||||
handle->prevBounds[i] = currBounds[i];
|
||||
}
|
||||
handle->prevBoundsCount = currCount;
|
||||
|
||||
// Draw shapes
|
||||
for (int i = handle->layerCount - 1; i >= 0; i--) {
|
||||
LottieLayer *layer = &handle->layers[i];
|
||||
if (!layer->valid || layer->type != 4)
|
||||
continue;
|
||||
float offsetX = 0, offsetY = 0;
|
||||
getLayerTransform(handle, layer, frame, &offsetX, &offsetY);
|
||||
for (int s = 0; s < layer->shapeCount; s++) {
|
||||
LottieRoundedRect *rect = &layer->shapes[s];
|
||||
if (!rect->valid)
|
||||
continue;
|
||||
float px = interpolateProperty(&rect->position, frame, 0) + offsetX;
|
||||
float py = interpolateProperty(&rect->position, frame, 1) + offsetY;
|
||||
float w = interpolateProperty(&rect->size, frame, 0);
|
||||
float h = interpolateProperty(&rect->size, frame, 1);
|
||||
float r = interpolateProperty(&rect->cornerRadius, frame, 0);
|
||||
if (w > 0 && h > 0) {
|
||||
drawRoundedRect(handle, (lv_coord_t)px, (lv_coord_t)py, (lv_coord_t)w,
|
||||
(lv_coord_t)h, (lv_coord_t)r, rect->fillColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear previous shape positions and track dirty areas
|
||||
lv_draw_rect_dsc_t clearDsc;
|
||||
lv_draw_rect_dsc_init(&clearDsc);
|
||||
clearDsc.bg_color = lv_color_black();
|
||||
clearDsc.bg_opa = LV_OPA_COVER;
|
||||
clearDsc.radius = 0;
|
||||
clearDsc.border_width = 0;
|
||||
|
||||
for (int i = 0; i < handle->prevBoundsCount; i++) {
|
||||
if (!handle->prevBounds[i].valid)
|
||||
continue;
|
||||
|
||||
ShapeBounds *prev = &handle->prevBounds[i];
|
||||
|
||||
// Check if shape moved
|
||||
bool needsClear = true;
|
||||
if (i < currCount && currBounds[i].valid) {
|
||||
ShapeBounds *curr = &currBounds[i];
|
||||
if (prev->x1 == curr->x1 && prev->y1 == curr->y1 &&
|
||||
prev->x2 == curr->x2 && prev->y2 == curr->y2) {
|
||||
needsClear = false; // Shape didn't move
|
||||
}
|
||||
}
|
||||
|
||||
if (needsClear) {
|
||||
lv_coord_t pw = prev->x2 - prev->x1;
|
||||
lv_coord_t ph = prev->y2 - prev->y1;
|
||||
if (pw > 0 && ph > 0) {
|
||||
lv_canvas_draw_rect(handle->canvas, prev->x1, prev->y1, pw, ph,
|
||||
&clearDsc);
|
||||
EXPAND_DIRTY(prev->x1, prev->y1, prev->x2, prev->y2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw current shapes and track dirty areas
|
||||
int shapeIdx = 0;
|
||||
for (int i = handle->layerCount - 1; i >= 0; i--) {
|
||||
LottieLayer *layer = &handle->layers[i];
|
||||
if (!layer->valid || layer->type != 4) {
|
||||
@@ -739,32 +926,60 @@ static void renderFrame(lottie_player_handle_t handle) {
|
||||
if (!rect->valid)
|
||||
continue;
|
||||
|
||||
float px = interpolateProperty(&rect->position, frame, 0);
|
||||
float py = interpolateProperty(&rect->position, frame, 1);
|
||||
float px = interpolateProperty(&rect->position, frame, 0) + offsetX;
|
||||
float py = interpolateProperty(&rect->position, frame, 1) + offsetY;
|
||||
float w = interpolateProperty(&rect->size, frame, 0);
|
||||
float h = interpolateProperty(&rect->size, frame, 1);
|
||||
float r = interpolateProperty(&rect->cornerRadius, frame, 0);
|
||||
|
||||
px += offsetX;
|
||||
py += offsetY;
|
||||
|
||||
if (!firstFrameLogged) {
|
||||
ESP_LOGI(TAG, "Layer %d shape %d: pos=(%.1f,%.1f) size=(%.1f,%.1f)",
|
||||
layer->index, s, px, py, w, h);
|
||||
}
|
||||
|
||||
if (w > 0 && h > 0) {
|
||||
lv_coord_t cx1 = (lv_coord_t)(px - w / 2);
|
||||
lv_coord_t cy1 = (lv_coord_t)(py - h / 2);
|
||||
lv_coord_t cx2 = (lv_coord_t)(px + w / 2);
|
||||
lv_coord_t cy2 = (lv_coord_t)(py + h / 2);
|
||||
|
||||
drawRoundedRect(handle, (lv_coord_t)px, (lv_coord_t)py, (lv_coord_t)w,
|
||||
(lv_coord_t)h, (lv_coord_t)r, rect->fillColor);
|
||||
|
||||
// Check if this shape moved from previous position
|
||||
if (shapeIdx < handle->prevBoundsCount &&
|
||||
handle->prevBounds[shapeIdx].valid) {
|
||||
ShapeBounds *prev = &handle->prevBounds[shapeIdx];
|
||||
if (cx1 != prev->x1 || cy1 != prev->y1 || cx2 != prev->x2 ||
|
||||
cy2 != prev->y2) {
|
||||
EXPAND_DIRTY(cx1, cy1, cx2, cy2);
|
||||
}
|
||||
} else {
|
||||
// New shape
|
||||
EXPAND_DIRTY(cx1, cy1, cx2, cy2);
|
||||
}
|
||||
}
|
||||
shapeIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!firstFrameLogged) {
|
||||
firstFrameLogged = true;
|
||||
// Cache current bounds for next frame
|
||||
for (int i = 0; i < currCount && i < LOTTIE_MAX_CACHED_SHAPES; i++) {
|
||||
handle->prevBounds[i] = currBounds[i];
|
||||
}
|
||||
handle->prevBoundsCount = currCount;
|
||||
|
||||
// Partial invalidation - only refresh the dirty area via DMA
|
||||
if (hasDirty) {
|
||||
// Clamp to canvas bounds
|
||||
if (dirtyArea.x1 < 0)
|
||||
dirtyArea.x1 = 0;
|
||||
if (dirtyArea.y1 < 0)
|
||||
dirtyArea.y1 = 0;
|
||||
if (dirtyArea.x2 >= handle->width)
|
||||
dirtyArea.x2 = handle->width - 1;
|
||||
if (dirtyArea.y2 >= handle->height)
|
||||
dirtyArea.y2 = handle->height - 1;
|
||||
|
||||
lv_obj_invalidate_area(handle->canvas, &dirtyArea);
|
||||
}
|
||||
|
||||
lv_obj_invalidate(handle->canvas);
|
||||
#undef EXPAND_DIRTY
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -95,6 +95,35 @@ void lottieStop(lottie_player_handle_t handle);
|
||||
*/
|
||||
void lottieSetLoop(lottie_player_handle_t handle, bool loop);
|
||||
|
||||
/**
|
||||
* @brief Disable natural blink mode
|
||||
*
|
||||
* By default, all animations enable natural blink mode. Call this
|
||||
* to disable it for non-blink animations like shake.
|
||||
*
|
||||
* @param handle Handle to the Lottie player instance
|
||||
*/
|
||||
void lottieDisableNaturalBlink(lottie_player_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Pause the natural blink timer
|
||||
*
|
||||
* Temporarily stops the blink timer without disabling natural blink mode.
|
||||
* Use lottieResumeNaturalBlink to resume.
|
||||
*
|
||||
* @param handle Handle to the Lottie player instance
|
||||
*/
|
||||
void lottiePauseNaturalBlink(lottie_player_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Resume the natural blink timer
|
||||
*
|
||||
* Resumes the blink timer that was paused with lottiePauseNaturalBlink.
|
||||
*
|
||||
* @param handle Handle to the Lottie player instance
|
||||
*/
|
||||
void lottieResumeNaturalBlink(lottie_player_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Check if animation is currently playing
|
||||
*
|
||||
@@ -119,6 +148,14 @@ uint32_t lottieGetCurrentFrame(lottie_player_handle_t handle);
|
||||
*/
|
||||
uint32_t lottieGetTotalFrames(lottie_player_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Set the playback speed multiplier
|
||||
*
|
||||
* @param handle Handle to the Lottie player instance
|
||||
* @param speed Speed multiplier (1.0 = native, 2.0 = 2x speed, etc.)
|
||||
*/
|
||||
void lottieSetSpeed(lottie_player_handle_t handle, float speed);
|
||||
|
||||
/**
|
||||
* @brief Set the current frame manually
|
||||
*
|
||||
|
||||
@@ -27,6 +27,11 @@ void splashScreenShow(void) {
|
||||
|
||||
// Create a temporary screen for the splash
|
||||
lv_obj_t *splashScreen = lv_obj_create(NULL);
|
||||
if (splashScreen == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create splash screen object");
|
||||
return;
|
||||
}
|
||||
|
||||
lv_obj_set_style_bg_color(splashScreen, lv_color_black(),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_opa(splashScreen, LV_OPA_COVER,
|
||||
@@ -34,6 +39,11 @@ void splashScreenShow(void) {
|
||||
|
||||
// Create and center the logo image
|
||||
lv_obj_t *logoImage = lv_img_create(splashScreen);
|
||||
if (logoImage == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create logo image object");
|
||||
lv_obj_del(splashScreen);
|
||||
return;
|
||||
}
|
||||
lv_img_set_src(logoImage, &logoIro);
|
||||
lv_obj_center(logoImage);
|
||||
|
||||
@@ -47,8 +57,27 @@ void splashScreenShow(void) {
|
||||
// Block for the display duration
|
||||
vTaskDelay(pdMS_TO_TICKS(SPLASH_SCREEN_DURATION_MS));
|
||||
|
||||
// Clean up the logo image before transitioning
|
||||
lv_obj_del(logoImage);
|
||||
|
||||
ESP_LOGI(TAG, "Splash screen complete");
|
||||
// Create a new main screen for the application to use
|
||||
lv_obj_t *mainScreen = lv_obj_create(NULL);
|
||||
if (mainScreen == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create main screen");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set black background for main screen
|
||||
lv_obj_set_style_bg_color(mainScreen, lv_color_black(),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_opa(mainScreen, LV_OPA_COVER,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
|
||||
// Switch to the main screen (this deactivates splash screen)
|
||||
lv_scr_load(mainScreen);
|
||||
|
||||
// Force an immediate refresh to ensure the transition is complete
|
||||
lv_refr_now(NULL);
|
||||
|
||||
// Now safe to delete the splash screen and its children
|
||||
lv_obj_del(splashScreen);
|
||||
|
||||
ESP_LOGI(TAG, "Splash screen complete, main screen active");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user