Files
iroBotAMOLED_Test/main/emotion-engine/emotion_manager.c
Neil Arora 22bd5a6f70 update: fixed shake animation
The shake animation figures have been fixed. However, the petting emotion working with touch remains an issue. The Lottie JSON for the emotion is unable not parsable for some reason and my next step is to fix that for tomorrow's meeting.
2026-01-27 00:30:12 +05:30

139 lines
3.3 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 "emotion-engine/shy/shy_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;
}
// Initialize shy emotion
if (!shyEmotionInit()) {
ESP_LOGE(TAG, "Failed to initialize shy 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;
case EMOTION_SHY:
// Stop any other animations and play shy
shakeEmotionStop();
blinkEmotionPause();
shyEmotionPlay();
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();
shyEmotionStop();
// Future: Stop other emotions
initialized = false;
}