Files
iroBotAMOLED_Test/main/sensors/glide_detector.h
Neil Arora 22bd5a6f70 update: fixed shake animation
The shake animation figures have been fixed. However, the petting emotion working with touch remains an issue. The Lottie JSON for the emotion is unable not parsable for some reason and my next step is to fix that for tomorrow's meeting.
2026-01-27 00:30:12 +05:30

137 lines
4.0 KiB
C

/**
* @file glide_detector.h
* @brief Glide gesture detection interface for touch input
*
* This module provides glide gesture detection using touch coordinates.
* It detects when a finger glides across the screen with continuous motion
* and can trigger emotional responses in the display system.
*/
#ifndef GLIDE_DETECTOR_H
#define GLIDE_DETECTOR_H
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// ----------------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------------
// Minimum distance (in pixels) to qualify as a glide gesture
#define GLIDE_MIN_DISTANCE 80
// Maximum time (in milliseconds) between touch points to consider continuous
#define GLIDE_MAX_TIME_BETWEEN_POINTS 300
// Maximum time (in milliseconds) for a complete glide gesture
#define GLIDE_MAX_GESTURE_TIME 1000
// Maximum number of touch points to track per gesture
#define GLIDE_MAX_TOUCH_POINTS 32
// ----------------------------------------------------------------------------
// Type Definitions
// ----------------------------------------------------------------------------
/**
* @brief Glide direction types
*/
typedef enum {
GLIDE_DIRECTION_NONE = 0, // No direction
GLIDE_DIRECTION_HORIZONTAL, // Horizontal glide (left or right)
GLIDE_DIRECTION_VERTICAL, // Vertical glide (up or down)
GLIDE_DIRECTION_DIAGONAL // Diagonal glide
} GlideDirection;
/**
* @brief Touch point data structure
*/
typedef struct {
uint16_t x; // X coordinate
uint16_t y; // Y coordinate
uint32_t timestamp; // Timestamp in milliseconds
} TouchPoint;
/**
* @brief Glide event data
*/
typedef struct {
GlideDirection direction; // Direction of glide
float distance; // Total distance in pixels
float deltaX; // X displacement
float deltaY; // Y displacement
uint32_t duration; // Gesture duration in milliseconds
} GlideEvent;
/**
* @brief Glide event callback function type
*
* @param event Pointer to the glide event data
* @param user_data User-provided data passed during registration
*/
typedef void (*GlideCallback)(const GlideEvent *event, void *user_data);
// ----------------------------------------------------------------------------
// Public API
// ----------------------------------------------------------------------------
/**
* @brief Initialize the glide detector
*
* Initializes internal state and prepares the detector for touch events.
* Call this once during system initialization.
*
* @return true on successful initialization, false on failure
*/
bool glideDetectorInit(void);
/**
* @brief Update the glide detector with a touch event
*
* Should be called for each touch event (press, move, release) from the
* touch input system. The detector tracks touch points and determines if
* a glide gesture has occurred.
*
* @param x Touch X coordinate (0 to DISPLAY_WIDTH)
* @param y Touch Y coordinate (0 to DISPLAY_HEIGHT)
* @param pressed true if touch is pressed, false if released
* @return true if a glide was detected in this update, false otherwise
*/
bool glideDetectorUpdate(uint16_t x, uint16_t y, bool pressed);
/**
* @brief Register a callback for glide events
*
* The callback will be invoked when a glide gesture is detected.
* Only one callback can be registered at a time.
*
* @param callback Function pointer to the callback
* @param user_data User data to pass to the callback (can be NULL)
*/
void glideDetectorRegisterCallback(GlideCallback callback, void *user_data);
/**
* @brief Reset the glide detector state
*
* Clears all tracked touch points and resets the state machine to IDLE.
* Use this to abort an in-progress gesture or after a timeout.
*/
void glideDetectorReset(void);
/**
* @brief Get the current number of tracked touch points
*
* @return Number of touch points currently being tracked
*/
uint8_t glideDetectorGetPointCount(void);
#ifdef __cplusplus
}
#endif
#endif // GLIDE_DETECTOR_H