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

System functionality not exposed to the end user. More...

#include "InternalTypes.hpp"
#include "SimWheelTypes.hpp"

Go to the source code of this file.

Namespaces

namespace  internals::hid::common
 Common functionality to all HID implementations.
 

Functions

void internals::batteryMonitor::getReady ()
 Prepare to run.
 
void internals::batteryMonitor::configureForTesting ()
 Configure period, warning and power-off limits for testing.
 
void internals::batteryMonitor::configureFakeMonitor (BatteryStatus *fakeStatus)
 Configure a fake monitor for testing.
 
void * internals::batteryMonitor::getHardwareInstance ()
 Get the Hardware Instance object.
 
void internals::batteryCalibration::getReady ()
 Prepare to run.
 
void internals::batteryCalibration::clear ()
 Clear calibration data (but may persist in flash memory).
 
void internals::batteryCalibration::addSample (int reading)
 Add an ADC reading to calibration data. The battery should get fully charged before first call.
 
void internals::pixels::getReady ()
 Prepare to run.
 
void internals::pixels::set (PixelGroup group, uint8_t pixelIndex, uint8_t red, uint8_t green, uint8_t blue)
 Set the color of a single pixel.
 
void internals::pixels::setAll (PixelGroup group, uint8_t red, uint8_t green, uint8_t blue)
 Set the color of all pixels in a group.
 
void internals::pixels::shiftToNext (PixelGroup group)
 Shift all pixel colors to the next pixel index.
 
void internals::pixels::shiftToPrevious (PixelGroup group)
 Shift all pixel colors to the previous pixel index.
 
void internals::pixels::show ()
 Display all pixels in all groups at once.
 
void internals::pixels::reset ()
 Turn off all pixels in all groups.
 
uint8_t internals::pixels::getCount (PixelGroup group)
 Get the total number of pixels in a group.
 
void internals::ui::getReady ()
 Prepare to run.
 
void internals::inputs::getReady ()
 Prepare to run.
 
void internals::inputs::addFakeInput (FakeInput *instance)
 Add a fake input instance for testing.
 
void internals::inputs::notifyInputEvent (const DecouplingEvent &input)
 Push an input event into the decoupling queue (for testing)
 
void internals::inputHub::getReady ()
 Check that user configuration is correct.
 
void internals::inputHub::onRawInput (DecouplingEvent &input)
 Process a single input event.
 
void internals::storage::getReady ()
 Prepare to run.
 
void internals::inputMap::getReady ()
 Prepare to run.
 
void internals::inputMap::clear ()
 Clear the whole map (for testing) and the custom defaults.
 
void internals::inputMap::map (bool isAltModeEngaged, uint64_t firmware_bitmap, uint64_t &low, uint64_t &high)
 Map a firmware-defined input bitmap.
 
void internals::power::getReady ()
 Prepare to run.
 
void internals::hid::begin (std::string deviceName, std::string deviceManufacturer, bool enableAutoPowerOff, uint16_t VID, uint16_t PID, bool usb_enable=true, bool ble_enable=true, bool exclusive=false)
 Start BLE/Bluetooth HID.
 
bool internals::hid::supportsCustomHardwareID ()
 Support for a custom PID/VID.
 
bool internals::hid::isConnected ()
 Tell if there is a host connection.
 
void internals::hid::reportChangeInConfig ()
 Report a change in user settings (clutch function, etc.)
 
void internals::hid::reportBatteryLevel (const BatteryStatus &status)
 Report current battery level and status to the host computer.
 
void internals::hid::reportInput (uint64_t inputsLow, uint64_t inputsHigh, uint8_t POVstate, uint8_t leftAxis, uint8_t rightAxis, uint8_t clutchAxis)
 Report HID inputs.
 
void internals::hid::reset ()
 Report all inputs as not active.
 
void internals::hid::common::getReady ()
 Prepare to run.
 
uint16_t internals::hid::common::onGetFeature (uint8_t report_id, uint8_t *buffer, uint16_t len)
 Send feature report.
 
void internals::hid::common::onSetFeature (uint8_t report_id, const uint8_t *buffer, uint16_t len)
 Receive a feature report.
 
void internals::hid::common::onOutput (uint8_t report_id, const uint8_t *buffer, uint16_t len)
 Receive an output report.
 
void internals::hid::common::onReset (uint8_t *report)
 Resets data for the input report.
 
void internals::hid::common::onReportInput (uint8_t *report, bool &notifyConfigChanges, uint64_t &inputsLow, uint64_t &inputsHigh, uint8_t &POVstate, uint8_t &leftAxis, uint8_t &rightAxis, uint8_t &clutchAxis)
 Sets data for the input report.
 
BatteryStatusChrData internals::hid::common::toBleBatteryStatus (const BatteryStatus &status)
 Convert a battery status to the data format required by the BAS specification (BLE only)
 

Detailed Description

System functionality not exposed to the end user.

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

Definition in file SimWheelInternals.hpp.

Function Documentation

◆ addFakeInput()

void internals::inputs::addFakeInput ( FakeInput * instance)

Add a fake input instance for testing.

Parameters
instanceFake iput instance

