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
201 GPIO sclPin,
202 GPIO sdaPin,
203 I2CBus bus = I2CBus::PRIMARY,
204 bool enableInternalPullup = true);
205
215 ADC_GPIO leftClutchPin,
216 ADC_GPIO rightClutchPin);
217
251 ADC_GPIO xAxisPin,
252 ADC_GPIO yAxisPin,
253 InputNumber up,
254 InputNumber down,
255 InputNumber left,
256 InputNumber right,
257 uint8_t xCenter = 127,
258 uint8_t yCenter = 127,
259 uint8_t xDeadZone = 63,
260 uint8_t yDeadZone = 63,
261 bool xAxisReverse = false,
262 bool yAxisReverse = false);
263
264} // namespace inputs
265
266//-------------------------------------------------------------------
267// Input Hub
268//-------------------------------------------------------------------
269
274namespace inputHub
275{
280 namespace clutch
281 {
290 void inputs(
291 InputNumber leftInputNumber,
292 InputNumber rightInputNumber);
293
302 InputNumber increase,
303 InputNumber decrease);
304
316
326 const InputNumberCombination &inputNumbers);
327
328 } // namespace Clutch
329
334 namespace dpad
335 {
349 void inputs(
350 InputNumber padUpNumber,
351 InputNumber padDownNumber,
352 InputNumber padLeftNumber,
353 InputNumber padRightNumber);
354
365 } // namespace DPAD
366
371 namespace altButtons
372 {
379 void inputs(const InputNumberCombination &inputNumbers);
380
390 } // namespace ALTButtons
391
396 namespace securityLock
397 {
408 } // namespace SecurityLock
409
414 namespace neutralGear
415 {
427 void set(
428 InputNumber neutral,
429 const InputNumberCombination &combination =
431 } // namespace neutral
432
437 namespace codedSwitch
438 {
447 void add(
448 InputNumber bit1,
449 InputNumber bit2,
450 InputNumber bit4,
451 const CodedSwitch8 &spec);
452
462 void add(
463 InputNumber bit1,
464 InputNumber bit2,
465 InputNumber bit4,
466 InputNumber bit8,
467 const CodedSwitch16 &spec);
468
479 void add(
480 InputNumber bit1,
481 InputNumber bit2,
482 InputNumber bit4,
483 InputNumber bit8,
484 InputNumber bit16,
485 const CodedSwitch32 &spec);
486 } // namespace codedSwitch
487
493 namespace route_to_ui
494 {
507 void add(InputNumber inputNumber);
508 } // namespace route_to_ui
509} // namespace inputHub
510
511//-------------------------------------------------------------------
512// Input map
513//-------------------------------------------------------------------
514
519namespace inputMap
520{
531 void set(
532 InputNumber firmware_defined,
533 InputNumber user_defined,
534 InputNumber user_defined_alt_engaged);
535
545 inline void set(
546 InputNumber firmware_defined,
547 InputNumber user_defined_alt_engaged)
548 {
550 firmware_defined,
551 static_cast<InputNumber>(firmware_defined),
552 user_defined_alt_engaged);
553 }
554
565
566} // namespace inputMap
567
572namespace hid
573{
588 std::string deviceName,
589 std::string deviceManufacturer,
590 bool enableAutoPowerOff = true,
591 uint16_t vendorID = 0,
592 uint16_t productID = 0);
593
605} // namespace hid
606
607//-------------------------------------------------------------------
608// Power management
609//-------------------------------------------------------------------
610
615namespace power
616{
623 void configureWakeUp(RTC_GPIO wakeUpPin);
624
633 OutputGPIO latchPin,
635 uint32_t waitMs = 5000);
636}
637
638//-------------------------------------------------------------------
639// Battery
640//-------------------------------------------------------------------
641
647{
658 void configure(ADC_GPIO battREADPin, OutputGPIO battENPin = UNSPECIFIED::VALUE);
659
671 void configure(I2CBus bus = I2CBus::PRIMARY, uint8_t i2c_address = 0xFF);
672
679 void setPeriod(uint32_t seconds);
680
689 void setWarningSoC(uint8_t percentage);
690
697 void setPowerOffSoC(uint8_t percentage);
698
707
721 InputGPIO sensePin,
722 bool negativeLogic = true,
723 bool enableInternalPullResistor = true);
724} // namespace batteryMonitor
725
726//-------------------------------------------------------------------
727// Pixel control
728//-------------------------------------------------------------------
729
734namespace pixels
735{
755 PixelGroup group,
756 OutputGPIO dataPin,
757 uint8_t pixelCount,
758 bool useLevelShift,
760 uint8_t globalBrightness = 0xFF,
761 bool reverse = false);
762} // namespace pixels
763
764//-------------------------------------------------------------------
765// Telemetry
766//-------------------------------------------------------------------
767
772namespace telemetry
773{
775 extern TelemetryData data;
776}
777
778//-------------------------------------------------------------------
779// User interface
780//-------------------------------------------------------------------
781
786namespace ui
787{
796 void add(AbstractUserInterface *instance);
797
805 template <typename UIClass, typename... _Args>
806 inline void add(_Args... __args)
807 {
808 static_assert(
809 std::is_base_of<AbstractUserInterface, UIClass>::value,
810 "Given user interface class is not derived from AbstractUserInterface");
811 ui::add(new UIClass(std::forward<_Args>(__args)...));
812 }
813
823}
824
825//-------------------------------------------------------------------
826// Firmware
827//-------------------------------------------------------------------
828
833namespace firmware
834{
836 void run();
839 void run(void (*func)());
840}
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::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.
#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.
static PixelControlNotification * getInstance()
Get the singleton instance.
Everything related to the measurement of available battery charge.
Definition SimWheel.hpp:647
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:834
void run()
Run the custom firmware (non blocking)
Everything related to the HID protocol.
Definition SimWheel.hpp:573
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(const InputNumberCombination &inputNumbers)
Set a combination of inputs to cycle the working mode of ALT buttons. All inputs must be activated at...
void bitePointInputs(InputNumber increase, InputNumber decrease)
Set inputs for clutch calibration while one and only one clutch paddle is pressed.
void cmdRecalibrateAxisInputs(const InputNumberCombination &inputNumbers)
Set a combination of inputs to command a recalibration of the analog clutch paddles.
void cycleWorkingModeInputs(const InputNumberCombination &inputNumbers)
Set a combination of inputs to cycle the working mode of clutch paddles. All inputs must be activated...
void add(InputNumber bit1, InputNumber bit2, InputNumber bit4, const CodedSwitch8 &spec)
Add a binary-coded switch up to 8 positions.
void cycleWorkingModeInputs(const 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, const InputNumberCombination &combination={JOY_LSHIFT_PADDLE, JOY_RSHIFT_PADDLE})
Set a "virtual" button for the neutral gear.
void add(InputNumber inputNumber)
Declare inputs that will be routed to the UI frameservers.
void cycleWorkingModeInputs(const 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:275
Translates firmware-defined input numbers to user-defined input numbers.
Definition SimWheel.hpp:520
void set(InputNumber firmware_defined, InputNumber user_defined, InputNumber user_defined_alt_engaged)
Set a default mapping for an input number.
void setOptimal()
Set an "optimal" default input map.
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 addJoystick(ADC_GPIO xAxisPin, ADC_GPIO yAxisPin, InputNumber up, InputNumber down, InputNumber left, InputNumber right, uint8_t xCenter=127, uint8_t yCenter=127, uint8_t xDeadZone=63, uint8_t yDeadZone=63, bool xAxisReverse=false, bool yAxisReverse=false)
Add an analog joystick as an 8-way input device.
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 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:735
void configure(PixelGroup group, OutputGPIO dataPin, uint8_t pixelCount, bool useLevelShift, PixelDriver driver=PixelDriver::WS2812, uint8_t globalBrightness=0xFF, bool reverse=false)
Configure an LED strip for pixel control.
Everything related to power management.
Definition SimWheel.hpp:616
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:773
TelemetryData data
Received telemetry data.
Everything related to the user interface, if available.
Definition SimWheel.hpp:787
void addPixelControlNotifications()
Add UI notifications using pixel control.
Definition SimWheel.hpp:819
void add(AbstractUserInterface *instance)
Add a user interface instance.
ADC-capable GPIO pin number.
GPIO pin number.
Input-capable GPIO pin number.
Combination of input numbers.
Firmware-defined input numbers in the range [0,127] or unspecified.
Output-capable GPIO pin number.
RTC-capable GPIO pin number.
Telemetry data.