Add initial project files for ESP32 animated eyes, including main application sources, assets, CMake configuration, and supporting ESP-IDF components for LCD and touch functionality. Includes documentation, test apps, and configuration files.
111 lines
3.3 KiB
C
111 lines
3.3 KiB
C
/**
|
|
* @file animated_eyes_demo.c
|
|
* @brief Demo implementation for animated eyes
|
|
*/
|
|
|
|
#include "animated_eyes_demo.h"
|
|
#include "esp_log.h"
|
|
// FreeRTOS includes not needed for lv_timer
|
|
|
|
static const char *TAG = "eyes_demo";
|
|
|
|
static lv_timer_t *update_timer = NULL;
|
|
static lv_timer_t *emotion_timer = NULL;
|
|
static animated_eyes_handle_t eyes_handle = NULL;
|
|
static int current_emotion_idx = 0;
|
|
|
|
static const char *emotion_names[] = {
|
|
"NORMAL", "ANGRY", "GLEE", "HAPPY", "SAD", "WORRIED",
|
|
"FOCUSED", "ANNOYED", "SURPRISED", "SKEPTIC", "FRUSTRATED",
|
|
"UNIMPRESSED", "SLEEPY", "SUSPICIOUS", "SQUINT", "FURIOUS",
|
|
"SCARED", "AWE"
|
|
};
|
|
|
|
// Timer callback for updating eyes
|
|
static void update_timer_callback(lv_timer_t *timer) {
|
|
if (eyes_handle) {
|
|
animated_eyes_update(eyes_handle);
|
|
}
|
|
}
|
|
|
|
// Timer callback for cycling emotions
|
|
static void emotion_timer_callback(lv_timer_t *timer) {
|
|
if (eyes_handle) {
|
|
current_emotion_idx = (current_emotion_idx + 1) % EMOTION_COUNT;
|
|
animated_eyes_emotion_t next_emotion = (animated_eyes_emotion_t)current_emotion_idx;
|
|
|
|
ESP_LOGI(TAG, "Switching emotion to: %s", emotion_names[next_emotion]);
|
|
animated_eyes_set_emotion(eyes_handle, next_emotion);
|
|
}
|
|
}
|
|
|
|
animated_eyes_handle_t animated_eyes_demo_start(void) {
|
|
ESP_LOGI(TAG, "Starting animated eyes demo");
|
|
|
|
// Get the active screen
|
|
lv_obj_t *scr = lv_scr_act();
|
|
|
|
// Set black background
|
|
lv_obj_set_style_bg_color(scr, lv_color_black(), 0);
|
|
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
|
|
|
|
// Configure and create animated eyes
|
|
animated_eyes_config_t config = ANIMATED_EYES_DEFAULT_CONFIG();
|
|
|
|
// Customize for your screen (368x448)
|
|
config.screen_width = 368;
|
|
config.screen_height = 448;
|
|
config.eye_size = 120; // Larger eyes to fill the screen better
|
|
config.eye_spacing = 20; // Closer together
|
|
config.eye_color = lv_color_white();
|
|
config.bg_color = lv_color_black();
|
|
|
|
// Disable random movements for stability
|
|
config.random_behavior = false;
|
|
config.random_look = false;
|
|
config.random_blink = true; // Keep blinking for life
|
|
|
|
// Timing settings (unused when random features disabled, but kept for reference)
|
|
config.behavior_interval = 6000;
|
|
config.look_interval = 3000;
|
|
config.blink_interval = 4000;
|
|
|
|
eyes_handle = animated_eyes_create(scr, &config);
|
|
if (!eyes_handle) {
|
|
ESP_LOGE(TAG, "Failed to create animated eyes");
|
|
return NULL;
|
|
}
|
|
|
|
// Reset emotion index
|
|
current_emotion_idx = 0;
|
|
|
|
// Create timers
|
|
// 1. Update timer: 33ms (approx 30 FPS) for smooth animation
|
|
update_timer = lv_timer_create(update_timer_callback, 33, NULL);
|
|
|
|
// 2. Emotion cycle timer: 4000ms (4 seconds) to switch emotions
|
|
emotion_timer = lv_timer_create(emotion_timer_callback, 4000, NULL);
|
|
|
|
ESP_LOGI(TAG, "Animated eyes started successfully");
|
|
return eyes_handle;
|
|
}
|
|
|
|
void animated_eyes_demo_stop(animated_eyes_handle_t handle) {
|
|
if (update_timer) {
|
|
lv_timer_del(update_timer);
|
|
update_timer = NULL;
|
|
}
|
|
|
|
if (emotion_timer) {
|
|
lv_timer_del(emotion_timer);
|
|
emotion_timer = NULL;
|
|
}
|
|
|
|
if (handle) {
|
|
animated_eyes_delete(handle);
|
|
eyes_handle = NULL;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Animated eyes demo stopped");
|
|
}
|