29#define PRIVATE private
30#include "esp_task_wdt.h"
32#define PROTECTED protected
37#define PROTECTED public
68 uint64_t bmp = (1ULL << n);
79 uint64_t bmp = (1ULL << n);
112#define BITMASK(count, first) \
113 ~(((1ULL << static_cast<uint64_t>(count)) - 1ULL) \
114 << static_cast<uint64_t>(first))
120#define NBITMASK(count, first) \
121 (((1ULL << static_cast<uint64_t>(count)) - 1ULL) \
122 << static_cast<uint64_t>(first))
175 _flags |= (1 <<
static_cast<uint8_t
>(capability));
177 _flags &= ~(1 <<
static_cast<uint8_t
>(capability));
189 return _flags & (1 <<
static_cast<uint8_t
>(capability));
200 inline static uint16_t _flags = 0;
230#define CLUTCH_NONE_VALUE 0
232#define CLUTCH_FULL_VALUE 254
234#define CLUTCH_DEFAULT_VALUE 127
236#define CLUTCH_1_4_VALUE 64
238#define CLUTCH_3_4_VALUE 192
240#define CLUTCH_INVALID_VALUE 255
306#define INPUT_TASK_PRIORITY (tskIDLE_PRIORITY + 2)
330 uint8_t bqTailNext = bqTail;
331 incDataPointer(bqTailNext);
332 if (bqTailNext != bqHead)
335 uint64_t aux = (1ULL << bqTail);
352 bool isNotEmpty = (bqHead != bqTail);
355 uint64_t bitState = (1ULL << bqHead) & bitsQueue;
356 value = (bitState != 0ULL);
357 incDataPointer(bqHead);
364 PRIVATE : uint64_t bitsQueue = 0ULL;
368 inline static void incDataPointer(uint8_t &pointer)
370 pointer = (pointer + 1) % 64;
397#define MAX_DECOUPLING_EVENT_COUNT 64
504 "Wrong size of BatteryStatusChrData (check struct packaging)");
569 BATTERY_AUTO_CALIBRATION,
570 BATTERY_CALIBRATION_DATA,
571 _MAX_VALUE = BATTERY_CALIBRATION_DATA
598 if (callback !=
nullptr)
599 _callbacks.push_back(callback);
609 for (
auto callback : _callbacks)
612 esp_task_wdt_reset();
614 callback(std::forward<_Args>(__args)...);
619 inline static std::vector<Callback> _callbacks = {};
627template <InternalEventType eventType>
640 if (callback !=
nullptr)
641 _callbacks.push_back(callback);
650 for (
auto callback : _callbacks)
664 inline static std::vector<Callback> _callbacks = {};
775#define AUTO_POWER_OFF_DELAY_SECS 60
InternalEvent< InternalEventType::SaveSetting, UserSetting > SaveSetting
Request to save a user setting.
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.
InternalEventType
Available internal event types.
@ LowBattery
The system is in a low battery state (repeated at timed intervals)
@ Shutdown
Sytem shutdown.
@ Connected
Device connected to a host computer.
@ NewBatteryStatus
Change in battery status or battery level.
@ AltButtonsWorkingMode
The ALT buttons working mode has changed.
@ BitePoint
The bite point has changed.
@ SettingsSaved
User settings were saved.
@ PulseWidthMultiplier
The pulse width multiplier has changed.
@ Disconnected
Discovery mode started.
InternalEvent< InternalEventType::SettingsSaved, void > OnSettingsSaved
Save event.
InternalEvent< InternalEventType::Shutdown, void > OnShutdown
The system is about to shutdown.
InternalEvent< InternalEventType::NewBatteryStatus, const BatteryStatus & > OnBatteryStatus
New battery level (state of charge) or battery status.
InternalEvent< InternalEventType::DPadWorkingMode, void > OnDPadWorkingMode
New DPAD working mode.
InternalEvent< InternalEventType::Connected, void > OnConnected
Host connection.
InternalEvent< InternalEventType::Start, void > OnStart
System startup.
InternalEvent< InternalEventType::ClutchWorkingMode, ClutchWorkingMode > OnClutchWorkingMode
New clutch working mode.
#define PRIVATE
For tesing.
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.
InternalEvent< InternalEventType::Disconnected, void > OnDisconnected
No host connection.
InternalEvent< InternalEventType::LowBattery, void > OnLowBattery
Notified when a low battery condition is detected.
InternalEvent< InternalEventType::PulseWidthMultiplier, PulseWidthMultiplier > OnPulseWidthMultiplier
New pulse width multiplier.
InternalEvent< InternalEventType::BitePoint, uint8_t > OnBitePoint
New bite point.
DeviceCapability
Enumeration of device capabilities.
@ TELEMETRY_POWERTRAIN
Able to display powertrain telemetry data.
@ DPAD
Has a directional pad.
@ 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.
DPadWorkingMode
User-selected working mode of directional pads.
@ Navigation
Navigation control.
InternalEvent< InternalEventType::AltButtonsWorkingMode, AltButtonsWorkingMode > OnAltButtonsWorkingMode
New ALT buttons working mode.
UserSetting
User setting to be stored in flash memory.
InternalEvent< InternalEventType::LoadSetting, UserSetting > LoadSetting
Request to load a user setting.
void enqueue(bool value)
Push a bit into the queue.
bool dequeue(bool &value)
Extract a bit from the queue.
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.
uint8_t rightAxisValue
Position of the right axis.
uint64_t rawInputBitmap
Input bitmap.
uint64_t rawInputChanges
Bitmap of changes from the previous event.
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.
static void subscribe(Callback callback)
Subscribe to this event.
static void clearSubscriptions()
Clear subscriptions (for testing)
static void notify()
Invoke all subscribed callbacks.
void(*) Callback(_Args...)
Callback prototype.
static void notify(_Args... __args)
Invoke all subscribed callbacks.
static void subscribe(Callback callback)
Subscribe to this event.