Event

Type-safe event definitions and data structures

#include <Events.h>

Public Member Functions

 Event ()
 
 Event (EventType t)
 
 Event (EventType t, int32_t v)
 
void setStringData (const String &str)
 
String getStringData () const
 
bool hasStringData () const
 
void clearStringData ()
 
void setWiFiData (const char *ssid, const char *ip="", int32_t connectionTime=0)
 
String getSSID () const
 
String getIP () const
 
int32_t getConnectionTime () const
 
int32_t getRotationDelta () const
 
int32_t getPressDuration () const
 
bool isClockwise () const
 
bool isLongPress (int32_t threshold=1000) const
 

Public Attributes

EventType type
 
int32_t value
 
char stringData [256]
 

Detailed Description

Event Data Structure

Unified data container for all event types with optimized memory layout. Designed for efficient FreeRTOS queue transmission and minimal memory usage.

Memory Layout:

  • type: 4 bytes (EventType enumeration)
  • value: 4 bytes (signed 32-bit integer for counters, timing, codes)
  • stringData: 256 bytes (null-terminated string buffer)
  • Total: 264 bytes (aligned for efficient queue operations)

Design Principles:

  • Fixed size for predictable memory usage
  • No pointers to avoid cross-task memory issues
  • Embedded string buffer to prevent heap fragmentation
  • Helper methods for common data patterns
  • Safe defaults and automatic null termination

Constructor & Destructor Documentation

◆ Event() [1/3]

CloudMouse::Event::Event ( )
inline

Default constructor - creates safe empty event Initializes with ENCODER_ROTATION type and zero values

◆ Event() [2/3]

CloudMouse::Event::Event ( EventType  t)
inline

Type-only constructor Creates event with specified type and zero values

Parameters
tEvent type from EventType enumeration

◆ Event() [3/3]

CloudMouse::Event::Event ( EventType  t,
int32_t  v 
)
inline

Type and value constructor Creates event with specified type and numeric value

Parameters
tEvent type from EventType enumeration
vNumeric value (counter, timing, error code, etc.)

Member Function Documentation

◆ clearStringData()

void CloudMouse::Event::clearStringData ( )
inline

Clear string data buffer Resets string buffer to empty state

◆ getConnectionTime()

int32_t CloudMouse::Event::getConnectionTime ( ) const
inline

Get WiFi connection time from value field Convenience accessor for connection timing data

Returns
Connection time in milliseconds

◆ getIP()

String CloudMouse::Event::getIP ( ) const
inline

Extract IP address from WiFi event data Parses IP address from "SSID|IP" format string

Returns
IP address string, or empty string if no separator found

◆ getPressDuration()

int32_t CloudMouse::Event::getPressDuration ( ) const
inline

Get encoder press duration Returns button press time for click/long-press differentiation

Returns
Press duration in milliseconds

◆ getRotationDelta()

int32_t CloudMouse::Event::getRotationDelta ( ) const
inline

Get encoder rotation delta Returns rotation amount with sign indicating direction

Returns
Rotation clicks (positive = clockwise, negative = counter-clockwise)

◆ getSSID()

String CloudMouse::Event::getSSID ( ) const
inline

Extract SSID from WiFi event data Parses SSID from "SSID|IP" format string

Returns
SSID string, or complete string if no separator found

◆ getStringData()

String CloudMouse::Event::getStringData ( ) const
inline

Get string payload as Arduino String object Safe accessor that always returns valid string (empty if unset)

Returns
String object containing current string data

◆ hasStringData()

bool CloudMouse::Event::hasStringData ( ) const
inline

Check if string data is present and non-empty

Returns
true if string data contains at least one character

◆ isClockwise()

bool CloudMouse::Event::isClockwise ( ) const
inline

Check if encoder rotation is clockwise

Returns
true if rotation value is positive (clockwise)

◆ isLongPress()

bool CloudMouse::Event::isLongPress ( int32_t  threshold = 1000) const
inline

Check if encoder press qualifies as long press Uses common threshold of 1000ms for long press detection

Parameters
thresholdLong press threshold in milliseconds (default: 1000)
Returns
true if press duration exceeds threshold

◆ setStringData()

void CloudMouse::Event::setStringData ( const String &  str)
inline

Set string payload with automatic truncation and null termination Safely copies string data with bounds checking to prevent buffer overflow

Parameters
strString data to store (will be truncated if > 255 characters)

◆ setWiFiData()

void CloudMouse::Event::setWiFiData ( const char *  ssid,
const char *  ip = "",
int32_t  connectionTime = 0 
)
inline

Set WiFi-specific data using structured format Stores SSID, IP address, and connection timing in standardized format Format: "SSID|IP_ADDRESS" with connection time in value field

Parameters
ssidNetwork SSID (max ~120 characters)
ipIP address string (typically "192.168.1.100" format)
connectionTimeConnection duration in milliseconds (stored in value)

Member Data Documentation

◆ stringData

char CloudMouse::Event::stringData[256]

◆ type

EventType CloudMouse::Event::type

◆ value

int32_t CloudMouse::Event::value

The documentation for this struct was generated from the following file: