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

Internal service interfaces for dependency injection. More...

#include "InternalTypes.hpp"
#include <cstdint>
#include <type_traits>
#include <cassert>
#include <typeinfo>
#include <vector>

Go to the source code of this file.

Classes

struct  DependencyManager< Service >
 Dependency Manager. More...
 

Macros

#define MOCK
 Macro to mark a mock implementation for void methods.
 
#define MOCK_R(value)
 Macro to mark a mock implementation for non-void methods.
 
#define SERVICE(ClassName)
 Macro to declare an internal service class.
 
#define VOID_SINGLETON_INVOKER(Decl, Call)
 Macro to declare a void static method in a service class.
 
#define SINGLETON_INVOKER(ReturnType, Decl, Call)
 Macro to declare a non-void static method in a service class.
 
#define ALL_INVOKER(Decl, Call)
 Reserved for future use.
 
#define BOTH_INVOKER(Decl, Call)
 Reserved for future use.
 

Functions

class SERVICE (InputService)
 Input hardware services.
 
class SERVICE (InputHubService)
 Input Hub service.
 
class SERVICE (InputMapService)
 Input map service.
 
class SERVICE (PowerService)
 Power service.
 
class SERVICE (BatteryService)
 Battery service.
 
class SERVICE (BatteryCalibrationService)
 Battery calibration service.
 
class SERVICE (HidService)
 HID service.
 
class SERVICE (UIService)
 User interface service.
 
class SERVICE (FirmwareService)
 Global firmware service.
 

Detailed Description

Internal service interfaces for dependency injection.

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

Definition in file InternalServices.hpp.

Macro Definition Documentation

◆ ALL_INVOKER

#define ALL_INVOKER ( Decl,
Call )
Value:
static void Decl \
{ \
auto instances = getAllInstances(); \
for (auto instance : instances) \
instance->Call; \
}

Reserved for future use.

Definition at line 61 of file InternalServices.hpp.

◆ BOTH_INVOKER

#define BOTH_INVOKER ( Decl,
Call )
Value:
static void Decl \
{ \
getInstance()->Call; \
auto instances = getAllInstances(); \
for (auto instance : instances) \
instance->Call; \
}

Reserved for future use.

Definition at line 70 of file InternalServices.hpp.

◆ MOCK

#define MOCK
Value:
{ \
}

Macro to mark a mock implementation for void methods.

Definition at line 30 of file InternalServices.hpp.

◆ MOCK_R

#define MOCK_R ( value)
Value:
{ \
return value; \
}

Macro to mark a mock implementation for non-void methods.

Definition at line 35 of file InternalServices.hpp.

◆ SERVICE

#define SERVICE ( ClassName)
Value:
ClassName: \
public \
DependencyManager<ClassName>

Macro to declare an internal service class.

Definition at line 41 of file InternalServices.hpp.

◆ SINGLETON_INVOKER

#define SINGLETON_INVOKER ( ReturnType,
Decl,
Call )
Value:
static ReturnType Decl \
{ \
return getInstance()->Call; \
}

Macro to declare a non-void static method in a service class.

Definition at line 54 of file InternalServices.hpp.

◆ VOID_SINGLETON_INVOKER

#define VOID_SINGLETON_INVOKER ( Decl,
Call )
Value:
static void Decl \
{ \
getInstance()->Call; \
}

Macro to declare a void static method in a service class.

Definition at line 47 of file InternalServices.hpp.

Function Documentation

◆ SERVICE() [1/9]

class SERVICE ( BatteryCalibrationService )

Battery calibration service.

Restart autocalibration algorithm.

Get a percentage of battery charge based on calibration data.

Parameters
readingAn ADC reading of current battery(+) voltage.
Returns
int -1 if the battery has not been calibrated. Otherwise, a percentage in the range 0%-100%.

Get a percentage of battery charge using auto-calibration. Will provide incorrect battery levels (higher) until the battery is fully charged. Anyway, this algorithm is not accurate.

