Files
iroBotAMOLED_Test/main/emotion-engine/blink/blink_emotion.c
Neil Arora 4d68a788ad 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.
2026-01-24 20:02:04 +05:30

94 lines
2.5 KiB
C

/**
* @file blink_emotion.c
* @brief Blink emotion animation implementation
*
* This module implements the idle blink animation using the Lottie player.
* It loads the blink animation data and manages playback with natural timing.
*/
#include "emotion-engine/blink/blink_emotion.h"
#include "drivers/display_driver.h"
#include "emotion-engine/blink/blink_data.h"
#include "esp_log.h"
#include "ui/lottie_player.h"
static const char *TAG = "blink_emotion";
// ----------------------------------------------------------------------------
// Private State
// ----------------------------------------------------------------------------
static lottie_player_handle_t blinkPlayer = NULL;
static bool initialized = false;
// ----------------------------------------------------------------------------
// Public API Implementation
// ----------------------------------------------------------------------------
bool blinkEmotionInit(void) {
ESP_LOGI(TAG, "Initializing blink emotion");
// Don't reinitialize if already done
if (initialized && blinkPlayer != NULL) {
ESP_LOGW(TAG, "Blink emotion already initialized");
return true;
}
initialized = true;
ESP_LOGI(TAG, "Blink emotion initialized (deferred player creation)");
return true;
}
void blinkEmotionPlay(void) {
if (!initialized) {
ESP_LOGE(TAG, "Blink emotion not initialized");
return;
}
// Create player on first play (ensures display is ready)
if (blinkPlayer == NULL) {
ESP_LOGI(TAG, "Creating blink player");
lv_obj_t *screen = displayDriverGetActiveScreen();
if (screen == NULL) {
ESP_LOGE(TAG, "No active screen available");
return;
}
blinkPlayer = lottieCreateFromData(screen, blinkAnimationData);
if (blinkPlayer == NULL) {
ESP_LOGE(TAG, "Failed to create blink player");
return;
}
} else {
// If player already exists, resume playback and blink timer
lottiePlay(blinkPlayer);
lottieResumeNaturalBlink(blinkPlayer);
}
ESP_LOGI(TAG, "Blink animation active");
}
void blinkEmotionPause(void) {
if (blinkPlayer != NULL) {
lottiePause(blinkPlayer);
lottiePauseNaturalBlink(blinkPlayer);
}
}
void blinkEmotionStop(void) {
if (blinkPlayer != NULL) {
lottieDestroy(blinkPlayer);
blinkPlayer = NULL;
}
initialized = false;
ESP_LOGI(TAG, "Blink emotion stopped");
}
void blinkEmotionTrigger(void) {
if (blinkPlayer != NULL) {
lottieSetFrame(blinkPlayer, 0);
lottiePlay(blinkPlayer);
}
}