CloudMouse

Core namespace with global functions and enums

Namespaces

 Hardware
 
 Network
 
 Prefs
 Preferences management components.
 
 Utils
 

Classes

class  Core
 
class  EventBus
 
struct  Event
 

Enumerations

enum class  SystemState {
  BOOTING , INITIALIZING , WIFI_CONNECTING , WIFI_CONNECTED ,
  WIFI_AP_MODE , WIFI_ERROR , READY , RUNNING ,
  ERROR
}
 
enum class  EventType {
  BOOTING_COMPLETE , ENCODER_ROTATION , ENCODER_CLICK , ENCODER_LONG_PRESS ,
  DISPLAY_WAKE_UP , DISPLAY_UPDATE , DISPLAY_CLEAR , DISPLAY_WIFI_CONNECTING ,
  DISPLAY_WIFI_CONNECTED , DISPLAY_WIFI_ERROR , DISPLAY_WIFI_AP_MODE , DISPLAY_WIFI_SETUP_URL ,
  WIFI_CONNECTING , WIFI_CONNECTED , WIFI_DISCONNECTED , WIFI_ERROR ,
  WIFI_AP_MODE
}
 

Detailed Description

CloudMouse SDK - Device Configuration Header

Central configuration hub for hardware variants, firmware versioning, and device-specific settings. Provides compile-time configuration management with PCB version compatibility, network settings, and device identification integration.

Configuration Categories:

  • Hardware PCB version selection with power management implications
  • Firmware version tracking for OTA updates and compatibility
  • WiFi network configuration and Access Point settings
  • Device identification macros with automatic ID generation
  • Service endpoint configuration for web-based setup

PCB Version Management:

  • Version 4: Legacy power logic (inverted enable signals)
  • Version 5: Updated power logic (normal enable signals)
  • Compile-time selection prevents hardware damage from incorrect logic
  • Affects display power management and potentially other peripherals

Device Identity System:

  • Automatic device ID generation based on MAC address
  • Unique UUID creation for cloud service registration
  • Secure Access Point credentials derived from hardware ID
  • Consistent device identification across firmware updates

Network Configuration:

  • WiFi requirement flags for deployment flexibility
  • Access Point configuration for device setup mode
  • Web service endpoints for configuration interface
  • Standardized URLs for user setup experience

Usage in SDK:

  • Include this header in all hardware-dependent modules
  • Use macros instead of hardcoded values for flexibility
  • PCB_VERSION affects power management logic in display drivers
  • Device ID macros provide consistent identification across modules
  • Configuration changes require recompilation for safety

CloudMouse SDK - Core System Implementation

Main system controller that orchestrates all CloudMouse components. Handles dual-core operation, event processing, and system lifecycle.

CloudMouse SDK - Core System

The Core is the heart of the CloudMouse SDK, providing:

  • Dual-core task management (UI on Core 1, Logic on Core 0)
  • Event-driven architecture with hardware abstraction
  • System state management and lifecycle control
  • Component registration and coordination

Architecture:

  • Core 0: Main coordination, WiFi, event processing, system health
  • Core 1: UI rendering, encoder input, display updates (30Hz)

CloudMouse SDK - Event Bus Implementation

Thread-safe event communication system using FreeRTOS queues for reliable inter-task messaging. Implements bidirectional communication channels with comprehensive error handling and monitoring.

Implementation Details:

  • Uses FreeRTOS xQueueCreate for queue allocation with fixed event size
  • Copy semantics for events ensure thread safety without pointer sharing
  • Non-blocking operations with configurable timeout support
  • Comprehensive error checking and status reporting
  • Memory-efficient fixed-size allocation strategy

Performance Characteristics:

  • Queue operations: O(1) constant time complexity
  • Memory usage: ~5.3KB for both queues (predictable footprint)
  • Latency: < 1ms for queue operations on ESP32 @ 240MHz
  • Throughput: > 10,000 events/second sustainable rate

Error Conditions:

  • Queue creation failure: Insufficient heap memory
  • Queue full conditions: Sending task faster than receiving task
  • Invalid operations: Attempting operations before initialization

CloudMouse SDK - Event Bus Communication System

Thread-safe bidirectional communication hub for inter-task messaging using FreeRTOS queues. Enables reliable event-driven architecture between Core system tasks and UI rendering tasks.

Architecture:

  • Singleton pattern for global access and resource management
  • Dual-queue system for bidirectional communication (UI ↔ Core)
  • Non-blocking and blocking send/receive operations with configurable timeouts
  • Queue monitoring and diagnostics for system health and debugging
  • Thread-safe operations suitable for multi-core ESP32 architecture

Communication Flow: Core Task → sendToUI() → UI Queue → receiveFromMain() → UI Task UI Task → sendToMain() → Main Queue → receiveFromUI() → Core Task

Queue Management:

  • Each queue holds up to 10 events (configurable QUEUE_SIZE)
  • Events are copied into queue (no pointer sharing for thread safety)
  • FIFO ordering ensures event sequence preservation
  • Automatic queue overflow detection and reporting

Usage Patterns:

  1. HardwareCore: Encoder events, system state changes
  2. Core → UI: Display updates, status changes, error notifications
  3. UI → Core: User actions, configuration changes, requests
  4. System-wide: Boot sequence coordination, shutdown procedures

Performance Characteristics:

  • Low latency: < 1ms for queue operations on ESP32
  • Memory efficient: Fixed queue size prevents heap fragmentation
  • Deterministic: Bounded execution time for real-time constraints
  • Scalable: Independent queues prevent cross-task blocking

Error Handling:

  • Queue full conditions are detected and reported
  • Failed sends return false for application error handling
  • Timeout mechanisms prevent indefinite blocking
  • Queue state monitoring for system diagnostics