Parameters
readingAn ADC reading of current battery(+) voltage
Returns
If auto-calibration is available, a percentage in the range 0%-100%. Otherwise, zero.
Note
Based on https://blog.ampow.com/lipo-voltage-chart/

Get the count of calibration data items

Get calibration data

Parameters
indexIndex of the required datum
Returns
uint16_t Required datum

Set calibration data

Parameters
indexIndex of this calibration data
dataData to set
saveTrue to save to persistent storage.

Get the auto-calibration parameter

Returns
int Auto-calibration parameter

Set the auto-calibration parameter

Parameters
valueValue of the auto-calibration parameter
saveTrue to save to persistent storage.

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [2/9]

class SERVICE ( BatteryService )

Battery service.

Get the last known battery level (SoC)

Check if the device can be powered by a battery

Note
This method should always return the same value on each call
Returns
true if this device can be powered by a battery
false if this device is always powered by a external power supply

Check if the battery is detected

Note
If this method returns false, the battery level is unknown
Returns
true if this device has a battery and was detected
false if this device has no battery or the battery is not detected (and the device is powered by a external power supply right now)

Get the full battery status

Parameters
statusCurrent battery status

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [3/9]

class SERVICE ( FirmwareService )

Global firmware service.

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [4/9]

class SERVICE ( HidService )

HID service.

Get the user-defined custom hardware ID

Parameters
[out]customVIDCustom VID or zero if not configured
[out]customPIDCustom PID or zero if not configured

Set the user-defiend custom hardware ID

Note
if both customVID and customPID are set to zero, the factory defaults will be used instead.
Parameters
customVIDCustom VID
customPIDCustom PID
saveTrue to save to persistent storage

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [5/9]

class SERVICE ( InputHubService )

Input Hub service.

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [6/9]

class SERVICE ( InputMapService )

Input map service.

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [7/9]

class SERVICE ( InputService )

Input hardware services.

Force auto-calibration of all axes (analog clutch paddles)

Change polarity of left axis (if any)

Note
Saved to flash memory without delay

Change polarity of right axis (if any)

Note
Saved to flash memory without delay

Multiply the pulse width of rotary encoders

Note
Valid values are saved to flash memory without delay.
Parameters
multiplierA pulse width multiplier greater than zero. Valid values are between 1 and 6. Invalid values are ignored.

Get the current pulse width multiplier for rotary encoders

Returns
PulseWidthMultiplier A pulse width multiplier greater than zero.

Get current axis calibration data

Note
To be called from the storage namespace
Parameters
[out]minLeftminimum ADC reading for the left clutch
[out]maxLeftmaximum ADC reading for the left clutch
[out]minRightminimum ADC reading for the right clutch
[out]maxRightmaximum ADC reading for the right clutch
Returns
true if there are analog clutch paddles
true if there are no analog clutch paddles, so the output parameters were not set.

Set the Axis calibration data

Note
To be called from the storage namespace
Parameters
[in]minLeftminimum ADC reading for the left clutch
[in]maxLeftmaximum ADC reading for the left clutch
[in]minRightminimum ADC reading for the right clutch
[in]maxRightmaximum ADC reading for the right clutch
[in]saveIf true, save to persistent storage

Get axes polarity

Parameters
[out]leftAxisReversedTrue if the left axis is reversed
[out]rightAxisReversedTrue if the right axis is reversed

Set axes polarity

Parameters
leftAxisReversedTrue if the left axis is reversed
rightAxisReversedTrue if the right axis is reversed
saveIf true, save to persistent storage

Repeat last input event

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [8/9]

class SERVICE ( PowerService )

Power service.

Definition at line 1 of file InternalServices.hpp.

◆ SERVICE() [9/9]

class SERVICE ( UIService )

User interface service.

Definition at line 1 of file InternalServices.hpp.