/** * @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) #define SHAKE_ACCEL_THRESHOLD 0.5f // Debounce time between shake detections (milliseconds) #define SHAKE_DEBOUNCE_MS 2000 // Number of samples to average for baseline calibration #define SHAKE_BASELINE_SAMPLES 10 // ---------------------------------------------------------------------------- // Type Definitions // ---------------------------------------------------------------------------- /** * @brief Shake event types with associated emotions */ typedef enum { SHAKE_NONE = 0, // No shake detected SHAKE_SURPRISED, // Quick shake - surprised emotion SHAKE_SAD, // Shake detected - sad emotion SHAKE_ANGRY // Shake detected - angry emotion } 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); #ifdef __cplusplus } #endif #endif // SHAKE_DETECTOR_H