ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputMgr.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputMgr.hpp - Output Management class
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2021, 2025 Shelby Merrick
7* http://www.forkineye.com
8*
9* This program is provided free for you to use in any way that you wish,
10* subject to the laws and regulations where you are using it. Due diligence
11* is strongly suggested before using this code. Please give credit where due.
12*
13* The Author makes no warranty of any kind, express or implied, with regard
14* to this program or the documentation contained in this document. The
15* Author shall not be liable in any event for incidental or consequential
16* damages in connection with, or arising out of, the furnishing, performance
17* or use of these programs.
18*
19* This is a factory class used to manage the output port. It creates and deletes
20* the output channel functionality as needed to support any new configurations
21* that get sent from from the WebPage.
22*
23*/
24
25#include "ESPixelStick.h"
26#include "memdebug.h"
27#include "FileMgr.hpp"
28#include <TimeLib.h>
29
30class c_OutputCommon;
31
32#ifdef UART_LAST
33# define NUM_UARTS UART_LAST
34#else
35# define NUM_UARTS 0
36#endif
37
39{
40public:
41 c_OutputMgr ();
42 virtual ~c_OutputMgr ();
43
44 void Begin ();
45 void Poll ();
47 void LoadConfig ();
48 void GetConfig (byte * Response, uint32_t maxlen);
49 void GetConfig (String & Response);
50 void SetConfig (const char * NewConfig);
51 void SetConfig (ArduinoJson::JsonDocument & NewConfig);
52 void GetStatus (JsonObject & jsonStatus);
53 void GetPortCounts (uint16_t& PixelCount, uint16_t& SerialCount) {PixelCount = uint16_t(OutputChannelId_End); SerialCount = uint16_t(NUM_UARTS); }
54 uint8_t* GetBufferAddress () { return OutputBuffer; }
55 uint32_t GetBufferUsedSize () { return UsedBufferSize; }
56 uint32_t GetBufferSize () { return sizeof(OutputBuffer); }
58 void PauseOutputs (bool NewState);
59 void GetDriverName (String & Name) { Name = "OutputMgr"; }
60 void WriteChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t * pData);
61 void ReadChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData);
62 void ClearBuffer ();
63 void TaskPoll ();
64
65 // handles to determine which output channel we are dealing with
67 {
68 #ifdef DEFAULT_UART_0_GPIO
69 OutputChannelId_UART_0,
70 #endif // def DEFAULT_UART_0_GPIO
71
72 #ifdef DEFAULT_UART_1_GPIO
73 OutputChannelId_UART_1,
74 #endif // def DEFAULT_UART_1_GPIO
75
76 #ifdef DEFAULT_UART_2_GPIO
77 OutputChannelId_UART_2,
78 #endif // def DEFAULT_UART_2_GPIO
79
80 #ifdef DEFAULT_RMT_0_GPIO
81 OutputChannelId_RMT_0,
82 #endif // def DEFAULT_RMT_0_GPIO
83
84 #ifdef DEFAULT_RMT_1_GPIO
85 OutputChannelId_RMT_1,
86 #endif // def DEFAULT_RMT_1_GPIO
87
88 #ifdef DEFAULT_RMT_2_GPIO
89 OutputChannelId_RMT_2,
90 #endif // def DEFAULT_RMT_2_GPIO
91
92 #ifdef DEFAULT_RMT_3_GPIO
93 OutputChannelId_RMT_3,
94 #endif // def DEFAULT_RMT_3_GPIO
95
96 #ifdef DEFAULT_RMT_4_GPIO
97 OutputChannelId_RMT_4,
98 #endif // def DEFAULT_RMT_3_GPIO
99
100 #ifdef DEFAULT_RMT_5_GPIO
101 OutputChannelId_RMT_5,
102 #endif // def DEFAULT_RMT_3_GPIO
103
104 #ifdef DEFAULT_RMT_6_GPIO
105 OutputChannelId_RMT_6,
106 #endif // def DEFAULT_RMT_3_GPIO
107
108 #ifdef DEFAULT_RMT_7_GPIO
109 OutputChannelId_RMT_7,
110 #endif // def DEFAULT_RMT_3_GPIO
111
112 #ifdef SUPPORT_SPI_OUTPUT
113 OutputChannelId_SPI_1,
114 #endif // def SUPPORT_SPI_OUTPUT
115
116 #if defined(SUPPORT_OutputType_Relay) || defined(SUPPORT_OutputType_Servo_PCA9685)
117 OutputChannelId_Relay,
118 #endif // def SUPPORT_RELAY_OUTPUT
119
120 OutputChannelId_End, // must be last in the list
122 };
123
124 // do NOT insert into the middle of this list. Always add new types to the end of the list
126 {
128
129 #ifdef SUPPORT_OutputType_WS2811
130 OutputType_WS2811 = 1,
131 #endif // def SUPPORT_OutputType_WS2811
132
133 #ifdef SUPPORT_OutputType_GECE
134 OutputType_GECE = 2,
135 #endif // def SUPPORT_OutputType_GECE
136
137 #ifdef SUPPORT_OutputType_DMX
138 OutputType_DMX = 3,
139 #endif // def SUPPORT_OutputType_DMX
140
141 #ifdef SUPPORT_OutputType_Renard
142 OutputType_Renard = 4,
143 #endif // def SUPPORT_OutputType_Renard
144
145 #ifdef SUPPORT_OutputType_Serial
146 OutputType_Serial = 5,
147 #endif // def SUPPORT_OutputType_Serial
148
149 #ifdef SUPPORT_OutputType_Relay
150 OutputType_Relay = 6,
151 #endif // def SUPPORT_OutputType_Relay
152
153 #ifdef SUPPORT_OutputType_Servo_PCA9685
154 OutputType_Servo_PCA9685 = 7,
155 #endif // def SUPPORT_OutputType_Servo_PCA9685
156
157 #ifdef SUPPORT_OutputType_UCS1903
158 OutputType_UCS1903 = 8,
159 #endif // def SUPPORT_OutputType_UCS1903
160
161 #ifdef SUPPORT_OutputType_TM1814
162 OutputType_TM1814 = 9,
163 #endif // def SUPPORT_OutputType_TM1814
164
165 #ifdef SUPPORT_OutputType_WS2801
166 OutputType_WS2801 = 10,
167 #endif // def SUPPORT_OutputType_WS2801
168
169 #ifdef SUPPORT_OutputType_APA102
170 OutputType_APA102 = 11,
171 #endif // def SUPPORT_OutputType_APA102
172
173 #ifdef SUPPORT_OutputType_GS8208
174 OutputType_GS8208 = 12,
175 #endif // def SUPPORT_OutputType_GS8208
176
177 #ifdef SUPPORT_OutputType_UCS8903
178 OutputType_UCS8903 = 13,
179 #endif // def SUPPORT_OutputType_UCS8903
180
181 #ifdef SUPPORT_OutputType_TLS3001
182 OutputType_TLS3001 = 14,
183 #endif // def SUPPORT_OutputType_TLS3001
184
185 #ifdef SUPPORT_OutputType_GRINCH
186 OutputType_GRINCH = 15,
187 #endif // def SUPPORT_OutputType_GRINCH
188
189 // Add new types here
190 OutputType_End, // must be last
192 };
193
194#ifdef ARDUINO_ARCH_ESP8266
195# define OM_MAX_NUM_CHANNELS (1200 * 3)
196#else // ARDUINO_ARCH_ESP32
197# define OM_MAX_NUM_CHANNELS (3000 * 3)
198#endif // !def ARDUINO_ARCH_ESP32
199
208
209private:
226
227 // pointer(s) to the current active output drivers
229
230 // configuration parameter names for the channel manager within the config file
231 #define NO_CONFIG_NEEDED time_t(-1)
232 bool HasBeenInitialized = false;
234 bool ConfigInProgress = false;
235 bool OutputIsPaused = false;
236 bool BuildingNewConfig = false;
237
238 bool ProcessJsonConfig (JsonDocument & jsonConfig);
239 void CreateJsonConfig (JsonObject & jsonConfig);
241 void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver = true);
242 void CreateNewConfig();
243 void SetSerialUart();
244 bool FindJsonChannelConfig (JsonDocument& jsonConfig, e_OutputChannelIds ChanId, e_OutputType Type, JsonObject& ChanConfig);
245
247
249 uint32_t UsedBufferSize = 0;
250 gpio_num_t ConsoleTxGpio = gpio_num_t::GPIO_NUM_1;
251 gpio_num_t ConsoleRxGpio = gpio_num_t::GPIO_NUM_3;
252#if defined(ARDUINO_ARCH_ESP32)
253 TaskHandle_t myTaskHandle = NULL;
254 // uint32_t PollCount = 0;
255#endif // defined(ARDUINO_ARCH_ESP32)
256
257#define OM_IS_UART (CurrentOutputChannelDriver.PortType == OM_PortType_t::Uart)
258#define OM_IS_RMT (CurrentOutputChannelDriver.PortType == OM_PortType_t::Rmt)
259
260}; // c_OutputMgr
261
c_FileMgr FileMgr
Definition FileMgr.cpp:2192
#define OM_MAX_NUM_CHANNELS
Definition OutputMgr.hpp:197
#define NO_CONFIG_NEEDED
Definition OutputMgr.hpp:231
#define NUM_UARTS
forward declaration to the pure virtual output class that will be defined later.
Definition OutputMgr.hpp:35
c_OutputMgr OutputMgr
Definition OutputMgr.cpp:1580
void DeleteFlashFile(const String &FileName)
Definition FileMgr.cpp:560
Definition OutputCommon.hpp:31
Definition OutputMgr.hpp:39
e_OutputChannelIds
Definition OutputMgr.hpp:67
@ OutputChannelId_End
Definition OutputMgr.hpp:120
@ OutputChannelId_Start
Definition OutputMgr.hpp:121
e_OutputType
Definition OutputMgr.hpp:126
@ OutputType_Disabled
Definition OutputMgr.hpp:127
@ OutputType_Start
Definition OutputMgr.hpp:191
@ OutputType_End
Definition OutputMgr.hpp:190
void GetDriverName(String &Name)
Definition OutputMgr.hpp:59
void LoadConfig()
Read the current configuration data from nvram.
Definition OutputMgr.cpp:995
void CreateJsonConfig(JsonObject &jsonConfig)
Definition OutputMgr.cpp:281
gpio_num_t ConsoleRxGpio
Definition OutputMgr.hpp:251
void UpdateDisplayBufferReferences(void)
Definition OutputMgr.cpp:1352
void TaskPoll()
bool ProcessJsonConfig(JsonDocument &jsonConfig)
Definition OutputMgr.cpp:1126
c_OutputMgr()
< Start up the driver and put it into a safe mode
Definition OutputMgr.cpp:198
void GetPortCounts(uint16_t &PixelCount, uint16_t &SerialCount)
Definition OutputMgr.hpp:53
void GetConfig(byte *Response, uint32_t maxlen)
Definition OutputMgr.cpp:452
virtual ~c_OutputMgr()
< deallocate any resources and put the output channels into a safe state
Definition OutputMgr.cpp:209
uint32_t UsedBufferSize
Definition OutputMgr.hpp:249
void GetStatus(JsonObject &jsonStatus)
Definition OutputMgr.cpp:463
uint8_t OutputBuffer[OM_MAX_NUM_CHANNELS]
Definition OutputMgr.hpp:248
void SetConfig(const char *NewConfig)
Save the current configuration data to nvram.
Definition OutputMgr.cpp:1225
void DeleteConfig()
Definition OutputMgr.hpp:57
void ClearBuffer()
Definition OutputMgr.cpp:1563
void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver=true)
Definition OutputMgr.cpp:496
bool BuildingNewConfig
Definition OutputMgr.hpp:236
time_t ConfigLoadNeeded
Definition OutputMgr.hpp:233
bool ConfigInProgress
Definition OutputMgr.hpp:234
bool FindJsonChannelConfig(JsonDocument &jsonConfig, e_OutputChannelIds ChanId, e_OutputType Type, JsonObject &ChanConfig)
Definition OutputMgr.cpp:1034
void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputMgr.cpp:225
void SetSerialUart()
Definition OutputMgr.cpp:1274
OM_PortType_t
Definition OutputMgr.hpp:201
@ Uart
Definition OutputMgr.hpp:202
@ Undefined
Definition OutputMgr.hpp:206
@ Spi
Definition OutputMgr.hpp:204
@ Relay
Definition OutputMgr.hpp:205
@ Rmt
Definition OutputMgr.hpp:203
uint32_t GetBufferUsedSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:55
void PauseOutputs(bool NewState)
Definition OutputMgr.cpp:1423
uint32_t GetBufferSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:56
void WriteChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pData)
Definition OutputMgr.cpp:1439
gpio_num_t ConsoleTxGpio
Definition OutputMgr.hpp:250
void ScheduleLoadConfig()
Definition OutputMgr.hpp:46
void CreateNewConfig()
Definition OutputMgr.cpp:361
void ReadChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData)
Definition OutputMgr.cpp:1503
String ConfigFileName
Definition OutputMgr.hpp:246
DriverInfo_t OutputChannelDrivers[OutputChannelId_End]
Definition OutputMgr.hpp:228
uint8_t * GetBufferAddress()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:54
void Poll()
Call from loop(), renders output data.
Definition OutputMgr.cpp:1319
bool HasBeenInitialized
Definition OutputMgr.hpp:232
bool OutputIsPaused
Definition OutputMgr.hpp:235
Definition OutputMgr.hpp:211
gpio_num_t GpioPin
Definition OutputMgr.hpp:220
c_OutputCommon * pOutputChannelDriver
Definition OutputMgr.hpp:224
OM_PortType_t PortType
Definition OutputMgr.hpp:221
uint32_t OutputChannelSize
Definition OutputMgr.hpp:217
uint32_t OutputChannelEndOffset
Definition OutputMgr.hpp:218
uint32_t OutputBufferStartingOffset
Definition OutputMgr.hpp:212
uint32_t OutputBufferDataSize
Definition OutputMgr.hpp:213
uint32_t OutputBufferEndOffset
Definition OutputMgr.hpp:214
uart_port_t PortId
Definition OutputMgr.hpp:222
e_OutputChannelIds DriverId
Definition OutputMgr.hpp:223
uint32_t OutputChannelStartingOffset
Definition OutputMgr.hpp:216