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:
2026-01-24 20:02:04 +05:30
parent 8aeaed8a15
commit 4d68a788ad
22 changed files with 5255 additions and 93 deletions

View File

@@ -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);
}
}

View File

@@ -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:

View File

@@ -25,11 +25,13 @@ extern "C" {
* @brief Supported emotion types
*/
typedef enum {
EMOTION_IDLE = 0, // Default idle state with blink
EMOTION_BLINK, // Single blink animation
EMOTION_SURPRISED, // Surprised expression
EMOTION_SAD, // Sad expression
EMOTION_ANGRY, // Angry expression
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
EMOTION_COUNT
} EmotionType;

File diff suppressed because one or more lines are too long

View 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;
}

View 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

View 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}