OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
Loading...
Searching...
No Matches
InternalTypes.hpp File Reference

Types and constants used everywhere for firmware implementation. More...

#include <cstdint>
#include <cassert>
#include <array>
#include <vector>
#include <stdexcept>
#include <semaphore>
#include <chrono>
#include <optional>
#include "esp_task_wdt.h"

Go to the source code of this file.

Classes

struct  FakeInput
 Fake input specification used for testing. More...
 
struct  DeviceCapabilities
 Set of device capabilities. More...
 
class  BitQueue
 Queue for 61 bits. More...
 
struct  DecouplingEvent
 Decoupling event. More...
 
struct  BatteryStatus
 Battery status. More...
 
struct  BatteryStatusChrData
 Data format for the Battery Level Status characteristic (packed) More...
 
struct  InternalEvent< eventType, _Args >
 Subscribable events. More...
 
struct  InternalEvent< eventType, void >
 Subscribable events requiring void handlers. More...
 

Macros

#define PRIVATE   private
 For tesing.
 
#define PROTECTED   protected
 For tesing.
 
#define BITMASK(count, first)
 Return a mask for a number of consecutive buttons (count) starting from first. A mask is a bit array where each bit determines if a button is to be used or not. 1 means not used. 0 means in use. Masks are required to combine the state from multiple input bitmaps. For example, BITMASK(2,2) returns 0b(...)11110011 which means that buttons numbered 2 and 3 are in use.
 
#define NBITMASK(count, first)
 Return the logical negation of a bit mask.
 
#define CLUTCH_NONE_VALUE   0
 Value for a fully released clutch.
 
#define CLUTCH_FULL_VALUE   254
 Value for a fully engaged clutch.
 
#define CLUTCH_DEFAULT_VALUE   127
 Default bite point value.
 
#define CLUTCH_1_4_VALUE   64
 Value for 1/4 engaged clutch.
 
#define CLUTCH_3_4_VALUE   192
 Value for 3/4 engaged clutch.
 
#define CLUTCH_INVALID_VALUE   255
 Invalid clutch value used for masking.
 
#define INPUT_TASK_PRIORITY   (tskIDLE_PRIORITY + 2)
 Priority of background tasks.
 
#define MAX_DECOUPLING_EVENT_COUNT   64
 Queue size for decoupling events.
 
#define AUTO_POWER_OFF_DELAY_SECS   60
 Time to wait for connection before power off (in seconds)
 

Typedefs

typedef InternalEvent< InternalEventType::Start, void > OnStart
 System startup.
 
typedef InternalEvent< InternalEventType::Shutdown, void > OnShutdown
 The system is about to shutdown.
 
typedef InternalEvent< InternalEventType::Disconnected, void > OnDisconnected
 No host connection.
 
typedef InternalEvent< InternalEventType::Connected, void > OnConnected
 Host connection.
 
typedef InternalEvent< InternalEventType::BitePoint, uint8_t > OnBitePoint
 New bite point.
 
typedef InternalEvent< InternalEventType::ClutchWorkingMode, ClutchWorkingModeOnClutchWorkingMode
 New clutch working mode.
 
typedef InternalEvent< InternalEventType::AltButtonsWorkingMode, AltButtonsWorkingModeOnAltButtonsWorkingMode
 New ALT buttons working mode.
 
typedef InternalEvent< InternalEventType::DPadWorkingMode, void > OnDPadWorkingMode
 New DPAD working mode.
 
typedef InternalEvent< InternalEventType::SettingsSaved, void > OnSettingsSaved
 Save event.
 
typedef InternalEvent< InternalEventType::PulseWidthMultiplier, PulseWidthMultiplierOnPulseWidthMultiplier
 New pulse width multiplier.
 
typedef InternalEvent< InternalEventType::LowBattery, void > OnLowBattery
 Notified when a low battery condition is detected.
 
typedef InternalEvent< InternalEventType::NewBatteryStatus, const BatteryStatus & > OnBatteryStatus
 New battery level (state of charge) or battery status.
 
typedef InternalEvent< InternalEventType::LoadSetting, UserSettingLoadSetting
 Request to load a user setting.
 
typedef InternalEvent< InternalEventType::SaveSetting, UserSettingSaveSetting
 Request to save a user setting.
 

Enumerations

