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.
124 lines
3.0 KiB
C
124 lines
3.0 KiB
C
/**
|
|
* @file emotion_manager.c
|
|
* @brief Central emotion coordination system implementation
|
|
*
|
|
* This module coordinates all emotion animations. Currently supports
|
|
* the blink emotion, with architecture ready for additional emotions.
|
|
*/
|
|
|
|
#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";
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Private State
|
|
// ----------------------------------------------------------------------------
|
|
|
|
static EmotionType currentEmotion = EMOTION_IDLE;
|
|
static bool initialized = false;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Public API Implementation
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool emotionManagerInit(void) {
|
|
ESP_LOGI(TAG, "Initializing emotion manager");
|
|
|
|
// Initialize blink emotion
|
|
if (!blinkEmotionInit()) {
|
|
ESP_LOGE(TAG, "Failed to initialize blink emotion");
|
|
return false;
|
|
}
|
|
|
|
// Initialize shake emotion
|
|
if (!shakeEmotionInit()) {
|
|
ESP_LOGE(TAG, "Failed to initialize shake emotion");
|
|
return false;
|
|
}
|
|
|
|
// Future: Initialize other emotions here
|
|
// surprisedEmotionInit();
|
|
// sadEmotionInit();
|
|
// angryEmotionInit();
|
|
|
|
initialized = true;
|
|
currentEmotion = EMOTION_IDLE;
|
|
|
|
ESP_LOGI(TAG, "Emotion manager initialized");
|
|
return true;
|
|
}
|
|
|
|
void emotionManagerStart(void) {
|
|
if (!initialized) {
|
|
ESP_LOGE(TAG, "Emotion manager not initialized");
|
|
return;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Starting emotion engine with idle state");
|
|
|
|
// Start the blink animation (idle state with natural blinking)
|
|
blinkEmotionPlay();
|
|
currentEmotion = EMOTION_IDLE;
|
|
}
|
|
|
|
void emotionManagerSetEmotion(EmotionType emotion) {
|
|
if (!initialized) {
|
|
ESP_LOGE(TAG, "Emotion manager not initialized");
|
|
return;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Setting emotion: %d", emotion);
|
|
currentEmotion = emotion;
|
|
|
|
// Handle emotion transitions
|
|
switch (emotion) {
|
|
case EMOTION_IDLE:
|
|
case EMOTION_BLINK:
|
|
// 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
|
|
ESP_LOGI(TAG, "Emotion %d not yet implemented", emotion);
|
|
break;
|
|
|
|
default:
|
|
ESP_LOGW(TAG, "Unknown emotion type: %d", emotion);
|
|
break;
|
|
}
|
|
}
|
|
|
|
EmotionType emotionManagerGetCurrent(void) { return currentEmotion; }
|
|
|
|
void emotionManagerStop(void) {
|
|
if (!initialized) {
|
|
return;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Stopping emotion manager");
|
|
|
|
blinkEmotionStop();
|
|
// Future: Stop other emotions
|
|
|
|
initialized = false;
|
|
}
|