Files
iroBotAMOLED_Test/main/ui/lottie_player.h
Neil Arora 8aeaed8a15 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'.
2026-01-24 15:21:50 +05:30

142 lines
4.0 KiB
C

/**
* @file lottie_player.h
* @brief Lightweight Lottie animation player for LVGL on ESP32
*
* This module provides a minimal Lottie JSON animation player optimized
* for embedded systems. It supports basic shape types (rounded rectangles)
* with keyframe animation and bezier curve interpolation.
*
* Designed for simple animations like blinking eyes on resource-constrained
* devices. Does not support the full Lottie specification.
*/
#ifndef LOTTIE_PLAYER_H
#define LOTTIE_PLAYER_H
#include "lvgl.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// ----------------------------------------------------------------------------
// Configuration (Modify as needed for different animations)
// ----------------------------------------------------------------------------
// Maximum number of layers supported in animation
#define LOTTIE_MAX_LAYERS 8
// Maximum shapes per layer
#define LOTTIE_MAX_SHAPES 4
// Maximum keyframes per animated property
#define LOTTIE_MAX_KEYFRAMES 24
// Animation timer update interval (milliseconds)
#define LOTTIE_TIMER_PERIOD_MS 16
// Random blink interval range (milliseconds)
#define LOTTIE_BLINK_MIN_MS 2000
#define LOTTIE_BLINK_MAX_MS 6000
// ----------------------------------------------------------------------------
// Type Definitions
// ----------------------------------------------------------------------------
// Forward declaration of internal structure
typedef struct lottie_player_t *lottie_player_handle_t;
// ----------------------------------------------------------------------------
// Public API
// ----------------------------------------------------------------------------
/**
* @brief Create a Lottie animation player from embedded JSON data
*
* Parses the Lottie JSON and creates an LVGL canvas for rendering.
* The animation auto-starts with random blink interval enabled.
*
* @param parent Parent LVGL object to attach the animation to
* @param jsonData Pointer to null-terminated JSON string
* @return Handle to the player instance, or NULL on failure
*/
lottie_player_handle_t lottieCreateFromData(lv_obj_t *parent,
const char *jsonData);
/**
* @brief Start or resume animation playback
*
* @param handle Handle to the Lottie player instance
*/
void lottiePlay(lottie_player_handle_t handle);
/**
* @brief Pause animation playback
*
* @param handle Handle to the Lottie player instance
*/
void lottiePause(lottie_player_handle_t handle);
/**
* @brief Stop animation and reset to first frame
*
* @param handle Handle to the Lottie player instance
*/
void lottieStop(lottie_player_handle_t handle);
/**
* @brief Set whether the animation should loop
*
* @param handle Handle to the Lottie player instance
* @param loop True to enable looping, false for single playthrough
*/
void lottieSetLoop(lottie_player_handle_t handle, bool loop);
/**
* @brief Check if animation is currently playing
*
* @param handle Handle to the Lottie player instance
* @return True if playing, false if paused or stopped
*/
bool lottieIsPlaying(lottie_player_handle_t handle);
/**
* @brief Get the current frame number
*
* @param handle Handle to the Lottie player instance
* @return Current frame number (0-indexed)
*/
uint32_t lottieGetCurrentFrame(lottie_player_handle_t handle);
/**
* @brief Get total number of frames in the animation
*
* @param handle Handle to the Lottie player instance
* @return Total frame count
*/
uint32_t lottieGetTotalFrames(lottie_player_handle_t handle);
/**
* @brief Set the current frame manually
*
* @param handle Handle to the Lottie player instance
* @param frame Frame number to seek to (clamped to valid range)
*/
void lottieSetFrame(lottie_player_handle_t handle, uint32_t frame);
/**
* @brief Destroy the Lottie player and free all resources
*
* @param handle Handle to the Lottie player instance
*/
void lottieDestroy(lottie_player_handle_t handle);
#ifdef __cplusplus
}
#endif
#endif // LOTTIE_PLAYER_H