enum class  DeviceCapability : uint8_t {
  CLUTCH_BUTTON = 0 , CLUTCH_ANALOG = 1 , ALT = 2 , DPAD = 3 ,
  BATTERY = 4 , BATTERY_CALIBRATION_AVAILABLE = 5 , TELEMETRY_POWERTRAIN = 6 , TELEMETRY_ECU = 7 ,
  TELEMETRY_RACE_CONTROL = 8 , TELEMETRY_GAUGES = 9 , ROTARY_ENCODERS = 10 , _MAX_VALUE = ROTARY_ENCODERS
}
 Enumeration of device capabilities. More...
 
enum class  ClutchWorkingMode : uint8_t {
  CLUTCH = 0 , AXIS , ALT , BUTTON ,
  LAUNCH_CONTROL_MASTER_LEFT , LAUNCH_CONTROL_MASTER_RIGHT , _MAX_VALUE = LAUNCH_CONTROL_MASTER_RIGHT , _DEFAULT_VALUE = CLUTCH
}
 User-selected working mode of the clutch paddles. More...
 
enum class  AltButtonsWorkingMode : uint8_t { Regular = 0 , ALT , _MAX_VALUE = ALT , _DEFAULT_VALUE = ALT }
 User-selected working mode of "ALT" buttons. More...
 
enum class  PulseWidthMultiplier : uint8_t {
  X1 = 1 , X2 , X3 , X4 ,
  X5 , X6 , _MAX_VALUE = X6 , _DEFAULT_VALUE = X2
}
 User-selected pulse width multiplier. More...
 
enum class  DPadWorkingMode : uint8_t { Regular = 0 , Navigation , _MAX_VALUE = Navigation , _DEFAULT_VALUE = Navigation }
 User-selected working mode of directional pads. More...
 
enum class  InternalEventType : uint8_t {
  Start , Shutdown , Disconnected , Connected ,
  BitePoint , ClutchWorkingMode , AltButtonsWorkingMode , DPadWorkingMode ,
  SettingsSaved , PulseWidthMultiplier , LowBattery , SaveSetting ,
  LoadSetting , NewBatteryStatus
}
 Available internal event types. More...
 
enum class  UserSetting : uint8_t {
  ALL = 0 , AXIS_CALIBRATION , AXIS_POLARITY , PULSE_WIDTH ,
  SECURITY_LOCK , BITE_POINT , CLUTCH_WORKING_MODE , ALT_WORKING_MODE ,
  DPAD_WORKING_MODE , INPUT_MAP , CUSTOM_HARDWARE_ID , BATTERY_AUTO_CALIBRATION ,
  BATTERY_CALIBRATION_DATA , _MAX_VALUE = BATTERY_CALIBRATION_DATA
}
 User setting to be stored in flash memory. More...
 
enum  SimpleCommand {
  CMD_RESERVED = 0 , CMD_AXIS_RECALIBRATE = 1 , CMD_BATT_RECALIBRATE = 2 , CMD_RESET_BUTTONS_MAP = 3 ,
  CMD_SAVE_NOW = 4 , CMD_REVERSE_LEFT_AXIS = 5 , CMD_REVERSE_RIGHT_AXIS = 6 , CMD_SHOW_PIXELS = 7 ,
  CMD_RESET_PIXELS = 8 , _MAX_VALUE = 8
}
 Simple commands accepted from a feature HID report. More...
 

Detailed Description

Types and constants used everywhere for firmware implementation.

Author
Ángel Fernández Pineda. Madrid. Spain.
Date
2025-02-04

Definition in file InternalTypes.hpp.

Macro Definition Documentation

◆ AUTO_POWER_OFF_DELAY_SECS

#define AUTO_POWER_OFF_DELAY_SECS   60

Time to wait for connection before power off (in seconds)

Definition at line 775 of file InternalTypes.hpp.

◆ BITMASK

#define BITMASK ( count,
first )
Value:
~(((1ULL << static_cast<uint64_t>(count)) - 1ULL) \
<< static_cast<uint64_t>(first))

Return a mask for a number of consecutive buttons (count) starting from first. A mask is a bit array where each bit determines if a button is to be used or not. 1 means not used. 0 means in use. Masks are required to combine the state from multiple input bitmaps. For example, BITMASK(2,2) returns 0b(...)11110011 which means that buttons numbered 2 and 3 are in use.

