Files
iroBotAMOLED_Test/main/ui/lottie_player.h
Neil Arora 4d68a788ad Add shake emotion with persistent state and calibration
Introduces a new shake emotion animation with a shake-stop transition, including embedded Lottie animation data and a state machine for emotion transitions. Adds a non-volatile storage (NVS) driver for persistent state management, including first-boot detection, boot count, and IMU calibration storage. Updates emotion manager and related headers to support new shake emotion states, and integrates new UI components for calibration and loading animations.
2026-01-24 20:02:04 +05:30

179 lines
5.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 Disable natural blink mode
*
* By default, all animations enable natural blink mode. Call this
* to disable it for non-blink animations like shake.
*
* @param handle Handle to the Lottie player instance
*/
void lottieDisableNaturalBlink(lottie_player_handle_t handle);
/**
* @brief Pause the natural blink timer
*
* Temporarily stops the blink timer without disabling natural blink mode.
* Use lottieResumeNaturalBlink to resume.
*
* @param handle Handle to the Lottie player instance
*/
void lottiePauseNaturalBlink(lottie_player_handle_t handle);
/**
* @brief Resume the natural blink timer
*
* Resumes the blink timer that was paused with lottiePauseNaturalBlink.
*
* @param handle Handle to the Lottie player instance
*/
void lottieResumeNaturalBlink(lottie_player_handle_t handle);
/**
* @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 playback speed multiplier
*
* @param handle Handle to the Lottie player instance
* @param speed Speed multiplier (1.0 = native, 2.0 = 2x speed, etc.)
*/
void lottieSetSpeed(lottie_player_handle_t handle, float speed);
/**
* @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