85 lines
2.2 KiB
C
85 lines
2.2 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 animated_eyes_handle_t eyes_handle = NULL;
|
|
|
|
// Timer callback for updating eyes
|
|
static void update_timer_callback(lv_timer_t *timer) {
|
|
if (eyes_handle) {
|
|
animated_eyes_update(eyes_handle);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// Create timers
|
|
// 1. Update timer: 33ms (approx 30 FPS) for smooth animation
|
|
update_timer = lv_timer_create(update_timer_callback, 33, NULL);
|
|
|
|
ESP_LOGI(TAG, "Animated eyes started successfully");
|
|
return eyes_handle;
|
|
}
|
|
|
|
animated_eyes_handle_t animated_eyes_demo_get_handle(void) {
|
|
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 (handle) {
|
|
animated_eyes_delete(handle);
|
|
eyes_handle = NULL;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Animated eyes demo stopped");
|
|
}
|