Definition at line 112 of file InternalTypes.hpp.

◆ CLUTCH_1_4_VALUE

#define CLUTCH_1_4_VALUE   64

Value for 1/4 engaged clutch.

Definition at line 236 of file InternalTypes.hpp.

◆ CLUTCH_3_4_VALUE

#define CLUTCH_3_4_VALUE   192

Value for 3/4 engaged clutch.

Definition at line 238 of file InternalTypes.hpp.

◆ CLUTCH_DEFAULT_VALUE

#define CLUTCH_DEFAULT_VALUE   127

Default bite point value.

Definition at line 234 of file InternalTypes.hpp.

◆ CLUTCH_FULL_VALUE

#define CLUTCH_FULL_VALUE   254

Value for a fully engaged clutch.

Definition at line 232 of file InternalTypes.hpp.

◆ CLUTCH_INVALID_VALUE

#define CLUTCH_INVALID_VALUE   255

Invalid clutch value used for masking.

Definition at line 240 of file InternalTypes.hpp.

◆ CLUTCH_NONE_VALUE

#define CLUTCH_NONE_VALUE   0

Value for a fully released clutch.

Definition at line 230 of file InternalTypes.hpp.

◆ INPUT_TASK_PRIORITY

#define INPUT_TASK_PRIORITY   (tskIDLE_PRIORITY + 2)

Priority of background tasks.

Definition at line 306 of file InternalTypes.hpp.

◆ MAX_DECOUPLING_EVENT_COUNT

#define MAX_DECOUPLING_EVENT_COUNT   64

Queue size for decoupling events.

Definition at line 397 of file InternalTypes.hpp.

◆ NBITMASK

#define NBITMASK ( count,
first )
Value:
(((1ULL << static_cast<uint64_t>(count)) - 1ULL) \
<< static_cast<uint64_t>(first))

Return the logical negation of a bit mask.

Definition at line 120 of file InternalTypes.hpp.

◆ PRIVATE

#define PRIVATE   private

For tesing.

Definition at line 29 of file InternalTypes.hpp.

◆ PROTECTED

#define PROTECTED   protected

For tesing.

Definition at line 32 of file InternalTypes.hpp.

Typedef Documentation

◆ LoadSetting

typedef InternalEvent<InternalEventType::LoadSetting, UserSetting> LoadSetting

Request to load a user setting.

Note
Notified when a user setting must be loaded

Definition at line 758 of file InternalTypes.hpp.

◆ OnAltButtonsWorkingMode

New ALT buttons working mode.

Note
Notified when that working mode changes

Definition at line 712 of file InternalTypes.hpp.

◆ OnBatteryStatus

New battery level (state of charge) or battery status.

Note
Notified when the state of charge changes by 1% or more.

Definition at line 751 of file InternalTypes.hpp.

◆ OnBitePoint

New bite point.

Note
Notified when the clutch's bite point changes

Definition at line 696 of file InternalTypes.hpp.

◆ OnClutchWorkingMode

New clutch working mode.

Note
Notified when that working mode changes

Definition at line 703 of file InternalTypes.hpp.

◆ OnConnected

Host connection.

Note
Notified when this condition is detected.

Definition at line 690 of file InternalTypes.hpp.

◆ OnDisconnected

No host connection.

Note
Notified when this condition is detected, but not while it persists.

Definition at line 684 of file InternalTypes.hpp.

◆ OnDPadWorkingMode

New DPAD working mode.

Note
Notified when that working mode changes

Definition at line 719 of file InternalTypes.hpp.

◆ OnLowBattery

Notified when a low battery condition is detected.

Note
This event is notified at timed intervals while the condition persists.

Definition at line 742 of file InternalTypes.hpp.

◆ OnPulseWidthMultiplier

New pulse width multiplier.

Note
Notified when changed

Definition at line 735 of file InternalTypes.hpp.

◆ OnSettingsSaved

Save event.

Note
Notified when a user setting is saved to persistent storage

Definition at line 726 of file InternalTypes.hpp.

◆ OnShutdown

The system is about to shutdown.

Note
Notified only once.

Definition at line 677 of file InternalTypes.hpp.

◆ OnStart

System startup.

Note
Notified only once.

Definition at line 671 of file InternalTypes.hpp.

◆ SaveSetting

typedef InternalEvent<InternalEventType::SaveSetting, UserSetting> SaveSetting

