22#define GPIO_IS_VALID_GPIO(pin) (pin < 100)
23#define TEST_NO_OUTPUT_GPIO 80
24#define GPIO_IS_VALID_OUTPUT_GPIO(pin) (pin < TEST_NO_OUTPUT_GPIO)
25#define TEST_RTC_GPIO1 40
26#define TEST_RTC_GPIO2 49
27#define GPIO_IS_VALID_RTC_GPIO(pin) ((pin >= TEST_RTC_GPIO1) && (pin <= TEST_RTC_GPIO2))
28#define TEST_RESERVED_GPIO 50
35#define GPIO_IS_VALID_RTC_GPIO(pin) rtc_gpio_is_valid_gpio(static_cast<gpio_num_t>(pin))
47#include <initializer_list>
52#include "driver/rtc_io.h"
53#include "hal/gpio_types.h"
54#include "driver/gpio.h"
55#include "esp32-hal-psram.h"
78 std::to_string(value) +
79 " is out of range [0,63]") {}
87 "Trying to use an unspecified input number.") {}
107 : std::runtime_error(
108 "Invalid GPIO number " +
109 std::to_string(value) +
127 : std::runtime_error(
128 "No input numbers were given to: " + hardware) {}
148 : std::runtime_error(
149 "There is an input number not assigned to a hardware input. Usage: " +
169 : std::runtime_error(
170 "The user-defined input number " +
171 std::to_string(value) +
172 " is out of range [0,127]") {}
179 : std::runtime_error(
180 "Trying to use an unspecified input number.") {}
201 for (
size_t i = 0; i < vector.size(); i++)
202 if (vector.at(i) == item)
204 vector.push_back(item);
218inline int map_value(
int x,
int in_min,
int in_max,
int out_min,
int out_max)
220 const int run = in_max - in_min;
223 const int rise = out_max - out_min;
224 const int delta = x - in_min;
225 return (delta * rise) / run + out_min;
289 _value = number._value;
297 explicit operator uint64_t()
const
300 return (1ULL << _value);
310 operator uint8_t()
const
313 throw std::bad_cast();
340 inline bool operator<(
const InputNumber value)
const {
return (_value < value._value); }
344 _value = other._value;
365 _registered |= (1ULL << _value);
375 _registered &= ~(1ULL << _value);
384 _registered = ~(0ULL);
396 return _registered & (uint64_t)inputNumber;
409 if (inputNumber < 64)
410 return _registered & (1ULL << inputNumber);
420 static uint64_t
booked() {
return _registered; }
423 static void clearBook()
431 inline static uint64_t _registered = 0ULL;
446 operator std::vector<uint8_t>()
448 std::vector<uint8_t> result = {};
454 result.push_back((uint8_t)inputNumber);
467 for (
auto item = items.begin(); item != items.end(); ++item)
481 explicit operator uint64_t()
483 uint64_t bitmap = 0ULL;
484 for (
size_t i = 0; i < this->size(); i++)
485 bitmap = bitmap | (uint64_t)this->at(i);
497#define JOY_LSHIFT_PADDLE 4
498#define JOY_RSHIFT_PADDLE 5
501#define JOY_LTHUMBSTICK_CLICK 8
502#define JOY_RTHUMBSTICK_CLICK 9
540 _value = number._value;
551 return (1ULL << _value);
566 return (1ULL << _value);
574 operator uint8_t()
const
577 throw std::bad_cast();
584 inline bool operator==(
const UserInputNumber value)
const {
return (_value == value._value); }
585 inline bool operator!=(
const UserInputNumber value)
const {
return (_value != value._value); }
586 inline bool operator<(
const UserInputNumber value)
const {
return (_value < value._value); }
623 if (!GPIO_IS_VALID_GPIO(pin))
625 bool reserved =
false;
626#if defined(CONFIG_IDF_TARGET_ESP32)
627 reserved = (pin >= GPIO_NUM_6) && (pin <= GPIO_NUM_11);
628 reserved = reserved ||
629 ((pin >= GPIO_NUM_16) && (pin <= GPIO_NUM_17) && psramFound());
632#elif defined(CONFIG_IDF_TARGET_ESP32S2)
635#elif defined(CONFIG_IDF_TARGET_ESP32S3)
636 reserved = ((pin >= GPIO_NUM_26) && (pin <= GPIO_NUM_32));
637 reserved = reserved ||
638 ((pin >= GPIO_NUM_35) && (pin <= GPIO_NUM_37) && psramFound());
641#elif defined(CONFIG_IDF_TARGET_ESP32C3)
642 reserved = (pin >= GPIO_NUM_11) && (pin <= GPIO_NUM_17);
646 reserved = (pin == TEST_RESERVED_GPIO);
649 throw gpio_error(pin,
"Reserved for SPI FLASH, PSRAM or otherwise NOT USABLE");
671 operator int()
const {
return _pin; }
702 inline bool operator<(
const GPIO value)
const {
return (
_pin < value.
_pin); }
728 reservedPins.begin(),
745 static void clearReservations()
747 reservedPins.clear();
752 inline static std::vector<int> reservedPins = {};
773 if ((pin >= 0) && !GPIO_IS_VALID_OUTPUT_GPIO(pin))
864#if CONFIG_IDF_TARGET_ESP32C3
1002 uint8_t rpmPercent = 0;
1004 uint8_t shiftLight1 = 0;
1006 uint8_t shiftLight2 = 0;
1008 bool revLimiter =
false;
1010 bool engineStarted =
false;
1021 bool absEngaged =
false;
1023 bool tcEngaged =
false;
1025 bool drsEngaged =
false;
1027 bool pitLimiter =
false;
1029 bool lowFuelAlert =
false;
1031 uint8_t absLevel = 0;
1033 uint8_t tcLevel = 0;
1037 uint8_t brakeBias = 0;
1045 bool blackFlag =
false;
1046 bool blueFlag =
false;
1047 bool checkeredFlag =
false;
1048 bool greenFlag =
false;
1049 bool orangeFlag =
false;
1050 bool whiteFlag =
false;
1051 bool yellowFlag =
false;
1053 uint16_t remainingLaps = 0;
1055 uint16_t remainingMinutes = 0;
1064 uint8_t relativeTurboPressure = 0;
1066 float absoluteTurboPressure = 0.0;
1068 uint16_t waterTemperature = 0;
1070 float oilPressure = 0.0;
1072 uint16_t oilTemperature = 0;
1074 uint8_t relativeRemainingFuel = 0;
1076 uint16_t absoluteRemainingFuel = 0;
1104 uint32_t &timerVariable,
1105 uint32_t elapsedTimeMs,
1106 uint32_t timeLimitMs)
1108 timerVariable += elapsedTimeMs;
1109 uint32_t result = timerVariable / timeLimitMs;
1110 timerVariable %= timeLimitMs;
1250 virtual void onStart()
override;
1251 virtual void onBitePoint(uint8_t bitePoint)
override;
1252 virtual void onConnected()
override;
1253 virtual void onBLEdiscovering()
override;
1254 virtual void onLowBattery()
override;
1255 virtual void onSaveSettings()
override;
1256 virtual void serveSingleFrame(uint32_t elapsedMs)
override {};
1257 virtual uint8_t getMaxFPS()
override {
return 0; }
1258 virtual void shutdown()
override {};
1348 bool colorGradientOrPercentage,
1349 uint32_t barColor = 0x00ACFA70);
bool addIfNotExists(T item, std::vector< T > &vector)
Add an item to a collection without duplicates.
#define GPIO_IS_VALID_RTC_GPIO(pin)
Validation of RTC GPIO pins.
PixelGroup
Available RGB LED groups for pixel control.
@ GRP_INDIVIDUAL
Individual leds group.
@ GRP_BUTTONS
Buttons lighting group.
@ GRP_TELEMETRY
Telemetry leds group.
Connectivity
Connectivity choice.
@ USB_BLE_EXCLUSIVE
Combined USB and BLE connectivity with forced connection drop.
@ USB
USB connectivity only, if available.
@ _DEFAULT
Default connectivity.
@ USB_BLE
Combined USB and BLE connectivity if available.
@ BLE
BLE connectivity only, if available.
@ DUMMY
No connectivity at all (for troubleshooting)
UNSPECIFIED
Unspecified value type.
@ VALUE
Unspecified value.
I2CBus
I2C bus controller.
PixelFormat
Byte order of pixel data.
@ AUTO
Auto-detect based on pixel driver.
int map_value(int x, int in_min, int in_max, int out_min, int out_max)
Equivalent to Arduino's map()
std::vector< InputGPIO > InputGPIOCollection
Collection of input GPIOs.
PowerLatchMode
Supported power latch modes.
@ POWER_OFF_LOW
Power on when high voltage, power off when low voltage.
@ POWER_OFF_HIGH
Power on when low voltage, power off when high voltage.
@ POWER_OPEN_DRAIN
Power on when low voltage, power off when open drain.
std::vector< GPIO > GPIOCollection
Collection of GPIOs.
std::vector< OutputGPIO > OutputGPIOCollection
Collection of output GPIOs.
Abstract interface for notifications and telemetry display.
virtual void shutdown()
Cut power to the UI hardware.
virtual void onStart()
Called just once after initialization.
bool requiresPowertrainTelemetry
Set to true to receive and use powertrain telemetry data.
virtual uint8_t getMaxFPS()
Get the maximum FPS supported by the underlying hardware.
bool requiresECUTelemetry
Set to true to receive and use ECU telemetry data.
virtual void onLowBattery()
Notify low battery.
virtual void onConnected()
Notify device is connected.
virtual void onBLEdiscovering()
Notify device is in discovery mode.
virtual uint16_t getStackSize()
Get the stack size required by this user interface.
virtual void onSaveSettings()
Notify that user settings have been saved to flash memory.
bool requiresRaceControlTelemetry
Set to true to receive and use race control telemetry data.
bool requiresGaugeTelemetry
Set to true to receive and use telemetry data for gauges.
uint32_t frameTimer(uint32_t &timerVariable, uint32_t elapsedTimeMs, uint32_t timeLimitMs)
Simple timer.
virtual void serveSingleFrame(uint32_t elapsedMs)
Draw a single frame.
virtual void onTelemetryData(const TelemetryData *pTelemetryData)
Notify new telemetry data.
virtual void onBitePoint(uint8_t bitePoint)
Notify a change in the current bite point.
Notifications using pixel control.
void shiftToPrevious(PixelGroup group)
Shift all pixel colors to the previous pixel index.
virtual void pixelControl_OnConnected()
Notify device is connected.
virtual bool renderBatteryLevel(PixelGroup group, bool colorGradientOrPercentage, uint32_t barColor=0x00ACFA70)
Macro to render the current battery SoC.
void setAll(PixelGroup group, uint8_t red, uint8_t green, uint8_t blue)
Set the color of all pixels in a group.
virtual void pixelControl_OnBitePoint(uint8_t bitePoint)
Notify a change in current bite point.
static PixelControlNotification * getInstance()
Get the singleton instance.
void shiftToNext(PixelGroup group)
Shift all pixel colors to the next pixel index.
uint8_t getPixelCount(PixelGroup group)
Get the count of pixels in a pixel group.
virtual void pixelControl_OnLowBattery()
Notify low battery.
virtual void pixelControl_OnSaveSettings()
Notify that user settings have been saved to flash memory.
bool notConnectedYet
Flag to indicate host connection.
void set(PixelGroup group, uint8_t pixelIndex, uint8_t red, uint8_t green, uint8_t blue)
Set the color of a single pixel.
virtual void pixelControl_OnBLEdiscovering()
Notify device is in discovery mode.
virtual void pixelControl_OnStart()
Called just once after initialization.
Exception for invalid GPIO pin numbers.
gpio_error(uint8_t value, const std::string &reason)
Construct a new gpio_error exception.
ADC-capable GPIO pin number.
ADC_GPIO(UNSPECIFIED value)
Create a "not connected" ADC GPIO.
ADC_GPIO(int pin)
Create an ADC GPIO connected to a pin number.
ADC_GPIO()
Create a "not connected" ADC GPIO.
bool operator==(const UNSPECIFIED value) const
Check if "not connected".
void reserve() const
Reserve this GPIO for exclusive use.
GPIO(int pin)
Assign a pin number.
GPIO(UNSPECIFIED value)
Assign a "not connected" value.
int _pin
Assigned pin number.
void abortIfUnspecified() const
Throw an exception if unspecified.
void grant() const
Grant this GPIO for non-exclusive use.
GPIO(const GPIO &instance)
Copy another GPIO instance.
bool operator!=(const UNSPECIFIED value) const
Check if a pin number was assigned.
GPIO()
Create a GPIO as "not connected".
Output-capable GPIO pin number.
OutputGPIO()
Create a "not connected" GPIO.
OutputGPIO(int pin)
Create a GPIO.
OutputGPIO(UNSPECIFIED value)
Create a "not connected" GPIO.
RTC-capable GPIO pin number.
RTC_GPIO(int pin)
Create a RTC GPIO connected to a pin number.
uint32_t frameID
Identifies a telemetry frame. For internal use. Do not overwrite.