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.
117 lines
3.2 KiB
C
117 lines
3.2 KiB
C
/**
|
|
* @file shake_detector.h
|
|
* @brief Shake detection interface using QMI8658 IMU sensor
|
|
*
|
|
* This module provides motion detection capabilities using the QMI8658
|
|
* accelerometer/gyroscope. It detects shake gestures and can trigger
|
|
* emotional responses in the display system.
|
|
*/
|
|
|
|
#ifndef SHAKE_DETECTOR_H
|
|
#define SHAKE_DETECTOR_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Configuration
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Acceleration deviation threshold to detect shake (in G)
|
|
// Set above 1G to account for gravity and require actual vigorous shaking
|
|
#define SHAKE_ACCEL_THRESHOLD 1.3f
|
|
|
|
// Number of consecutive readings above threshold to confirm shake
|
|
#define SHAKE_CONTINUOUS_THRESHOLD 10
|
|
|
|
// Number of samples to average for baseline calibration
|
|
#define SHAKE_BASELINE_SAMPLES 10
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Type Definitions
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Shake event types
|
|
*/
|
|
typedef enum {
|
|
SHAKE_NONE = 0, // No shake detected
|
|
SHAKE_ACTIVE, // Device is currently being shaken
|
|
SHAKE_STOPPED // Shaking just stopped
|
|
} ShakeEvent;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Public API
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Initialize the shake detector and IMU sensor
|
|
*
|
|
* Configures the QMI8658 accelerometer and gyroscope for shake detection.
|
|
* The I2C bus must be initialized before calling this function.
|
|
*
|
|
* @return true on successful initialization, false on failure
|
|
*/
|
|
bool shakeDetectorInit(void);
|
|
|
|
/**
|
|
* @brief Poll the shake detector for events
|
|
*
|
|
* Should be called periodically (e.g., every 50ms) to check for shakes.
|
|
* Performs baseline calibration on first several calls.
|
|
*
|
|
* @return The detected shake event, or SHAKE_NONE if no shake
|
|
*/
|
|
ShakeEvent shakeDetectorUpdate(void);
|
|
|
|
/**
|
|
* @brief Get raw accelerometer readings
|
|
*
|
|
* Retrieves the latest accelerometer values in G units.
|
|
*
|
|
* @param x Pointer to store X-axis acceleration
|
|
* @param y Pointer to store Y-axis acceleration
|
|
* @param z Pointer to store Z-axis acceleration
|
|
* @return true on success, false on failure
|
|
*/
|
|
bool shakeDetectorGetRawAccel(float *x, float *y, float *z);
|
|
|
|
/**
|
|
* @brief Perform immediate baseline calibration
|
|
*
|
|
* Collects multiple samples and computes the baseline average.
|
|
* Should be called when device is on a stable, flat surface.
|
|
*
|
|
* @return true on successful calibration, false on failure
|
|
*/
|
|
bool shakeDetectorCalibrateBaseline(void);
|
|
|
|
/**
|
|
* @brief Set baseline values directly
|
|
*
|
|
* Used to restore calibration from NVS storage.
|
|
*
|
|
* @param x X-axis baseline value
|
|
* @param y Y-axis baseline value
|
|
* @param z Z-axis baseline value
|
|
*/
|
|
void shakeDetectorSetBaseline(float x, float y, float z);
|
|
|
|
/**
|
|
* @brief Get current baseline values
|
|
*
|
|
* @param x Pointer to store X-axis baseline
|
|
* @param y Pointer to store Y-axis baseline
|
|
* @param z Pointer to store Z-axis baseline
|
|
*/
|
|
void shakeDetectorGetBaseline(float *x, float *y, float *z);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // SHAKE_DETECTOR_H
|