Request to save a user setting.

Note
Notified when a user setting must be saved to persistent storage

Definition at line 765 of file InternalTypes.hpp.

Enumeration Type Documentation

◆ AltButtonsWorkingMode

enum class AltButtonsWorkingMode : uint8_t
strong

User-selected working mode of "ALT" buttons.

Enumerator
Regular 

Regular button.

ALT 

Engage or disengage alternate mode.

Definition at line 250 of file InternalTypes.hpp.

◆ ClutchWorkingMode

enum class ClutchWorkingMode : uint8_t
strong

User-selected working mode of the clutch paddles.

Enumerator
CLUTCH 

F1-Style clutch. Must be the first in the enum: do not change.

AXIS 

Independent axes.

ALT 

Alternate mode.

BUTTON 

Regular buttons.

LAUNCH_CONTROL_MASTER_LEFT 

Launch control (left paddle is master)

LAUNCH_CONTROL_MASTER_RIGHT 

Launch control (right paddle is master)

Definition at line 211 of file InternalTypes.hpp.

◆ DeviceCapability

enum class DeviceCapability : uint8_t
strong

Enumeration of device capabilities.

Enumerator
CLUTCH_BUTTON 

Has digital clutch paddles (switches)

CLUTCH_ANALOG 

Has analog clutch paddles (potentiometers)

ALT 

Has "ALT" buttons.

DPAD 

Has a directional pad.

BATTERY 

Battery-operated.

BATTERY_CALIBRATION_AVAILABLE 

Has battery calibration data.

TELEMETRY_POWERTRAIN 

Able to display powertrain telemetry data.

TELEMETRY_ECU 

Able to display ECU telemetry data.

TELEMETRY_RACE_CONTROL 

Able to display race control telemetry data.

TELEMETRY_GAUGES 

Able to display telemetry data for gauges.

ROTARY_ENCODERS 

Has one or more rotary encoders.

Definition at line 132 of file InternalTypes.hpp.

◆ DPadWorkingMode

enum class DPadWorkingMode : uint8_t
strong

User-selected working mode of directional pads.

Enumerator
Regular 

Regular button.

Navigation 

Navigation control.

Definition at line 288 of file InternalTypes.hpp.

◆ InternalEventType

enum class InternalEventType : uint8_t
strong

Available internal event types.

Enumerator
Start 

System startup.

Shutdown 

Sytem shutdown.

Disconnected 

Discovery mode started.

Connected 

Device connected to a host computer.

BitePoint 

The bite point has changed.

ClutchWorkingMode 

The clutch working mode has changed.

AltButtonsWorkingMode 

The ALT buttons working mode has changed.

DPadWorkingMode 

The DPAD working mode has changed.

SettingsSaved 

User settings were saved.

PulseWidthMultiplier 

The pulse width multiplier has changed.

LowBattery 

The system is in a low battery state (repeated at timed intervals)

SaveSetting 

Request to save a user setting.

LoadSetting 

Request to load a user setting.

NewBatteryStatus 

Change in battery status or battery level.

Definition at line 517 of file InternalTypes.hpp.

◆ PulseWidthMultiplier

enum class PulseWidthMultiplier : uint8_t
strong

User-selected pulse width multiplier.

Definition at line 268 of file InternalTypes.hpp.

◆ SimpleCommand

Simple commands accepted from a feature HID report.

Enumerator
CMD_RESERVED 

Not a command, reserved to avoid mistakes.

CMD_AXIS_RECALIBRATE 

Recalibrate analog axes (if any)

CMD_BATT_RECALIBRATE 

Restart battery auto-calibration.

CMD_RESET_BUTTONS_MAP 

Reset buttons map to factory defaults.

CMD_SAVE_NOW 

Save all user settings to flash memory immediately.

CMD_REVERSE_LEFT_AXIS 

Reverse left axis (if any)

CMD_REVERSE_RIGHT_AXIS 

Reverse right axis (if any)

CMD_SHOW_PIXELS 

Display all pixels in all pixel groups.

CMD_RESET_PIXELS 

Turn off all pixels in all groups.

Definition at line 785 of file InternalTypes.hpp.

◆ UserSetting

enum class UserSetting : uint8_t
strong

User setting to be stored in flash memory.

Warning
Must be in the range [0,63]

Definition at line 556 of file InternalTypes.hpp.