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:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user