/** * @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 #ifdef __cplusplus extern "C" { #endif // ---------------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------------- // Acceleration deviation threshold to detect shake (in G) // Set above 2.2 to require vigorous shaking #define SHAKE_ACCEL_THRESHOLD 2.2f // 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