OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
Loading...
Searching...
No Matches
OutputHardware.hpp
Go to the documentation of this file.
1
12#pragma once
13
14//---------------------------------------------------------------
15// Imports
16//---------------------------------------------------------------
17
18#include "SimWheelTypes.hpp"
19#include "driver/rmt_tx.h" // For rmt_channel_handle_t & rmt_encoder_handle_t
20
21//---------------------------------------------------------------
22// Led strip encoder
23//---------------------------------------------------------------
24
30{
31public:
45 OutputGPIO dataPin,
46 uint8_t pixelCount,
47 bool useLevelShift,
49 PixelFormat pixelFormat = PixelFormat::AUTO);
50 ~LEDStrip();
51
57 uint8_t getPixelCount() { return pixelCount; }
58
70 void brightness(uint8_t value) { brightnessWeight = value + 1; }
71
72 // protected:
78 void clear();
79
90 uint8_t pixelIndex,
91 uint8_t redChannel,
92 uint8_t greenChannel,
93 uint8_t blueChannel);
94
106 uint8_t fromPixelIndex,
107 uint8_t toPixelIndex,
108 uint8_t redChannel,
109 uint8_t greenChannel,
110 uint8_t blueChannel);
111
119 uint8_t pixelIndex,
120 uint32_t packedRGB)
121 {
122 pixelRGB(pixelIndex,
123 (uint8_t)(packedRGB >> 16),
124 (uint8_t)(packedRGB >> 8),
125 (uint8_t)(packedRGB));
126 }
127
136 uint8_t fromPixelIndex,
137 uint8_t toPixelIndex,
138 uint32_t packedRGB)
139 {
140 pixelRangeRGB(fromPixelIndex,
141 toPixelIndex,
142 (uint8_t)(packedRGB >> 16),
143 (uint8_t)(packedRGB >> 8),
144 (uint8_t)(packedRGB));
145 }
146
152
158
163 void show();
164
165private:
166 uint8_t pixelCount;
167 uint8_t *pixelData;
168 PixelFormat pixelFormat;
169 rmt_channel_handle_t rmtHandle = nullptr;
170 rmt_encoder_handle_t encHandle = nullptr;
171 bool changed = false;
172 uint8_t brightnessWeight = 16;
173 uint32_t resetTimeNs = 280000;
174
175 void normalizeColor(uint8_t &r, uint8_t &g, uint8_t &b);
176 void rawPixelRGB(
177 uint8_t pixelIndex,
178 uint8_t redChannel,
179 uint8_t greenChannel,
180 uint8_t blueChannel);
181};
182
183//---------------------------------------------------------------
184// PCF8574 LED Driver
185//---------------------------------------------------------------
186
195{
196public:
205 I2CBus bus,
206 uint8_t address7bits);
207
217 void setLed(uint8_t index, bool state);
218
225 void shiftLeft();
226
234
240 void swap() { _state = ~_state; }
241
246 void show() const;
247
253 uint8_t getState() const { return _state; };
254
262 void setState(uint8_t state) { _state = state; }
263
265 {
266 setState(0);
267 show();
268 }
269
270private:
272 uint8_t _state = 0;
273
275 void *device = nullptr;
276};
277
278//---------------------------------------------------------------
279// Single LED
280//---------------------------------------------------------------
281
290{
291public:
298
304 void set(bool state) { _state = state; }
305
312 bool get() { return _state; }
313
319 void swap() { _state = !_state; }
320
325 void show();
326
327 ~SingleLED() { _pin.grant(); }
328
329private:
330 OutputGPIO _pin;
331 bool _state = false;
332};
Types and constants required for custom firmware setup.
I2CBus
I2C bus controller.
PixelFormat
Byte order of pixel data.
@ AUTO
Auto-detect based on pixel driver.
PixelDriver
Pixel driver.
@ WS2812
WS2812 family.
Low-level interface to LED strips.
void shiftToPrevious()
Shift all pixel colors to the previous pixel index.
void pixelRangeRGB(uint8_t fromPixelIndex, uint8_t toPixelIndex, uint32_t packedRGB)
Set color (in RGB format) to a range of pixels.
void show()
Show pixel colors.
uint8_t getPixelCount()
Retrieve the pixel count in the strip.
void shiftToNext()
Shift all pixel colors to the next pixel index.
void brightness(uint8_t value)
Set global LED brightness.
void pixelRGB(uint8_t pixelIndex, uint32_t packedRGB)
Set pixel color in RGB format.
void clear()
Turn off all LEDs.
LEDStrip(OutputGPIO dataPin, uint8_t pixelCount, bool useLevelShift, PixelDriver pixelType=PixelDriver::WS2812, PixelFormat pixelFormat=PixelFormat::AUTO)
Create an LED strip object.
void pixelRGB(uint8_t pixelIndex, uint8_t redChannel, uint8_t greenChannel, uint8_t blueChannel)
Set pixel color in RGB format.
void pixelRangeRGB(uint8_t fromPixelIndex, uint8_t toPixelIndex, uint8_t redChannel, uint8_t greenChannel, uint8_t blueChannel)
Set color (in RGB format) to a range of pixels.
8-LED driver based on the PCF8574 GPIO expander
void shiftLeft()
Shift all lights to the left.
uint8_t getState() const
Get the state of each LED.
PCF8574LedDriver(I2CBus bus, uint8_t address7bits)
Construct a LED driver.
void swap()
Invert the state of all LEDs.
void shiftRight()
Shift all lights to the right.
void setLed(uint8_t index, bool state)
Set the state of a single LED.
void setState(uint8_t state)
Set the state of each LED all at once.
void show() const
Show the required LEDs all at once.
A simple LED driver for a single LED.
void swap()
Invert the state of the LED.
SingleLED(OutputGPIO pin)
Create a new single-LED driver.
void set(bool state)
Set the state of the LED.
bool get()
Get the state of the LED.
void show()
Show the state of the LED.
void grant() const
Grant this GPIO for non-exclusive use.
Output-capable GPIO pin number.