Refactor project structure and update display logic
Reorganized source files into new directories for config, drivers, sensors, emotion engine, and UI. Removed legacy assets and code related to previous eye animation implementation. Added new display and touch drivers, emotion manager, shake detector, and UI components. Updated CMake project name to 'irobot_display'.
This commit is contained in:
202
main/emotion-engine/blink/blink_data.h
Normal file
202
main/emotion-engine/blink/blink_data.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* @file blink_data.h
|
||||
* @brief Embedded blink Lottie animation data
|
||||
*
|
||||
* This file contains the blink.json Lottie animation stored as a C string.
|
||||
* The animation shows two eyes blinking on a 368x448 display at 60fps.
|
||||
* Source file: assets/emotions/blink.json
|
||||
*/
|
||||
|
||||
#ifndef BLINK_DATA_H
|
||||
#define BLINK_DATA_H
|
||||
|
||||
// Lottie JSON animation data stored in flash
|
||||
// Animation: 368x448, 60fps, 36 frames
|
||||
const char blinkAnimationData[] =
|
||||
"{\"fr\":60,\"h\":448,\"ip\":0,\"layers\":["
|
||||
"{\"ind\":3,\"ty\":4,\"parent\":2,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0,"
|
||||
"\"shapes\":["
|
||||
"{\"ty\":\"rc\",\"p\":{\"a\":1,\"k\":["
|
||||
"{\"t\":0,\"s\":[48.5,68],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":2.952,\"s\":[48.5,13.753],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":5.898,\"s\":[48.5,-2.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":11.802,\"s\":[48.5,0.118],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":17.76,\"s\":[48.5,-0.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":18,\"s\":[48.5,-0.005],\"h\":1},"
|
||||
"{\"t\":18,\"s\":[48.5,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":20.952,\"s\":[48.5,54.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":23.898,\"s\":[48.5,70.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":29.802,\"s\":[48.5,67.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":35.76,\"s\":[48.5,68.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":36,\"s\":[48.5,68.005],\"h\":1}"
|
||||
"]},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":1,\"k\":["
|
||||
"{\"t\":0,\"s\":[97,136],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":2.952,\"s\":[97,27.505],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":5.898,\"s\":[97,-5.662],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":11.802,\"s\":[97,0.236],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":17.76,\"s\":[97,-0.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":18,\"s\":[97,-0.01],\"h\":1},"
|
||||
"{\"t\":18,\"s\":[97,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":20.952,\"s\":[97,108.495],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":23.898,\"s\":[97,141.662],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":29.802,\"s\":[97,135.764],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":35.76,\"s\":[97,136.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":36,\"s\":[97,136.01],\"h\":1}"
|
||||
"]}},"
|
||||
"{\"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\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":2.952,\"s\":[211,142.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":5.898,\"s\":[211,158.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":11.802,\"s\":[211,155.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":17.76,\"s\":[211,156.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":18,\"s\":[211,156.005],\"h\":1},"
|
||||
"{\"t\":18,\"s\":[211,156],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":20.952,\"s\":[211,101.753],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":23.898,\"s\":[211,85.169],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":29.802,\"s\":[211,88.118],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":35.76,\"s\":[211,87.995],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":36,\"s\":[211,87.995],\"h\":1}"
|
||||
"]}},\"ip\":0,\"op\":37,\"st\":0},"
|
||||
"{\"ind\":5,\"ty\":4,\"parent\":4,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0,"
|
||||
"\"shapes\":["
|
||||
"{\"ty\":\"rc\",\"p\":{\"a\":1,\"k\":["
|
||||
"{\"t\":0,\"s\":[48.5,66],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":2.952,\"s\":[48.5,13.348],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":5.898,\"s\":[48.5,-2.748],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":11.802,\"s\":[48.5,0.114],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":17.76,\"s\":[48.5,-0.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":18,\"s\":[48.5,-0.005],\"h\":1},"
|
||||
"{\"t\":18,\"s\":[48.5,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":20.952,\"s\":[48.5,54.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":23.898,\"s\":[48.5,70.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":29.802,\"s\":[48.5,67.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":35.76,\"s\":[48.5,68.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":36,\"s\":[48.5,68.005],\"h\":1}"
|
||||
"]},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":1,\"k\":["
|
||||
"{\"t\":0,\"s\":[97,132],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":2.952,\"s\":[97,26.696],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":5.898,\"s\":[97,-5.496],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":11.802,\"s\":[97,0.229],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":17.76,\"s\":[97,-0.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":18,\"s\":[97,-0.009],\"h\":1},"
|
||||
"{\"t\":18,\"s\":[97,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":20.952,\"s\":[97,108.495],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":23.898,\"s\":[97,141.662],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":29.802,\"s\":[97,135.764],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":35.76,\"s\":[97,136.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":36,\"s\":[97,136.01],\"h\":1}"
|
||||
"]}},"
|
||||
"{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[1,1,1]},\"o\":{\"a\":0,\"k\":100}}"
|
||||
"]},"
|
||||
"{\"ind\":4,\"ty\":3,\"parent\":1,\"ks\":{\"a\":{\"a\":1,\"k\":["
|
||||
"{\"t\":0,\"s\":[48.5,66],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":2.952,\"s\":[48.5,13.348],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":5.898,\"s\":[48.5,-2.748],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":11.802,\"s\":[48.5,0.114],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":17.76,\"s\":[48.5,-0.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":18,\"s\":[48.5,-0.005],\"h\":1},"
|
||||
"{\"t\":18,\"s\":[48.5,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{"
|
||||
"\"x\":[0,0.283],\"y\":[0,0.035]}},"
|
||||
"{\"t\":20.952,\"s\":[48.5,54.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.343],\"y\":[0,0.908]}},"
|
||||
"{\"t\":23.898,\"s\":[48.5,70.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]},"
|
||||
"\"o\":{"
|
||||
"\"x\":[0,0.262],\"y\":[0,0.033]}},"
|
||||
"{\"t\":29.802,\"s\":[48.5,67.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":35.76,\"s\":[48.5,68.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{"
|
||||
"\"x\":[0,0],\"y\":[0,0]}},"
|
||||
"{\"t\":36,\"s\":[48.5,68.005],\"h\":1}"
|
||||
"]},\"p\":{\"a\":0,\"k\":[108.5,157]}},\"ip\":0,\"op\":37,\"st\":0},"
|
||||
"{\"ind\":1,\"ty\":3,\"parent\":0,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0},"
|
||||
"{\"ind\":6,\"ty\":4,\"parent\":0,\"ks\":{},\"ip\":0,\"op\":37,\"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\":37,\"st\":0}"
|
||||
"],\"meta\":{\"g\":\"https://"
|
||||
"jitter.video\"},\"op\":36,\"v\":\"5.7.4\",\"w\":368}";
|
||||
|
||||
#endif // BLINK_DATA_H
|
||||
90
main/emotion-engine/blink/blink_emotion.c
Normal file
90
main/emotion-engine/blink/blink_emotion.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
// Lottie player auto-starts with natural blink mode
|
||||
ESP_LOGI(TAG, "Blink animation active");
|
||||
}
|
||||
|
||||
void blinkEmotionPause(void) {
|
||||
if (blinkPlayer != NULL) {
|
||||
lottiePause(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);
|
||||
}
|
||||
}
|
||||
54
main/emotion-engine/blink/blink_emotion.h
Normal file
54
main/emotion-engine/blink/blink_emotion.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @file blink_emotion.h
|
||||
* @brief Blink emotion animation interface
|
||||
*
|
||||
* This module handles the idle blink animation using Lottie.
|
||||
* It plays the eyes open/close animation with natural random intervals.
|
||||
*/
|
||||
|
||||
#ifndef BLINK_EMOTION_H
|
||||
#define BLINK_EMOTION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize the blink emotion
|
||||
*
|
||||
* Loads the blink animation data and prepares the Lottie player.
|
||||
* Must be called after display driver initialization.
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool blinkEmotionInit(void);
|
||||
|
||||
/**
|
||||
* @brief Start or trigger the blink animation
|
||||
*
|
||||
* Starts the natural blink loop with random intervals.
|
||||
*/
|
||||
void blinkEmotionPlay(void);
|
||||
|
||||
/**
|
||||
* @brief Pause the blink animation
|
||||
*/
|
||||
void blinkEmotionPause(void);
|
||||
|
||||
/**
|
||||
* @brief Stop and cleanup the blink animation
|
||||
*/
|
||||
void blinkEmotionStop(void);
|
||||
|
||||
/**
|
||||
* @brief Trigger a single blink immediately
|
||||
*/
|
||||
void blinkEmotionTrigger(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // BLINK_EMOTION_H
|
||||
107
main/emotion-engine/emotion_manager.c
Normal file
107
main/emotion-engine/emotion_manager.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @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 "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;
|
||||
}
|
||||
|
||||
// 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:
|
||||
// Play blink animation
|
||||
blinkEmotionPlay();
|
||||
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();
|
||||
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;
|
||||
}
|
||||
84
main/emotion-engine/emotion_manager.h
Normal file
84
main/emotion-engine/emotion_manager.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file emotion_manager.h
|
||||
* @brief Central emotion coordination system
|
||||
*
|
||||
* This module manages all emotion-related animations and coordinates
|
||||
* transitions between emotional states. It provides a unified interface
|
||||
* for triggering emotions from various sources (shake, touch, etc.).
|
||||
*/
|
||||
|
||||
#ifndef EMOTION_MANAGER_H
|
||||
#define EMOTION_MANAGER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Type Definitions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @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_COUNT
|
||||
} EmotionType;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Public API
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Initialize the emotion engine
|
||||
*
|
||||
* Sets up all emotion animations and prepares the system.
|
||||
* Must be called after display driver initialization.
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool emotionManagerInit(void);
|
||||
|
||||
/**
|
||||
* @brief Start the emotion engine with default state
|
||||
*
|
||||
* Begins the idle animation with natural blinking.
|
||||
* Call this after splash screen is complete.
|
||||
*/
|
||||
void emotionManagerStart(void);
|
||||
|
||||
/**
|
||||
* @brief Trigger a specific emotion
|
||||
*
|
||||
* Plays the specified emotion animation. The system will
|
||||
* automatically return to idle state after the animation completes.
|
||||
*
|
||||
* @param emotion The emotion to trigger
|
||||
*/
|
||||
void emotionManagerSetEmotion(EmotionType emotion);
|
||||
|
||||
/**
|
||||
* @brief Get the currently active emotion
|
||||
*
|
||||
* @return The current emotion type
|
||||
*/
|
||||
EmotionType emotionManagerGetCurrent(void);
|
||||
|
||||
/**
|
||||
* @brief Stop all emotions and cleanup
|
||||
*/
|
||||
void emotionManagerStop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // EMOTION_MANAGER_H
|
||||
Reference in New Issue
Block a user