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 void RelayUpdate (uint8_t RelayId, String & NewValue, String & Response);
65 void ClearStatistics (void);
66
67 // handles to determine which output channel we are dealing with
69 {
70 #ifdef DEFAULT_UART_0_GPIO
71 OutputChannelId_UART_0,
72 #endif // def DEFAULT_UART_0_GPIO
73
74 #ifdef DEFAULT_UART_1_GPIO
75 OutputChannelId_UART_1,
76 #endif // def DEFAULT_UART_1_GPIO
77
78 #ifdef DEFAULT_UART_2_GPIO
79 OutputChannelId_UART_2,
80 #endif // def DEFAULT_UART_2_GPIO
81
82 #ifdef DEFAULT_RMT_0_GPIO
83 OutputChannelId_RMT_0,
84 #endif // def DEFAULT_RMT_0_GPIO
85
86 #ifdef DEFAULT_RMT_1_GPIO
87 OutputChannelId_RMT_1,
88 #endif // def DEFAULT_RMT_1_GPIO
89
90 #ifdef DEFAULT_RMT_2_GPIO
91 OutputChannelId_RMT_2,
92 #endif // def DEFAULT_RMT_2_GPIO
93
94 #ifdef DEFAULT_RMT_3_GPIO
95 OutputChannelId_RMT_3,
96 #endif // def DEFAULT_RMT_3_GPIO
97
98 #ifdef DEFAULT_RMT_4_GPIO
99 OutputChannelId_RMT_4,
100 #endif // def DEFAULT_RMT_3_GPIO
101
102 #ifdef DEFAULT_RMT_5_GPIO
103 OutputChannelId_RMT_5,
104 #endif // def DEFAULT_RMT_3_GPIO
105
106 #ifdef DEFAULT_RMT_6_GPIO
107 OutputChannelId_RMT_6,
108 #endif // def DEFAULT_RMT_3_GPIO
109
110 #ifdef DEFAULT_RMT_7_GPIO
111 OutputChannelId_RMT_7,
112 #endif // def DEFAULT_RMT_3_GPIO
113
114 #ifdef SUPPORT_SPI_OUTPUT
115 OutputChannelId_SPI_1,
116 #endif // def SUPPORT_SPI_OUTPUT
117
118 #if defined(SUPPORT_OutputType_Relay) || defined(SUPPORT_OutputType_Servo_PCA9685)
119 OutputChannelId_Relay,
120 #endif // def SUPPORT_RELAY_OUTPUT
121
122 OutputChannelId_End, // must be last in the list
124 };
125
126 // do NOT insert into the middle of this list. Always add new types to the end of the list
128 {
130
131 #ifdef SUPPORT_OutputType_WS2811
132 OutputType_WS2811 = 1,
133 #endif // def SUPPORT_OutputType_WS2811
134
135 #ifdef SUPPORT_OutputType_GECE
136 OutputType_GECE = 2,
137 #endif // def SUPPORT_OutputType_GECE
138
139 #ifdef SUPPORT_OutputType_DMX
140 OutputType_DMX = 3,
141 #endif // def SUPPORT_OutputType_DMX
142
143 #ifdef SUPPORT_OutputType_Renard
144 OutputType_Renard = 4,
145 #endif // def SUPPORT_OutputType_Renard
146
147 #ifdef SUPPORT_OutputType_Serial
148 OutputType_Serial = 5,
149 #endif // def SUPPORT_OutputType_Serial
150
151 #ifdef SUPPORT_OutputType_Relay
152 OutputType_Relay = 6,
153 #endif // def SUPPORT_OutputType_Relay
154
155 #ifdef SUPPORT_OutputType_Servo_PCA9685
156 OutputType_Servo_PCA9685 = 7,
157 #endif // def SUPPORT_OutputType_Servo_PCA9685
158
159 #ifdef SUPPORT_OutputType_UCS1903
160 OutputType_UCS1903 = 8,
161 #endif // def SUPPORT_OutputType_UCS1903
162
163 #ifdef SUPPORT_OutputType_TM1814
164 OutputType_TM1814 = 9,
165 #endif // def SUPPORT_OutputType_TM1814
166
167 #ifdef SUPPORT_OutputType_WS2801
168 OutputType_WS2801 = 10,
169 #endif // def SUPPORT_OutputType_WS2801
170
171 #ifdef SUPPORT_OutputType_APA102
172 OutputType_APA102 = 11,
173 #endif // def SUPPORT_OutputType_APA102
174
175 #ifdef SUPPORT_OutputType_GS8208
176 OutputType_GS8208 = 12,
177 #endif // def SUPPORT_OutputType_GS8208
178
179 #ifdef SUPPORT_OutputType_UCS8903
180 OutputType_UCS8903 = 13,
181 #endif // def SUPPORT_OutputType_UCS8903
182
183 #ifdef SUPPORT_OutputType_TLS3001
184 OutputType_TLS3001 = 14,
185 #endif // def SUPPORT_OutputType_TLS3001
186
187 #ifdef SUPPORT_OutputType_GRINCH
188 OutputType_GRINCH = 15,
189 #endif // def SUPPORT_OutputType_GRINCH
190
191 // Add new types here
192 OutputType_End, // must be last
194 };
195
196#ifdef ARDUINO_ARCH_ESP8266
197# define OM_MAX_NUM_CHANNELS (1200 * 3)
198#else // ARDUINO_ARCH_ESP32
199# define OM_MAX_NUM_CHANNELS (3000 * 3)
200#endif // !def ARDUINO_ARCH_ESP32
201
210
211 // must be 16 byte aligned. Determined by upshifting the max size of all drivers
212 #define OutputDriverMemorySize 1200
214private:
216 {
221
223 uint32_t OutputChannelSize = 0;
225
226 gpio_num_t GpioPin = gpio_num_t(-1);
228 uart_port_t PortId = uart_port_t(-1);
230 bool OutputDriverInUse = false;
231 };
232
233 // pointer(s) to the current active output drivers
235
236 // configuration parameter names for the channel manager within the config file
237 #define NO_CONFIG_NEEDED time_t(-1)
238 bool HasBeenInitialized = false;
240 bool ConfigInProgress = false;
241 bool OutputIsPaused = false;
242 bool BuildingNewConfig = false;
243
244 bool ProcessJsonConfig (JsonDocument & jsonConfig);
245 void CreateJsonConfig (JsonObject & jsonConfig);
247 void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver = true);
248 void CreateNewConfig();
249 void SetSerialUart();
250 bool FindJsonChannelConfig (JsonDocument& jsonConfig, e_OutputChannelIds ChanId, e_OutputType Type, JsonObject& ChanConfig);
251
253
255 uint32_t UsedBufferSize = 0;
256 gpio_num_t ConsoleTxGpio = gpio_num_t::GPIO_NUM_1;
257 gpio_num_t ConsoleRxGpio = gpio_num_t::GPIO_NUM_3;
258
259#if defined(ARDUINO_ARCH_ESP32)
260 TaskHandle_t myTaskHandle = NULL;
261 // uint32_t PollCount = 0;
262#endif // defined(ARDUINO_ARCH_ESP32)
263
264#define OM_IS_UART (CurrentOutput.PortType == OM_PortType_t::Uart)
265#define OM_IS_RMT (CurrentOutput.PortType == OM_PortType_t::Rmt)
266
267}; // c_OutputMgr
268
c_FileMgr FileMgr
Definition FileMgr.cpp:2241
#define OM_MAX_NUM_CHANNELS
Definition OutputMgr.hpp:199
#define NO_CONFIG_NEEDED
Definition OutputMgr.hpp:237
#define NUM_UARTS
forward declaration to the pure virtual output class that will be defined later.
Definition OutputMgr.hpp:35
#define OutputDriverMemorySize
Definition OutputMgr.hpp:212
c_OutputMgr OutputMgr
Definition OutputMgr.cpp:1633
void DeleteFlashFile(String FileName)
Definition FileMgr.cpp:587
Definition OutputCommon.hpp:31
Definition OutputMgr.hpp:39
e_OutputChannelIds
Definition OutputMgr.hpp:69
@ OutputChannelId_End
Definition OutputMgr.hpp:122
@ OutputChannelId_Start
Definition OutputMgr.hpp:123
e_OutputType
Definition OutputMgr.hpp:128
@ OutputType_Disabled
Definition OutputMgr.hpp:129
@ OutputType_Start
Definition OutputMgr.hpp:193
@ OutputType_End
Definition OutputMgr.hpp:192
void GetDriverName(String &Name)
Definition OutputMgr.hpp:59
void LoadConfig()
Read the current configuration data from nvram.
Definition OutputMgr.cpp:1027
void CreateJsonConfig(JsonObject &jsonConfig)
Definition OutputMgr.cpp:292
gpio_num_t ConsoleRxGpio
Definition OutputMgr.hpp:257
void UpdateDisplayBufferReferences(void)
Definition OutputMgr.cpp:1384
void TaskPoll()
bool ProcessJsonConfig(JsonDocument &jsonConfig)
Definition OutputMgr.cpp:1158
c_OutputMgr()
< Start up the driver and put it into a safe mode
Definition OutputMgr.cpp:205
void GetPortCounts(uint16_t &PixelCount, uint16_t &SerialCount)
Definition OutputMgr.hpp:53
void ClearStatistics(void)
Definition OutputMgr.cpp:496
void GetConfig(byte *Response, uint32_t maxlen)
Definition OutputMgr.cpp:464
virtual ~c_OutputMgr()
< deallocate any resources and put the output channels into a safe state
Definition OutputMgr.cpp:220
uint32_t UsedBufferSize
Definition OutputMgr.hpp:255
void GetStatus(JsonObject &jsonStatus)
Definition OutputMgr.cpp:475
uint8_t OutputBuffer[OM_MAX_NUM_CHANNELS]
Definition OutputMgr.hpp:254
void SetConfig(const char *NewConfig)
Save the current configuration data to nvram.
Definition OutputMgr.cpp:1257
void DeleteConfig()
Definition OutputMgr.hpp:57
void ClearBuffer()
Definition OutputMgr.cpp:1622
void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver=true)
Definition OutputMgr.cpp:527
bool BuildingNewConfig
Definition OutputMgr.hpp:242
time_t ConfigLoadNeeded
Definition OutputMgr.hpp:239
bool ConfigInProgress
Definition OutputMgr.hpp:240
bool FindJsonChannelConfig(JsonDocument &jsonConfig, e_OutputChannelIds ChanId, e_OutputType Type, JsonObject &ChanConfig)
Definition OutputMgr.cpp:1066
void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputMgr.cpp:236
void SetSerialUart()
Definition OutputMgr.cpp:1306
OM_PortType_t
Definition OutputMgr.hpp:203
@ Uart
Definition OutputMgr.hpp:204
@ Undefined
Definition OutputMgr.hpp:208
@ Spi
Definition OutputMgr.hpp:206
@ Relay
Definition OutputMgr.hpp:207
@ Rmt
Definition OutputMgr.hpp:205
uint32_t GetBufferUsedSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:55
uint32_t GetDriverSize()
Definition OutputMgr.hpp:213
void PauseOutputs(bool NewState)
Definition OutputMgr.cpp:1482
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:1498
gpio_num_t ConsoleTxGpio
Definition OutputMgr.hpp:256
void ScheduleLoadConfig()
Definition OutputMgr.hpp:46
void CreateNewConfig()
Definition OutputMgr.cpp:372
void ReadChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData)
Definition OutputMgr.cpp:1562
String ConfigFileName
Definition OutputMgr.hpp:252
DriverInfo_t OutputChannelDrivers[OutputChannelId_End]
Definition OutputMgr.hpp:234
uint8_t * GetBufferAddress()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:54
void RelayUpdate(uint8_t RelayId, String &NewValue, String &Response)
Definition OutputMgr.cpp:1455
void Poll()
Call from loop(), renders output data.
Definition OutputMgr.cpp:1351
bool HasBeenInitialized
Definition OutputMgr.hpp:238
bool OutputIsPaused
Definition OutputMgr.hpp:241
Definition OutputMgr.hpp:216
gpio_num_t GpioPin
Definition OutputMgr.hpp:226
bool OutputDriverInUse
Definition OutputMgr.hpp:230
OM_PortType_t PortType
Definition OutputMgr.hpp:227
uint32_t OutputChannelSize
Definition OutputMgr.hpp:223
byte OutputDriver[OutputDriverMemorySize]
Definition OutputMgr.hpp:217
uint32_t OutputChannelEndOffset
Definition OutputMgr.hpp:224
uint32_t OutputBufferStartingOffset
Definition OutputMgr.hpp:218
uint32_t OutputBufferDataSize
Definition OutputMgr.hpp:219
uint32_t OutputBufferEndOffset
Definition OutputMgr.hpp:220
uart_port_t PortId
Definition OutputMgr.hpp:228
e_OutputChannelIds DriverId
Definition OutputMgr.hpp:229
uint32_t OutputChannelStartingOffset
Definition OutputMgr.hpp:222