Implements a progressive deceleration phase for the shake emotion using a cubic ease-out, replacing the previous abrupt stop logic. Adds the shy.json animation asset for the 'shy' emotion. Updates lottie_player to properly delete existing blink timers before scheduling a new one. Also includes minor header and enum adjustments for shake_emotion.
420 lines
23 KiB
C
420 lines
23 KiB
C
/**
|
|
* @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"
|
|
#include "esp_timer.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_SLOWING_DOWN,
|
|
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;
|
|
|
|
// Recovery phase variables for progressive deceleration
|
|
static int64_t slowdown_start_time = 0;
|
|
static const int64_t slowdown_duration_ms = 1000; // 1 second recovery phase
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// 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);
|
|
}
|
|
|
|
// Record the start time for progressive deceleration
|
|
slowdown_start_time = esp_timer_get_time() / 1000; // Convert to milliseconds
|
|
|
|
state = SHAKE_STATE_SLOWING_DOWN;
|
|
ESP_LOGI(TAG, "Starting progressive deceleration phase");
|
|
}
|
|
|
|
bool shakeEmotionUpdate(void) {
|
|
if (state == SHAKE_STATE_IDLE || state == SHAKE_STATE_SHAKING) {
|
|
return false;
|
|
}
|
|
|
|
if (state == SHAKE_STATE_SLOWING_DOWN) {
|
|
// Calculate elapsed time since slowdown began
|
|
int64_t current_time = esp_timer_get_time() / 1000; // Convert to milliseconds
|
|
int64_t elapsed_ms = current_time - slowdown_start_time;
|
|
|
|
// Check if shake animation has completed its loop
|
|
if (shakePlayer != NULL && !lottieIsPlaying(shakePlayer)) {
|
|
// Destroy shake player
|
|
lottieDestroy(shakePlayer);
|
|
shakePlayer = NULL;
|
|
state = SHAKE_STATE_COMPLETE;
|
|
ESP_LOGI(TAG, "Progressive deceleration complete");
|
|
return false;
|
|
}
|
|
|
|
// Calculate current speed using linear interpolation (1.0 -> 0.0)
|
|
if (elapsed_ms >= slowdown_duration_ms) {
|
|
// Recovery phase complete, stop the animation
|
|
if (shakePlayer != NULL) {
|
|
lottiePause(shakePlayer);
|
|
lottieDestroy(shakePlayer);
|
|
shakePlayer = NULL;
|
|
}
|
|
state = SHAKE_STATE_COMPLETE;
|
|
ESP_LOGI(TAG, "Progressive deceleration complete");
|
|
return false;
|
|
}
|
|
|
|
// Calculate speed: 1.0 at start, 0.0 at end
|
|
float progress = (float)elapsed_ms / (float)slowdown_duration_ms;
|
|
float current_speed = 1.0f - progress;
|
|
|
|
// Apply easing function for smoother deceleration (ease-out cubic)
|
|
// This makes the deceleration feel more natural - starts fast, slows gradually
|
|
float eased_speed = 1.0f - (progress * progress * progress);
|
|
|
|
// Update animation speed with thread safety
|
|
if (shakePlayer != NULL && displayDriverLock(100)) {
|
|
lottieSetSpeed(shakePlayer, eased_speed);
|
|
displayDriverUnlock();
|
|
}
|
|
|
|
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_SLOWING_DOWN;
|
|
}
|