◆ addSample()

void internals::batteryCalibration::addSample ( int reading)

Add an ADC reading to calibration data. The battery should get fully charged before first call.

Parameters
readingAn ADC reading of current battery(+) voltage.

◆ begin()

void internals::hid::begin ( std::string deviceName,
std::string deviceManufacturer,
bool enableAutoPowerOff,
uint16_t VID,
uint16_t PID,
bool usb_enable = true,
bool ble_enable = true,
bool exclusive = false )

Start BLE/Bluetooth HID.

Warning
Setting both usb_enable and ble_enable to false will cause a runtime error
Note
When USB is enabled, VID will be ignored as another USB-IF license would be required. However, Espressif (the license holder) allows to use a custom PID . See https://docs.espressif.com/projects/esp-iot-solution/en/latest/usb/usb_overview/usb_vid_pid.html
Parameters
deviceNameConfigured device name
deviceManufacturerConfigured device manufacturer
enableAutoPowerOffRequest for automatic shutdown (may be ignored)
VIDConfigured custom vendor ID (may be ignored)
PIDConfigured custom product ID
usb_enableif true and available, USB connectivity is enabled
ble_enableif true and available, BLE connectivity is enabled
exclusiveif true, any previous connection is dropped when another comes

◆ configureFakeMonitor()

void internals::batteryMonitor::configureFakeMonitor ( BatteryStatus * fakeStatus)

Configure a fake monitor for testing.

Parameters
fakeStatusPointer to variable holding the fake battery status

◆ getCount()

uint8_t internals::pixels::getCount ( PixelGroup group)

Get the total number of pixels in a group.

Parameters
groupGroup of pixels
Returns
byte Number of pixels in the given group

◆ getHardwareInstance()

void * internals::batteryMonitor::getHardwareInstance ( )

Get the Hardware Instance object.

Note
For testing
Returns
void* Untyped hardware instance (must be type-casted)

◆ isConnected()

bool internals::hid::isConnected ( )

Tell if there is a host connection.

Returns
true when connected to a computer
false when not connected

◆ map()

void internals::inputMap::map ( bool isAltModeEngaged,
uint64_t firmware_bitmap,
uint64_t & low,
uint64_t & high )

Map a firmware-defined input bitmap.

Parameters
isAltModeEngagedTrue if ALT mode is engaged, false otherwise.
firmware_bitmapFirmware-defined input bitmap
lowLeast significant 64-bits of the user-defined map
highMost significant 64-bits of the user-defined map

◆ notifyInputEvent()

void internals::inputs::notifyInputEvent ( const DecouplingEvent & input)
inline

Push an input event into the decoupling queue (for testing)

Parameters
inputEvent to push

◆ onRawInput()

void internals::inputHub::onRawInput ( DecouplingEvent & input)

Process a single input event.

Parameters
inputEvent to process

◆ reportBatteryLevel()

void internals::hid::reportBatteryLevel ( const BatteryStatus & status)

Report current battery level and status to the host computer.

Warning
May be called before internals::hid::begin()
Parameters
statusBattery status

◆ reportInput()

void internals::hid::reportInput ( uint64_t inputsLow,
uint64_t inputsHigh,
uint8_t POVstate,
uint8_t leftAxis,
uint8_t rightAxis,
uint8_t clutchAxis )

Report HID inputs.

Parameters
[in]inputsLowState of input numbers 0 to 63
[in]inputsHighState of input numbers 64 to 127
[in]POVstateState of the hat switch (POV or DPAD), this is, a button number in the range 0 (no input) to 8 (up-left).
[in]leftAxisPosition of the left clutch, in the range 0-254.
[in]rightAxisPosition of the right clutch, in the range 0-254.
[in]clutchAxisPosition of the combined clutch, in the range 0-254.

◆ set()

void internals::pixels::set ( PixelGroup group,
uint8_t pixelIndex,
uint8_t red,
uint8_t green,
uint8_t blue )

Set the color of a single pixel.

Note
Not displayed immediately
Non-existing pixels will be ignored
Parameters
groupThe group to which the pixel is a member
pixelIndexIndex of the pixel in the LED strip (zero-based)
redRed component of the pixel color
greenGreen component of the pixel color
blueBlue component of the pixel color

◆ setAll()

void internals::pixels::setAll ( PixelGroup group,
uint8_t red,
uint8_t green,
uint8_t blue )

Set the color of all pixels in a group.

Parameters
groupA group of pixels
redRed component of the pixel color
greenGreen component of the pixel color
blueBlue component of the pixel color

◆ shiftToNext()

void internals::pixels::shiftToNext ( PixelGroup group)

Shift all pixel colors to the next pixel index.

Parameters
groupA group of pixels

◆ shiftToPrevious()

void internals::pixels::shiftToPrevious ( PixelGroup group)

Shift all pixel colors to the previous pixel index.

Parameters
groupA group of pixels

◆ supportsCustomHardwareID()

bool internals::hid::supportsCustomHardwareID ( )

Support for a custom PID/VID.

Returns
true If VID and PID can be provided externally via begin()
false If the externally provided VID/PID are ignored