OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
Loading...
Searching...
No Matches
SimWheelTypes.hpp
Go to the documentation of this file.
1
12#pragma once
13
14//-------------------------------------------------------------------
15// Global macros
16//-------------------------------------------------------------------
17
18#if CD_CI
19
21
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
29
31
32#else
33
35#define GPIO_IS_VALID_RTC_GPIO(pin) rtc_gpio_is_valid_gpio(static_cast<gpio_num_t>(pin))
36
37#endif
38
39//-------------------------------------------------------------------
40// Imports
41//-------------------------------------------------------------------
42
43#include <cstdint>
44#include <string>
45#include <stdexcept>
46#include <vector>
47#include <initializer_list>
48#include <map>
49#include <algorithm>
50
51#if !CD_CI
52#include "driver/rtc_io.h" // For rtc_gpio_is_valid_gpio()
53#include "hal/gpio_types.h" // For gpio_num_t
54#include "driver/gpio.h" // For GPIO_IS_VALID... and others
55#include "esp32-hal-psram.h" // For psramFound()
56#endif
57
58//-------------------------------------------------------------------
59// Exceptions
60//-------------------------------------------------------------------
61
67class invalid_input_number : public std::runtime_error
68{
69public:
75 invalid_input_number(uint8_t value)
76 : std::runtime_error(
77 "The input number " +
78 std::to_string(value) +
79 " is out of range [0,63]") {}
86 : std::runtime_error(
87 "Trying to use an unspecified input number.") {}
88
89 virtual ~invalid_input_number() noexcept {}
90};
91
96class gpio_error : public std::runtime_error
97{
98public:
106 gpio_error(uint8_t value, const std::string &reason)
107 : std::runtime_error(
108 "Invalid GPIO number " +
109 std::to_string(value) +
110 ". Reason: " +
111 reason) {}
112};
113
118class empty_input_number_set : public std::runtime_error
119{
120public:
126 empty_input_number_set(const std::string &hardware)
127 : std::runtime_error(
128 "No input numbers were given to: " + hardware) {}
129
130 virtual ~empty_input_number_set() noexcept {}
131};
132
139class unknown_input_number : public std::runtime_error
140{
141public:
147 unknown_input_number(std::string usage)
148 : std::runtime_error(
149 "There is an input number not assigned to a hardware input. Usage: " +
150 usage) {}
151
152 virtual ~unknown_input_number() noexcept {}
153};
154
160class invalid_user_input_number : public std::runtime_error
161{
162public:
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.") {}
181
182 virtual ~invalid_user_input_number() noexcept {}
183};
184
185//-------------------------------------------------------------------
186// Utility functions
187//-------------------------------------------------------------------
188
198template <typename T>
199bool addIfNotExists(T item, std::vector<T> &vector)
200{
201 for (size_t i = 0; i < vector.size(); i++)
202 if (vector.at(i) == item)
203 return false;
204 vector.push_back(item);
205 return true;
206}
207
218inline int map_value(int x, int in_min, int in_max, int out_min, int out_max)
219{
220 const int run = in_max - in_min;
221 if (run == 0)
222 return 0;
223 const int rise = out_max - out_min;
224 const int delta = x - in_min;
225 return (delta * rise) / run + out_min;
226}
227
228//-------------------------------------------------------------------
229// Unspecified values
230//-------------------------------------------------------------------
231
236enum class UNSPECIFIED
237{
239 VALUE = 0xFF
240};
241
242//-------------------------------------------------------------------
243// Input numbers
244//-------------------------------------------------------------------
245
252{
253public:
256 {
257 _value = 0xFF;
258 }
259
265 InputNumber(uint8_t value)
266 {
267 if (value >= 64)
268 throw invalid_input_number(value);
269 _value = value;
270 }
271
278 {
279 _value = 0xFF;
280 }
281
288 {
289 _value = number._value;
290 }
291
297 explicit operator uint64_t() const
298 {
299 if (_value < 64)
300 return (1ULL << _value);
301 else
302 return 0ULL;
303 }
304
310 operator uint8_t() const
311 {
312 if (_value > 63)
313 throw std::bad_cast();
314 else
315 return _value;
316 }
317
325 bool operator==(const UNSPECIFIED value) const { return (_value > 63); }
326
334 bool operator!=(const UNSPECIFIED value) const { return (_value < 64); }
335
337
338 inline bool operator==(const InputNumber value) const { return (_value == value._value); }
339 inline bool operator!=(const InputNumber value) const { return (_value != value._value); }
340 inline bool operator<(const InputNumber value) const { return (_value < value._value); }
341
342 constexpr InputNumber &operator=(const InputNumber &other)
343 {
344 _value = other._value;
345 return *this;
346 }
347
348 constexpr InputNumber &operator=(uint8_t value)
349 {
350 if (value >= 64)
351 throw invalid_input_number(value);
352 _value = value;
353 return *this;
354 }
355
357
362 void book() const
363 {
364 if (_value < 64)
365 _registered |= (1ULL << _value);
366 }
367
372 void unbook() const
373 {
374 if (_value < 64)
375 _registered &= ~(1ULL << _value);
376 }
377
382 static void bookAll()
383 {
384 _registered = ~(0ULL);
385 }
386
394 static bool booked(InputNumber inputNumber)
395 {
396 return _registered & (uint64_t)inputNumber;
397 }
398
406 static bool booked(uint8_t inputNumber)
407 {
408 // Avoid two implicit typecasts
409 if (inputNumber < 64)
410 return _registered & (1ULL << inputNumber);
411 else
412 return false;
413 }
414
420 static uint64_t booked() { return _registered; }
421
422#if CD_CI
423 static void clearBook()
424 {
425 _registered = 0ULL;
426 };
427#endif
428
429private:
430 uint8_t _value;
431 inline static uint64_t _registered = 0ULL;
432};
433
438class InputNumberCombination : public std::vector<InputNumber>
439{
440public:
446 operator std::vector<uint8_t>()
447 {
448 std::vector<uint8_t> result = {};
449 for (InputNumber inputNumber : *this)
450 {
451 if (inputNumber == UNSPECIFIED::VALUE)
452 throw invalid_input_number();
453 else
454 result.push_back((uint8_t)inputNumber);
455 }
456 return result;
457 }
458
464 InputNumberCombination(std::initializer_list<uint8_t> items)
465 {
466 this->clear();
467 for (auto item = items.begin(); item != items.end(); ++item)
468 {
469 if (*item > 63)
470 throw invalid_input_number(*item);
471 else
472 this->push_back(static_cast<InputNumber>(*item));
473 }
474 }
475
481 explicit operator uint64_t()
482 {
483 uint64_t bitmap = 0ULL;
484 for (size_t i = 0; i < this->size(); i++)
485 bitmap = bitmap | (uint64_t)this->at(i);
486 return bitmap;
487 }
488};
489
490// Well-known input numbers for PC game controllers
491#define JOY_A 0
492#define JOY_B 1
493#define JOY_X 2
494#define JOY_Y 3
495#define JOY_LB 4
496#define JOY_RB 5
497#define JOY_LSHIFT_PADDLE 4
498#define JOY_RSHIFT_PADDLE 5
499#define JOY_BACK 6
500#define JOY_START 7
501#define JOY_LTHUMBSTICK_CLICK 8
502#define JOY_RTHUMBSTICK_CLICK 9
503
504//-------------------------------------------------------------------
505// User-defined input numbers
506//-------------------------------------------------------------------
507
513{
514public:
517 {
518 _value = 0;
519 }
520
526 UserInputNumber(uint8_t value)
527 {
528 if (value >= 128)
529 throw invalid_user_input_number(value);
530 _value = value;
531 }
532
539 {
540 _value = number._value;
541 }
542
548 uint64_t getHigh() const
549 {
550 if (_value < 64)
551 return (1ULL << _value);
552 else
553 return 0ULL;
554 }
555
561 uint64_t getLow() const
562 {
563 if (_value >= 64)
564 return 0ULL;
565 else
566 return (1ULL << _value);
567 }
568
574 operator uint8_t() const
575 {
576 if (_value > 127)
577 throw std::bad_cast();
578 else
579 return _value;
580 }
581
583
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); }
587
589
590private:
591 uint8_t _value;
592};
593
594//-------------------------------------------------------------------
595// GPIO PINS
596//-------------------------------------------------------------------
597// Implemented in GPIO.cpp
598//-------------------------------------------------------------------
599
605struct GPIO
606{
607public:
614 GPIO(int pin)
615 {
616 if (pin < 0)
617 {
618 // Unspecified
619 _pin = -1;
620 return;
621 }
622
623 if (!GPIO_IS_VALID_GPIO(pin))
624 throw gpio_error(pin, "Does not exist");
625 bool reserved = false;
626#if defined(CONFIG_IDF_TARGET_ESP32)
627 reserved = (pin >= GPIO_NUM_6) && (pin <= GPIO_NUM_11); // Flash
628 reserved = reserved ||
629 ((pin >= GPIO_NUM_16) && (pin <= GPIO_NUM_17) && psramFound()); // PSRAM
630
631 // reserved = reserved || (pin == GPIO_NUM_1) || (pin == GPIO_NUM_3); // Serial port
632#elif defined(CONFIG_IDF_TARGET_ESP32S2)
633// Not sure:
634// reserved = (pin >= GPIO_NUM_22) && (pin <= GPIO_NUM_32) && (pin != GPIO_NUM_26);
635#elif defined(CONFIG_IDF_TARGET_ESP32S3)
636 reserved = ((pin >= GPIO_NUM_26) && (pin <= GPIO_NUM_32)); // Flash
637 reserved = reserved ||
638 ((pin >= GPIO_NUM_35) && (pin <= GPIO_NUM_37) && psramFound()); // PSRAM
639
640 // reserved = reserved || (pin == GPIO_NUM_43) || (pin == GPIO_NUM_44); // Serial port
641#elif defined(CONFIG_IDF_TARGET_ESP32C3)
642 reserved = (pin >= GPIO_NUM_11) && (pin <= GPIO_NUM_17);
643
644 // reserved = reserved || (pin == GPIO_NUM_20) || (pin == GPIO_NUM_21); // Serial port
645#elif CD_CI
646 reserved = (pin == TEST_RESERVED_GPIO);
647#endif
648 if (reserved)
649 throw gpio_error(pin, "Reserved for SPI FLASH, PSRAM or otherwise NOT USABLE");
650 _pin = pin;
651 }
652
657 GPIO() { _pin = -1; }
658
664 GPIO(UNSPECIFIED value) : GPIO() {}
665
671 operator int() const { return _pin; }
672
678 GPIO(const GPIO &instance) { _pin = instance._pin; }
679
687 inline bool operator==(const UNSPECIFIED value) const { return _pin < 0; }
688
696 inline bool operator!=(const UNSPECIFIED value) const { return _pin >= 0; }
697
699
700 inline bool operator!=(const GPIO value) const { return (_pin != value._pin); }
701 inline bool operator==(const GPIO value) const { return (_pin == value._pin); }
702 inline bool operator<(const GPIO value) const { return (_pin < value._pin); }
703
705
711 void reserve() const
712 {
714 if ((_pin >= 0) && !addIfNotExists<int>(_pin, reservedPins))
715 throw gpio_error(_pin, "Already in use");
716 }
717
722 void grant() const
723 {
725 if (_pin >= 0)
726 reservedPins.erase(
727 std::find(
728 reservedPins.begin(),
729 reservedPins.end(),
730 _pin));
731 }
732
739 {
740 if (_pin < 0)
741 throw gpio_error(_pin, "Is unspecified but required");
742 }
743
744#if CD_CI
745 static void clearReservations()
746 {
747 reservedPins.clear();
748 }
749#endif
750
751private:
752 inline static std::vector<int> reservedPins = {};
753
754protected:
756 int _pin;
757};
758
763struct OutputGPIO : public GPIO
764{
765public:
771 OutputGPIO(int pin) : GPIO(pin)
772 {
773 if ((pin >= 0) && !GPIO_IS_VALID_OUTPUT_GPIO(pin))
774 throw gpio_error(pin, "Not output-capable");
775 }
777 OutputGPIO() : GPIO() {};
779 OutputGPIO(UNSPECIFIED value) : GPIO(value) {}
780};
781
786struct InputGPIO : public GPIO
787{
788public:
790 InputGPIO() : GPIO() {};
796 InputGPIO(int pin) : GPIO(pin) {}
798 InputGPIO(UNSPECIFIED value) : GPIO(value) {}
799};
800
805struct ADC_GPIO : public InputGPIO
806{
807public:
810
816 ADC_GPIO(int pin) : InputGPIO(pin) {}
817
823 ADC_GPIO(UNSPECIFIED value) : InputGPIO(value) {}
824};
825
830struct RTC_GPIO : public InputGPIO
831{
832public:
838 RTC_GPIO(int pin) : InputGPIO(pin)
839 {
840 if ((pin >= 0) && !GPIO_IS_VALID_RTC_GPIO(pin))
841 throw gpio_error(pin, "Not RTC-capable");
842 }
843};
844
845//-------------------------------------------------------------------
846// GPIO pin collections
847//-------------------------------------------------------------------
848
850typedef std::vector<GPIO> GPIOCollection;
852typedef std::vector<InputGPIO> InputGPIOCollection;
854typedef std::vector<OutputGPIO> OutputGPIOCollection;
855
856//-------------------------------------------------------------------
857// I2C
858//-------------------------------------------------------------------
859
864#if CONFIG_IDF_TARGET_ESP32C3
865// The ESP32-C3 does not have a secondary bus
866enum class I2CBus
867{
868 PRIMARY = 0,
869 SECONDARY = 0
870};
871#else
872enum class I2CBus
873{
874 PRIMARY = 0,
875 SECONDARY
876};
877#endif
878
879//-------------------------------------------------------------------
880// Power latch
881//-------------------------------------------------------------------
882
887enum class PowerLatchMode : uint8_t
888{
895};
896
897//-------------------------------------------------------------------
898// Connectivity
899//-------------------------------------------------------------------
900
902enum class Connectivity : uint8_t
903{
905 USB_BLE = 0,
909 USB = 2,
911 BLE = 3,
913 DUMMY = 4,
916};
917
918//-------------------------------------------------------------------
919// LED strips
920//-------------------------------------------------------------------
921
926enum class PixelGroup
927{
929 GRP_TELEMETRY = 0,
934};
935
940enum class PixelDriver
941{
943 WS2811 = 0,
945 WS2812,
947 WS2815,
949 SK6812,
951 UCS1903
952};
953
958enum class PixelFormat
959{
961 AUTO = 0,
963 RGB,
965 RBG,
967 GRB,
969 GBR,
971 BRG,
973 BGR
974};
975
976//-------------------------------------------------------------------
977// Telemetry data
978//-------------------------------------------------------------------
979
984typedef struct
985{
990 uint32_t frameID;
995 struct
996 {
998 char gear = ' ';
1000 uint16_t rpm = 0;
1002 uint8_t rpmPercent = 0;
1004 uint8_t shiftLight1 = 0;
1006 uint8_t shiftLight2 = 0;
1008 bool revLimiter = false;
1010 bool engineStarted = false;
1012 uint16_t speed = 0;
1013 } powertrain;
1018 struct
1019 {
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;
1035 uint8_t tcCut = 0;
1037 uint8_t brakeBias = 0;
1038 } ecu;
1043 struct
1044 {
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;
1056 } raceControl;
1061 struct
1062 {
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;
1077 } gauges;
1079
1080//-------------------------------------------------------------------
1081// User interface
1082//-------------------------------------------------------------------
1083
1090{
1091protected:
1103 uint32_t frameTimer(
1104 uint32_t &timerVariable,
1105 uint32_t elapsedTimeMs,
1106 uint32_t timeLimitMs)
1107 {
1108 timerVariable += elapsedTimeMs;
1109 uint32_t result = timerVariable / timeLimitMs;
1110 timerVariable %= timeLimitMs;
1111 return result;
1112 };
1113
1114public:
1123
1124 // Non copyable
1125
1126 AbstractUserInterface() = default;
1128 AbstractUserInterface &operator=(const AbstractUserInterface &) = delete;
1129
1130public:
1138 virtual uint8_t getMaxFPS() { return 0; }
1139
1151 virtual uint16_t getStackSize() { return 0; }
1152
1157 virtual void onStart() {};
1158
1181 virtual void onTelemetryData(const TelemetryData *pTelemetryData) {};
1182
1194 virtual void serveSingleFrame(uint32_t elapsedMs) {};
1195
1202 virtual void onBitePoint(uint8_t bitePoint) {};
1203
1208 virtual void onConnected() {};
1209
1214 virtual void onBLEdiscovering() {};
1215
1222 virtual void onLowBattery() {};
1223
1228 virtual void onSaveSettings() {};
1229
1237 virtual void shutdown() {};
1238};
1239
1240//-------------------------------------------------------------------
1241
1248{
1249private:
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 {};
1259
1260protected:
1261 // Singleton pattern
1262
1264 virtual ~PixelControlNotification() {}
1265
1266 // For descendant classes
1267
1275 bool notConnectedYet = true;
1276
1284
1298 void set(PixelGroup group,
1299 uint8_t pixelIndex,
1300 uint8_t red,
1301 uint8_t green,
1302 uint8_t blue);
1303
1313 PixelGroup group,
1314 uint8_t red,
1315 uint8_t green,
1316 uint8_t blue);
1317
1324
1331
1347 PixelGroup group,
1348 bool colorGradientOrPercentage,
1349 uint32_t barColor = 0x00ACFA70);
1350
1351public:
1358 {
1359 static PixelControlNotification *_instance = nullptr;
1360 if (!_instance)
1361 _instance = new PixelControlNotification();
1362 return _instance;
1363 }
1364
1365public:
1367 void operator=(const PixelControlNotification &) = delete;
1368
1373 virtual void pixelControl_OnStart();
1374
1380 virtual void pixelControl_OnBitePoint(uint8_t bitePoint);
1381
1388
1395
1401
1409};
1410
1411//-------------------------------------------------------------------
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.
@ RBG
Red-blue-green.
@ BGR
Blue-green-red.
@ BRG
Blue-red-green.
@ GRB
Green-red-blue.
@ RGB
Red-green-blue.
@ GBR
Green-blue-red.
@ 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.
PixelDriver
Pixel driver.
@ UCS1903
UCS1903 driver.
@ SK6812
SK6812 driver.
@ WS2812
WS2812 family.
@ WS2815
WS2815 family.
@ WS2811
WS2811 driver.
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.
Combination of input numbers.
InputNumberCombination(std::initializer_list< uint8_t > items)
Create a vector of input numbers from integer constants/variables.
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 empty input number specifications.
empty_input_number_set(const std::string &hardware)
Construct a new empty_input_number_set exception.
Exception for invalid GPIO pin numbers.
gpio_error(uint8_t value, const std::string &reason)
Construct a new gpio_error exception.
Exception for invalid input numbers.
invalid_input_number()
Construct a new invalid input number object for unspecified input numbers.
invalid_input_number(uint8_t value)
Construct a new invalid_input_number exception.
Exception for invalid user-defined input numbers.
invalid_user_input_number()
Construct a new invalid input number object for unspecified input numbers.
invalid_user_input_number(uint8_t value)
Construct a new invalid_input_number exception.
Exception for unknown input numbers.
unknown_input_number(std::string usage)
Construct a new unknown_input_number 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.
GPIO pin number.
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".
Input-capable GPIO pin number.
InputGPIO(UNSPECIFIED value)
Create a "not connected" input GPIO.
InputGPIO(int pin)
Create an input GPIO.
InputGPIO()
Create a "not connected" input GPIO.
Firmware-defined input numbers in the range [0,63] or unspecified.
InputNumber(uint8_t value)
Cast an integer to a input number.
InputNumber(const InputNumber &number)
Copy an input number.
bool operator==(const UNSPECIFIED value) const
Check if this input number is unspecified.
static void bookAll()
Book all input numbers as in use (for testing)
bool operator!=(const UNSPECIFIED value) const
Check if this input number was specified.
void unbook() const
Unbook.
void book() const
Book as in use.
InputNumber(UNSPECIFIED value)
Assign an unspecified value.
static bool booked(InputNumber inputNumber)
Check if an input number is booked.
static bool booked(uint8_t inputNumber)
Check if an input number is booked.
static uint64_t booked()
Get a bitmap of all booked input numbers.
InputNumber()
Construct an unspecified input number.
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.
Telemetry data.
uint32_t frameID
Identifies a telemetry frame. For internal use. Do not overwrite.
User-defined input numbers in the range [0,127].
uint64_t getHigh() const
Get the most significant 64-bit bitmap.
UserInputNumber()
Construct an user-defined input number.
uint64_t getLow() const
Get the least significant 64-bit bitmap.
UserInputNumber(const UserInputNumber &number)
Copy a user-defined input number.
UserInputNumber(uint8_t value)
Cast an integer to a user-defined input number.