Thread Safety:

  • All operations are atomic at FreeRTOS queue level
  • No shared mutable state between tasks
  • Safe for concurrent access from multiple cores
  • Events are value-copied to eliminate pointer races

CloudMouse SDK - Event System Core

Comprehensive event type definitions and data structures for thread-safe inter-task communication. Forms the foundation of the SDK's event-driven architecture using FreeRTOS queues.

Architecture:

  • Strongly-typed event enumeration for compile-time safety
  • Fixed-size event structure optimized for FreeRTOS queue transmission
  • Support for numeric data, string payloads, and specialized data formats
  • Memory-efficient design with stack allocation and minimal heap usage
  • Built-in helper methods for common data patterns (WiFi, encoder, display)

Event Flow: Hardware/System → Event Creation → EventBus Queue → Target Task → Event Processing

Usage Patterns:

  1. Hardware events: ENCODER_ROTATION, ENCODER_CLICK, ENCODER_LONG_PRESS
  2. System events: BOOTING_COMPLETE, WIFI_CONNECTED, WIFI_DISCONNECTED
  3. Display events: DISPLAY_UPDATE, DISPLAY_CLEAR, DISPLAY_WAKE_UP
  4. UI events: DISPLAY_WIFI_CONNECTING, DISPLAY_WIFI_SETUP_URL

Memory Layout:

  • Event: ~260 bytes total (4 + 4 + 252 bytes padding)
  • Optimized for FreeRTOS queue efficiency
  • String data uses fixed buffer to avoid heap fragmentation
  • Safe for cross-task transmission without pointer issues

Thread Safety:

  • All Event operations are stack-based and thread-safe
  • No shared mutable state or heap allocations
  • Safe for concurrent access from multiple FreeRTOS tasks
  • Immutable after creation for predictable behavior

Enumeration Type Documentation

◆ EventType

enum CloudMouse::EventType
strong

Event Type Enumeration

Defines all possible events in the CloudMouse SDK ecosystem. Organized by functional category for maintainability and extensibility.

Categories:

  • System: Boot sequence and lifecycle events
  • Encoder: Hardware input events from rotary encoder
  • Display: Screen control and content update events
  • WiFi Display: UI feedback for WiFi connection states
  • WiFi System: Network stack state changes and events
Enumerator
BOOTING_COMPLETE 

System boot sequence completed successfully Fired when all hardware managers are initialized and system is operational Usage: Trigger initial UI state, start main application logic

ENCODER_ROTATION 

Rotary encoder rotation detected value: Rotation delta (-N to +N clicks, positive = clockwise) Usage: Menu navigation, value adjustment, scrolling

ENCODER_CLICK 

Rotary encoder button pressed and released (short press) value: Press duration in milliseconds Usage: Menu selection, action confirmation, mode switching

ENCODER_LONG_PRESS 

Rotary encoder button held down (long press) value: Total press duration in milliseconds Usage: Context menus, settings access, power functions

DISPLAY_WAKE_UP 

Display should wake up from sleep/screensaver Usage: User interaction detected, restore screen brightness

DISPLAY_UPDATE 

Display content should be refreshed stringData: Optional update reason or content identifier Usage: Periodic refresh, data changes, UI state transitions

DISPLAY_CLEAR 

Display should be cleared/reset Usage: Mode transitions, error recovery, screen cleaning

DISPLAY_WIFI_CONNECTING 

Display WiFi connection attempt in progress stringData: SSID being connected to value: Connection attempt number or timeout Usage: Show connecting animation, SSID name, progress indication

DISPLAY_WIFI_CONNECTED 

Display successful WiFi connection status stringData: "SSID|IP_ADDRESS" format (use getSSID/getIP helpers) value: Connection time in milliseconds Usage: Show success message, network info, IP address

DISPLAY_WIFI_ERROR 

Display WiFi connection error or failure stringData: Error message or failed SSID value: Error code or retry count Usage: Show error message, suggest solutions, retry options

DISPLAY_WIFI_AP_MODE 

Display Access Point mode activation stringData: "AP_SSID|AP_PASSWORD" format Usage: Show AP credentials, setup instructions, QR code

DISPLAY_WIFI_SETUP_URL 

Display WiFi setup URL for configuration stringData: Setup URL (typically "http://192.168.4.1") Usage: Show configuration URL, QR code generation, setup instructions

WIFI_CONNECTING 

WiFi connection attempt started stringData: Target SSID value: Timeout in milliseconds Usage: Internal state tracking, LED indicators, system coordination

WIFI_CONNECTED 

WiFi successfully connected with IP assignment stringData: "SSID|IP_ADDRESS|GATEWAY|DNS" format value: Signal strength (RSSI) in dBm Usage: Enable network features, sync time, update status

WIFI_DISCONNECTED 

WiFi connection lost or terminated stringData: Disconnection reason or last known SSID value: Uptime before disconnection in seconds Usage: Disable network features, attempt reconnection, update status

WIFI_ERROR 

WiFi connection error or failure stringData: Error description or failed SSID value: Error code (timeout, authentication, etc.) Usage: Error handling, fallback to AP mode, user notification

WIFI_AP_MODE 

WiFi Access Point mode activated stringData: "AP_SSID|AP_PASSWORD|AP_IP" format Usage: Start web server, enable configuration, LED indicators

◆ SystemState

System state machine for CloudMouse lifecycle management

Enumerator
BOOTING 
INITIALIZING 
WIFI_CONNECTING 
WIFI_CONNECTED 
WIFI_AP_MODE 
WIFI_ERROR 
READY 
RUNNING 
ERROR