OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
Loading...
Searching...
No Matches
SimWheel.hpp
Go to the documentation of this file.
1
12#pragma once
13
14//-------------------------------------------------------------------
15// Imports
16//-------------------------------------------------------------------
17
19
20#include <type_traits>
21
22//-------------------------------------------------------------------
23// Inputs
24//-------------------------------------------------------------------
25
30namespace inputs
31{
40 void addButton(InputGPIO pin, InputNumber inputNumber);
41
56 InputGPIO clkPin,
57 InputGPIO dtPin,
58 InputNumber cwInputNumber,
59 InputNumber ccwInputNumber,
60 bool useAlternateEncoding = false);
61
70 const ButtonMatrix &matrix,
71 bool negativeLogic = false);
72
84 OutputGPIO selectorPin1,
85 OutputGPIO selectorPin2,
86 OutputGPIO selectorPin3,
88
101 OutputGPIO selectorPin1,
102 OutputGPIO selectorPin2,
103 OutputGPIO selectorPin3,
104 OutputGPIO selectorPin4,
106
120 OutputGPIO selectorPin1,
121 OutputGPIO selectorPin2,
122 OutputGPIO selectorPin3,
123 OutputGPIO selectorPin4,
124 OutputGPIO selectorPin5,
126
141 const MCP23017Expander &chip,
142 uint8_t address,
143 bool isFullAddress = false,
144 I2CBus bus = I2CBus::PRIMARY);
145
160 const PCF8574Expander &chip,
161 uint8_t address,
162 bool isFullAddress = false,
163 I2CBus bus = I2CBus::PRIMARY);
164
179 OutputGPIO loadPin,
180 OutputGPIO nextPin,
181 InputGPIO inputPin,
182 const ShiftRegisterChain &chain,
183 InputNumber SER_inputNumber = UNSPECIFIED::VALUE,
184 const bool negativeLogic = true);
185
198 const RotaryCodedSwitch &spec,
199 InputGPIO pin0,
200 InputGPIO pin1,
201 InputGPIO pin2,
202 bool complementaryCode = true);
203
217 const RotaryCodedSwitch &spec,
218 InputGPIO pin0,
219 InputGPIO pin1,
220 InputGPIO pin2,
221 InputGPIO pin3,
222 bool complementaryCode = true);
223
238 const RotaryCodedSwitch &spec,
239 InputGPIO pin0,
240 InputGPIO pin1,
241 InputGPIO pin2,
242 InputGPIO pin3,
243 InputGPIO pin4,
244 bool complementaryCode = true);
245
261 GPIO sclPin,
262 GPIO sdaPin,
263 I2CBus bus = I2CBus::PRIMARY,
264 bool enableInternalPullup = true);
265
275 ADC_GPIO leftClutchPin,
276 ADC_GPIO rightClutchPin);
277
278} // namespace inputs
279
280//-------------------------------------------------------------------
281// Input Hub
282//-------------------------------------------------------------------
283
288namespace inputHub
289{
294 namespace clutch
295 {
302 void inputs(
303 InputNumber leftInputNumber,
304 InputNumber rightInputNumber);
305
314 InputNumber increase,
315 InputNumber decrease);
316
327
337
338 } // namespace Clutch
339
344 namespace dpad
345 {
359 void inputs(
360 InputNumber padUpNumber,
361 InputNumber padDownNumber,
362 InputNumber padLeftNumber,
363 InputNumber padRightNumber);
364
375 } // namespace DPAD
376
381 namespace altButtons
382 {
389 void inputs(InputNumberCombination inputNumbers);
390
400 } // namespace ALTButtons
401
406 namespace securityLock
407 {
418 } // namespace SecurityLock
419
424 namespace neutralGear
425 {
437 void set(
438 InputNumber neutral,
439 InputNumberCombination combination =
441 } // namespace neutral
442
447 namespace codedSwitch
448 {
457 void add(
458 InputNumber bit1,
459 InputNumber bit2,
460 InputNumber bit4,
461 CodedSwitch8 spec);
462
472 void add(
473 InputNumber bit1,
474 InputNumber bit2,
475 InputNumber bit4,
476 InputNumber bit8,
477 CodedSwitch16 spec);
478
489 void add(
490 InputNumber bit1,
491 InputNumber bit2,
492 InputNumber bit4,
493 InputNumber bit8,
494 InputNumber bit16,
495 CodedSwitch32 spec);
496 } // namespace codedSwitch
497
498} // namespace inputHub
499
500//-------------------------------------------------------------------
501// Input map
502//-------------------------------------------------------------------
503
508namespace inputMap
509{
520 void set(
521 InputNumber firmware_defined,
522 UserInputNumber user_defined,
523 UserInputNumber user_defined_alt_engaged);
524
534 inline void set(
535 InputNumber firmware_defined,
536 UserInputNumber user_defined_alt_engaged)
537 {
539 firmware_defined,
540 static_cast<UserInputNumber>(firmware_defined),
541 user_defined_alt_engaged);
542 }
543
554
555} // namespace inputMap
556
561namespace hid
562{
577 std::string deviceName,
578 std::string deviceManufacturer,
579 bool enableAutoPowerOff = true,
580 uint16_t vendorID = 0,
581 uint16_t productID = 0);
582
594} // namespace hid
595
596//-------------------------------------------------------------------
597// Power management
598//-------------------------------------------------------------------
599
604namespace power
605{
612 void configureWakeUp(RTC_GPIO wakeUpPin);
613
622 OutputGPIO latchPin,
624 uint32_t waitMs = 5000);
625}
626
627//-------------------------------------------------------------------
628// Battery
629//-------------------------------------------------------------------
630
636{
647 void configure(ADC_GPIO battREADPin, OutputGPIO battENPin = UNSPECIFIED::VALUE);
648
660 void configure(I2CBus bus = I2CBus::PRIMARY, uint8_t i2c_address = 0xFF);
661
668 void setPeriod(uint32_t seconds);
669
678 void setWarningSoC(uint8_t percentage);
679
686 void setPowerOffSoC(uint8_t percentage);
687
696
710 InputGPIO sensePin,
711 bool negativeLogic = true,
712 bool enableInternalPullResistor = true);
713} // namespace batteryMonitor
714
715//-------------------------------------------------------------------
716// Pixel control
717//-------------------------------------------------------------------
718
723namespace pixels
724{
744 PixelGroup group,
745 OutputGPIO dataPin,
746 uint8_t pixelCount,
747 bool useLevelShift,
749 PixelFormat pixelFormat = PixelFormat::AUTO,
750 uint8_t globalBrightness = 0xFF);
751} // namespace pixels
752
753//-------------------------------------------------------------------
754// Telemetry
755//-------------------------------------------------------------------
756
761namespace telemetry
762{
764 extern TelemetryData data;
765}
766
767//-------------------------------------------------------------------
768// User interface
769//-------------------------------------------------------------------
770
775namespace ui
776{
785 void add(AbstractUserInterface *instance);
786
794 template <typename UIClass, typename... _Args>
795 inline void add(_Args... __args)
796 {
797 static_assert(
798 std::is_base_of<AbstractUserInterface, UIClass>::value,
799 "Given user interface class is not derived from AbstractUserInterface");
800 ui::add(new UIClass(std::forward<_Args>(__args)...));
801 }
802
812}
813
814//-------------------------------------------------------------------
815// Firmware
816//-------------------------------------------------------------------
817
822namespace firmware
823{
825 void run();
828 void run(void (*func)());
829}
Configure input hardware and specify input numbers.
std::array< InputNumber, 32 > CodedSwitch32
Rotary coded switch up to 32 positions.
GPIOExpanderChip< PCF8574Pin > PCF8574Expander
PCF8574 GPIO Expander for switches.
std::array< InputNumber, 8 > CodedSwitch8
Rotary coded switch up to 8 positions.
std::vector< AnalogMultiplexerChip< PinTags > > AnalogMultiplexerGroup
Group of analog multiplexer chips sharing the same selector pins.
std::vector< ShiftRegisterChip > ShiftRegisterChain
Chain of PISO shift registers for switches.
std::map< uint8_t, InputNumber > RotaryCodedSwitch
Rotary coded switch.
std::array< InputNumber, 16 > CodedSwitch16
Rotary coded switch up to 16 positions.
std::map< OutputGPIO, std::map< InputGPIO, InputNumber > > ButtonMatrix
Button matrix specification.
GPIOExpanderChip< MCP23017Pin > MCP23017Expander
MCP23017 GPIO Expander for switches.
PixelGroup
Available RGB LED groups for pixel control.
Connectivity
Connectivity choice.
@ VALUE
Unspecified value.
I2CBus
I2C bus controller.
PixelFormat
Byte order of pixel data.
@ AUTO
Auto-detect based on pixel driver.
#define JOY_RSHIFT_PADDLE
Right shift paddle.
#define JOY_LSHIFT_PADDLE
Left shift paddle.
PowerLatchMode
Supported power latch modes.
@ POWER_OPEN_DRAIN
Power on when low voltage, power off when open drain.
PixelDriver
Pixel driver.
@ WS2812
WS2812 family.
Abstract interface for notifications and telemetry display.
Combination of input numbers.
static PixelControlNotification * getInstance()
Get the singleton instance.
Everything related to the measurement of available battery charge.
Definition SimWheel.hpp:636
void setPowerOffSoC(uint8_t percentage)
Set a battery level to shutdown the system.
void configure(ADC_GPIO battREADPin, OutputGPIO battENPin=UNSPECIFIED::VALUE)
Monitor battery charge using a battery monitor circuit or a voltage divider.
void setExternalPowerWitness(InputGPIO sensePin)
Set a GPIO pin to sense the power wire.
void setPeriod(uint32_t seconds)
Set time interval between measurements.
void setWarningSoC(uint8_t percentage)
Set a battery level to warn to the user.
void setChargingWitness(InputGPIO sensePin, bool negativeLogic=true, bool enableInternalPullResistor=true)
Set a GPIO pin to sense if the battery is being charged.
Firmware operation.
Definition SimWheel.hpp:823
void run()
Run the custom firmware (non blocking)
Everything related to the HID protocol.
Definition SimWheel.hpp:562
void connectivity(Connectivity option)
Choose a connectivity option.
void configure(std::string deviceName, std::string deviceManufacturer, bool enableAutoPowerOff=true, uint16_t vendorID=0, uint16_t productID=0)
Initialize Bluetooth/USB device.
void cycleWorkingModeInputs(InputNumberCombination inputNumbers)
Set a combination of inputs to cycle the working mode of ALT buttons. All inputs must be activated at...
void cycleWorkingModeInputs(InputNumberCombination inputNumbers)
Set a combination of inputs to cycle the working mode of clutch paddles. All inputs must be activated...
void bitePointInputs(InputNumber increase, InputNumber decrease)
Set inputs for clutch calibration while one and only one clutch paddle is pressed.
void cmdRecalibrateAxisInputs(InputNumberCombination inputNumbers)
Set a combination of inputs to command a recalibration of the analog clutch paddles.
void add(InputNumber bit1, InputNumber bit2, InputNumber bit4, CodedSwitch8 spec)
Add a binary-coded switch up to 8 positions.
void cycleWorkingModeInputs(InputNumberCombination inputNumbers)
Set a combination of inputs to cycle the working mode of the DPAD. All inputs must be activated at th...
void set(InputNumber neutral, InputNumberCombination combination={JOY_LSHIFT_PADDLE, JOY_RSHIFT_PADDLE})
Set a "virtual" button for the neutral gear.
void cycleWorkingModeInputs(InputNumberCombination inputNumbers)
Set a combination of inputs to cycle the working mode of the security lock. All inputs must be activa...
Everything related to the combined state of all inputs and their treatment.
Definition SimWheel.hpp:289
Translates firmware-defined input numbers to user-defined input numbers.
Definition SimWheel.hpp:509
void setOptimal()
Set an "optimal" default input map.
void set(InputNumber firmware_defined, UserInputNumber user_defined, UserInputNumber user_defined_alt_engaged)
Set a default mapping for an input number.
Everything related to hardware inputs and their events.
Definition SimWheel.hpp:31
void setAnalogClutchPaddles(ADC_GPIO leftClutchPin, ADC_GPIO rightClutchPin)
Set two potentiometers as clutch paddles. Each one will work as an analog axis.
void addRotaryEncoder(InputGPIO clkPin, InputGPIO dtPin, InputNumber cwInputNumber, InputNumber ccwInputNumber, bool useAlternateEncoding=false)
Add incremental rotary encoder inputs bound to specific input numbers.
void add74HC165NChain(OutputGPIO loadPin, OutputGPIO nextPin, InputGPIO inputPin, const ShiftRegisterChain &chain, InputNumber SER_inputNumber=UNSPECIFIED::VALUE, const bool negativeLogic=true)
Add a chain of 74HC165N PISO shift registers to the hardware inputs.
void addAnalogMultiplexerGroup(OutputGPIO selectorPin1, OutputGPIO selectorPin2, OutputGPIO selectorPin3, const AnalogMultiplexerGroup< Mux8Pin > &chips)
Add a group of 8-channel multiplexers to the hardware inputs.
void addPCF8574Expander(const PCF8574Expander &chip, uint8_t address, bool isFullAddress=false, I2CBus bus=I2CBus::PRIMARY)
Add a PCF8574 GPIO expander to the hardware inputs.
void addMCP23017Expander(const MCP23017Expander &chip, uint8_t address, bool isFullAddress=false, I2CBus bus=I2CBus::PRIMARY)
Add a MCP23017 GPIO expander to the hardware inputs.
void addButtonMatrix(const ButtonMatrix &matrix, bool negativeLogic=false)
Add a button matrix to the hardware inputs.
void addRotaryCodedSwitch(const RotaryCodedSwitch &spec, InputGPIO pin0, InputGPIO pin1, InputGPIO pin2, bool complementaryCode=true)
Add a binary coded rotary switch up to 8 positions.
void initializeI2C(GPIO sclPin, GPIO sdaPin, I2CBus bus=I2CBus::PRIMARY, bool enableInternalPullup=true)
Initialize an I2C bus to certain pins.
void addButton(InputGPIO pin, InputNumber inputNumber)
Add a button attached to a single pin to the hardware inputs.
Everything related to pixel control.
Definition SimWheel.hpp:724
void configure(PixelGroup group, OutputGPIO dataPin, uint8_t pixelCount, bool useLevelShift, PixelDriver pixelType=PixelDriver::WS2812, PixelFormat pixelFormat=PixelFormat::AUTO, uint8_t globalBrightness=0xFF)
Configure an LED strip for pixel control.
Everything related to power management.
Definition SimWheel.hpp:605
void configureWakeUp(RTC_GPIO wakeUpPin)
Initialize power management.
void configurePowerLatch(OutputGPIO latchPin, PowerLatchMode mode=PowerLatchMode::POWER_OPEN_DRAIN, uint32_t waitMs=5000)
Configure an external latch circuit for power on and off.
Holds received telemetry data.
Definition SimWheel.hpp:762
TelemetryData data
Received telemetry data.
Everything related to the user interface, if available.
Definition SimWheel.hpp:776
void addPixelControlNotifications()
Add UI notifications using pixel control.
Definition SimWheel.hpp:808
void add(AbstractUserInterface *instance)
Add a user interface instance.
ADC-capable GPIO pin number.
GPIO pin number.
Input-capable GPIO pin number.
Firmware-defined input numbers in the range [0,63] or unspecified.
Output-capable GPIO pin number.
RTC-capable GPIO pin number.
Telemetry data.
User-defined input numbers in the range [0,127].