25#define PRIVATE private
27#define PROTECTED protected
32#define PROTECTED public
141 _flags |= (1 <<
static_cast<uint8_t
>(capability));
143 _flags &= ~(1 <<
static_cast<uint8_t
>(capability));
155 return _flags & (1 <<
static_cast<uint8_t
>(capability));
166 inline static uint16_t _flags = 0;
196#define CLUTCH_NONE_VALUE 0
198#define CLUTCH_FULL_VALUE 254
200#define CLUTCH_DEFAULT_VALUE 127
202#define CLUTCH_1_4_VALUE 64
204#define CLUTCH_3_4_VALUE 192
206#define CLUTCH_INVALID_VALUE 255
272#define INPUT_TASK_PRIORITY (tskIDLE_PRIORITY + 2)
296 uint8_t bqTailNext = bqTail;
297 incDataPointer(bqTailNext);
298 if (bqTailNext != bqHead)
301 uint64_t aux = (1ULL << bqTail);
318 bool isNotEmpty = (bqHead != bqTail);
321 uint64_t bitState = (1ULL << bqHead) & bitsQueue;
322 value = (bitState != 0ULL);
323 incDataPointer(bqHead);
330 PRIVATE : uint64_t bitsQueue = 0ULL;
334 inline static void incDataPointer(uint8_t &pointer)
336 pointer = (pointer + 1) % 64;
361#define MAX_DECOUPLING_EVENT_COUNT 64
468 "Wrong size of BatteryStatusChrData (check struct packaging)");
496 BATTERY_AUTO_CALIBRATION,
497 BATTERY_CALIBRATION_DATA,
498 _MAX_VALUE = BATTERY_CALIBRATION_DATA
517template <
class... Args>
535 _subscriptions.push_back(callback);
545 _subscriptions.clear();
555 for (
const auto &entry : _subscriptions)
568 for (
const auto &entry : _subscriptions)
581 return _subscriptions.size();
592 _subscriptions.swap(source._subscriptions);
604 _subscriptions = source._subscriptions;
621 _subscriptions = source._subscriptions;
631 _subscriptions.swap(source._subscriptions);
645 return (_subscriptions == other._subscriptions);
650 ::std::vector<callback_type> _subscriptions{};
747#define AUTO_POWER_OFF_DELAY_SECS 60
SimpleCommand
Simple commands accepted from a feature HID report.
@ CMD_SHOW_PIXELS
Display all pixels in all pixel groups.
@ CMD_SAVE_NOW
Save all user settings to flash memory immediately.
@ CMD_AXIS_RECALIBRATE
Recalibrate analog axes (if any)
@ CMD_RESERVED
Not a command, reserved to avoid mistakes.
@ CMD_REVERSE_LEFT_AXIS
Reverse left axis (if any)
@ CMD_RESET_PIXELS
Turn off all pixels in all groups.
@ CMD_BATT_RECALIBRATE
Restart battery auto-calibration.
@ CMD_REVERSE_RIGHT_AXIS
Reverse right axis (if any)
@ CMD_RESET_BUTTONS_MAP
Reset buttons map to factory defaults.
static_event OnStart
System startup.
static_event OnShutdown
The system is about to shutdown.
static_event OnConnected
Host connection.
static_event OnLowBattery
Notified when a low battery condition is detected.
static_event< PulseWidthMultiplier > OnPulseWidthMultiplier
New pulse width multiplier.
#define CLUTCH_NONE_VALUE
Value for a fully released clutch.
static_event< uint8_t > OnBitePoint
New bite point.
#define PRIVATE
For testing.
ClutchWorkingMode
User-selected working mode of the clutch paddles.
@ LAUNCH_CONTROL_MASTER_LEFT
Launch control (left paddle is master)
@ CLUTCH
F1-Style clutch. Must be the first in the enum: do not change.
@ LAUNCH_CONTROL_MASTER_RIGHT
Launch control (right paddle is master)
PulseWidthMultiplier
User-selected pulse width multiplier.
AltButtonsWorkingMode
User-selected working mode of "ALT" buttons.
static_event< UserSetting > SaveSetting
Request to save a user setting.
static_event OnSettingsSaved
Save event.
DeviceCapability
Enumeration of device capabilities.
@ TELEMETRY_POWERTRAIN
Able to display powertrain telemetry data.
@ DPAD
Has a directional pad.
@ TELEMETRY_WHEELS
Able to display wheel telemetry data.
@ CLUTCH_BUTTON
Has digital clutch paddles (switches)
@ BATTERY_CALIBRATION_AVAILABLE
Has battery calibration data.
@ TELEMETRY_RACE_CONTROL
Able to display race control telemetry data.
@ BATTERY
Battery-operated.
@ CLUTCH_ANALOG
Has analog clutch paddles (potentiometers)
@ TELEMETRY_ECU
Able to display ECU telemetry data.
@ ROTARY_ENCODERS
Has one or more rotary encoders.
@ TELEMETRY_GAUGES
Able to display telemetry data for gauges.
static_event< UserSetting > LoadSetting
Request to load a user setting.
static_event< ClutchWorkingMode > OnClutchWorkingMode
New clutch working mode.
static_event< AltButtonsWorkingMode > OnAltButtonsWorkingMode
New ALT buttons working mode.
static_event OnDPadWorkingMode
New DPAD working mode.
DPadWorkingMode
User-selected working mode of directional pads.
@ Navigation
Navigation control.
static_event OnDisconnected
No host connection.
static_event< const BatteryStatus & > OnBatteryStatus
New battery level (state of charge) or battery status.
UserSetting
User setting to be stored in flash memory.
Types and constants required for custom firmware setup.
void enqueue(bool value)
Push a bit into the queue.
bool dequeue(bool &value)
Extract a bit from the queue.
Publish-subscribe event (forever subscribed)
void operator()(const Args &...args) const
Dispatch event to all subscribed callbacks (const)
constexpr bool operator==(const type &other) const noexcept
Equality operator.
void subscribe(callback_type callback) noexcept
Subscribe forever.
typename ::std::add_pointer< void(Args...)>::type callback_type
Callback type for subscribers.
static_event< Args... > type
This type.
type & operator=(const type &source) noexcept
Copy-assignment.
constexpr static_event() noexcept=default
Default constructor.
void clear() noexcept
Clear all subscriptions.
void operator()(const Args &...args)
Dispatch event to all subscribed callbacks.
type & operator=(type &&source) noexcept
Move-assignment.
static_event(type &&source)
Move constructor.
::std::size_t subscribed()
Get the number of subscribed callbacks.
Data format for the Battery Level Status characteristic (packed)
unsigned int as_service_required
Additional status: service required.
unsigned int ps_battery_charge_level
Power state: summarized state of charge.
unsigned int flag_reserved
Flags: reserved for future use.
uint8_t battery_level
Field: Battery level.
unsigned int as_battery_fault
Additional status: battery fault status.
unsigned int flag_id_present
Flags: id field present.
unsigned int ps_wired_ext_power
Power state: is wired external power present.
unsigned int ps_fault_reason
Power state: charging fault reason.
unsigned int ps_battery_charge_state
Power state: battery charging status.
unsigned int flag_battery_level_present
Flags: battery level field present.
unsigned int as_reserved
Additional status: reserved for future use.
unsigned int ps_charging_type
Power state: charging type.
unsigned int flag_additional_status_present
Flags: additional status field present.
unsigned int ps_reserved
Power state: reserved for future use.
unsigned int ps_wireless_ext_power
Power state: is wireless external power present.
unsigned int ps_battery_present
Power state: is battery present.
constexpr bool operator==(const BatteryStatus &other) const noexcept
Compare for equality.
std::optional< bool > usingExternalPower
True if there is wired power.
std::optional< uint8_t > stateOfCharge
Measured battery level in the range from 0% to 100%.
void reset() noexcept
Reset to unknown.
std::optional< bool > isCharging
True if the battery is being charged.
std::optional< bool > isBatteryPresent
False if the battery is not connected.
uint8_t leftAxisValue
Position of the left axis.
uint128_t rawInputBitmap
Input bitmap.
uint8_t rightAxisValue
Position of the right axis.
Set of device capabilities.
static uint16_t getFlags()
Get all flags as a bitmap.
static void setFlag(DeviceCapability capability, bool setOrClear=true)
Clear or set a device capability.
static bool hasFlag(DeviceCapability capability)
Check if a capability is available.
constexpr void set_bit(uint8_t n, bool value=true) noexcept
Set or clear a single bit.