/** * @file animated_eyes.h * @brief Animated expressive eyes for LVGL displays * * Ported from esp32-eyes (https://github.com/playfultechnology/esp32-eyes) * Original Copyright (c) 2020 Luis Llamas, 2023 Alastair Aitchison * LVGL port for ESP-IDF * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Affero General Public License. */ #ifndef ANIMATED_EYES_H #define ANIMATED_EYES_H #include "lvgl.h" #include #include #ifdef __cplusplus extern "C" { #endif /** * @brief Available emotions for the animated face */ typedef enum { EMOTION_NORMAL = 0, EMOTION_ANGRY, EMOTION_GLEE, EMOTION_HAPPY, EMOTION_SAD, EMOTION_WORRIED, EMOTION_FOCUSED, EMOTION_ANNOYED, EMOTION_SURPRISED, EMOTION_SKEPTIC, EMOTION_FRUSTRATED, EMOTION_UNIMPRESSED, EMOTION_SLEEPY, EMOTION_SUSPICIOUS, EMOTION_SQUINT, EMOTION_FURIOUS, EMOTION_SCARED, EMOTION_AWE, EMOTION_COUNT } animated_eyes_emotion_t; /** * @brief Configuration for animated eyes */ typedef struct { uint16_t screen_width; /**< Screen width in pixels */ uint16_t screen_height; /**< Screen height in pixels */ uint16_t eye_size; /**< Base eye size (will be scaled) */ uint16_t eye_spacing; /**< Distance between eyes */ lv_color_t eye_color; /**< Color of the eyes */ lv_color_t bg_color; /**< Background color */ bool random_behavior; /**< Enable random emotion changes */ bool random_look; /**< Enable random look-around */ bool random_blink; /**< Enable random blinking */ uint32_t behavior_interval; /**< Interval for behavior changes (ms) */ uint32_t look_interval; /**< Interval for look changes (ms) */ uint32_t blink_interval; /**< Interval for blinking (ms) */ } animated_eyes_config_t; /** * @brief Handle for animated eyes instance */ typedef struct animated_eyes_t *animated_eyes_handle_t; /** * @brief Default configuration macro */ #define ANIMATED_EYES_DEFAULT_CONFIG() \ {.screen_width = 368, \ .screen_height = 448, \ .eye_size = 120, \ .eye_spacing = 20, \ .eye_color = lv_color_white(), \ .bg_color = lv_color_black(), \ .random_behavior = true, \ .random_look = true, \ .random_blink = true, \ .behavior_interval = 5000, \ .look_interval = 4000, \ .blink_interval = 3500} /** * @brief Create animated eyes on a parent LVGL object * * @param parent Parent LVGL object to attach eyes to * @param config Configuration for the eyes * @return Handle to the animated eyes instance, or NULL on failure */ animated_eyes_handle_t animated_eyes_create(lv_obj_t *parent, const animated_eyes_config_t *config); /** * @brief Delete animated eyes and free resources * * @param handle Handle to the animated eyes instance */ void animated_eyes_delete(animated_eyes_handle_t handle); /** * @brief Update the animated eyes (call this regularly, e.g., every frame) * * @param handle Handle to the animated eyes instance */ void animated_eyes_update(animated_eyes_handle_t handle); /** * @brief Trigger a blink animation * * @param handle Handle to the animated eyes instance */ void animated_eyes_blink(animated_eyes_handle_t handle); /** * @brief Set the current emotion * * @param handle Handle to the animated eyes instance * @param emotion The emotion to set */ void animated_eyes_set_emotion(animated_eyes_handle_t handle, animated_eyes_emotion_t emotion); /** * @brief Set a temporary emotion that reverts after a duration * * @param handle Handle to the animated eyes instance * @param emotion The temporary emotion to set * @param duration_ms Duration in milliseconds before reverting */ void animated_eyes_set_temporary_emotion(animated_eyes_handle_t handle, animated_eyes_emotion_t emotion, uint32_t duration_ms); /** * @brief Get the current emotion * * @param handle Handle to the animated eyes instance * @return Current emotion */ animated_eyes_emotion_t animated_eyes_get_emotion(animated_eyes_handle_t handle); /** * @brief Set a temporary emotion that reverts after a duration * * @param handle Handle to the animated eyes instance * @param emotion The temporary emotion to set * @param duration_ms Duration in milliseconds before reverting */ void animated_eyes_set_temporary_emotion(animated_eyes_handle_t handle, animated_eyes_emotion_t emotion, uint32_t duration_ms); /** * @brief Apply an inertia-based offset * to the eyes * * @param handle Handle to the animated * eyes instance * @param intensity_x Intensity of the * shake X component (G-force) * @param intensity_y Intensity of the * shake Y component (G-force) */ void animated_eyes_shake_inertia(animated_eyes_handle_t handle, float intensity_x, float intensity_y); /** * @brief Set the emotion probability * weight * * @param handle Handle to the animated * eyes instance * @param emotion The emotion to set * weight for * @param weight Weight value (0.0 to * disable, higher = more likely) */ void animated_eyes_set_emotion_weight(animated_eyes_handle_t handle, animated_eyes_emotion_t emotion, float weight); /** * @brief Make the eyes look in a * specific direction * * @param handle Handle to the animated * eyes instance * @param x Horizontal direction (-1.0 * = left, 0.0 = center, 1.0 = right) * @param y Vertical direction (-1.0 = * down, 0.0 = center, 1.0 = up) */ void animated_eyes_look_at(animated_eyes_handle_t handle, float x, float y); /** * @brief Make the eyes look at a * screen position * * @param handle Handle to the animated * eyes instance * @param screen_x X coordinate on * screen * @param screen_y Y coordinate on * screen */ void animated_eyes_look_at_point(animated_eyes_handle_t handle, int16_t screen_x, int16_t screen_y); /** * @brief Convenience methods for * common look directions */ void animated_eyes_look_left(animated_eyes_handle_t handle); void animated_eyes_look_right(animated_eyes_handle_t handle); void animated_eyes_look_up(animated_eyes_handle_t handle); void animated_eyes_look_down(animated_eyes_handle_t handle); void animated_eyes_look_center(animated_eyes_handle_t handle); /** * @brief Enable or disable random * behaviors * * @param handle Handle to the animated * eyes instance * @param behavior Enable random * emotion changes * @param look Enable random looking * around * @param blink Enable random blinking */ void animated_eyes_set_random(animated_eyes_handle_t handle, bool behavior, bool look, bool blink); /** * @brief Set the eye color * * @param handle Handle to the animated * eyes instance * @param color New eye color */ void animated_eyes_set_color(animated_eyes_handle_t handle, lv_color_t color); /** * @brief Set the background color * * @param handle Handle to the animated * eyes instance * @param color New background color */ void animated_eyes_set_bg_color(animated_eyes_handle_t handle, lv_color_t color); #ifdef __cplusplus } #endif #endif /* ANIMATED_EYES_H */