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
66 // handles to determine which output channel we are dealing with
68 {
69 #ifdef DEFAULT_UART_0_GPIO
70 OutputChannelId_UART_0,
71 #endif // def DEFAULT_UART_0_GPIO
72
73 #ifdef DEFAULT_UART_1_GPIO
74 OutputChannelId_UART_1,
75 #endif // def DEFAULT_UART_1_GPIO
76
77 #ifdef DEFAULT_UART_2_GPIO
78 OutputChannelId_UART_2,
79 #endif // def DEFAULT_UART_2_GPIO
80
81 #ifdef DEFAULT_RMT_0_GPIO
82 OutputChannelId_RMT_0,
83 #endif // def DEFAULT_RMT_0_GPIO
84
85 #ifdef DEFAULT_RMT_1_GPIO
86 OutputChannelId_RMT_1,
87 #endif // def DEFAULT_RMT_1_GPIO
88
89 #ifdef DEFAULT_RMT_2_GPIO
90 OutputChannelId_RMT_2,
91 #endif // def DEFAULT_RMT_2_GPIO
92
93 #ifdef DEFAULT_RMT_3_GPIO
94 OutputChannelId_RMT_3,
95 #endif // def DEFAULT_RMT_3_GPIO
96
97 #ifdef DEFAULT_RMT_4_GPIO
98 OutputChannelId_RMT_4,
99 #endif // def DEFAULT_RMT_3_GPIO
100
101 #ifdef DEFAULT_RMT_5_GPIO
102 OutputChannelId_RMT_5,
103 #endif // def DEFAULT_RMT_3_GPIO
104
105 #ifdef DEFAULT_RMT_6_GPIO
106 OutputChannelId_RMT_6,
107 #endif // def DEFAULT_RMT_3_GPIO
108
109 #ifdef DEFAULT_RMT_7_GPIO
110 OutputChannelId_RMT_7,
111 #endif // def DEFAULT_RMT_3_GPIO
112
113 #ifdef SUPPORT_SPI_OUTPUT
114 OutputChannelId_SPI_1,
115 #endif // def SUPPORT_SPI_OUTPUT
116
117 #if defined(SUPPORT_OutputType_Relay) || defined(SUPPORT_OutputType_Servo_PCA9685)
118 OutputChannelId_Relay,
119 #endif // def SUPPORT_RELAY_OUTPUT
120
121 OutputChannelId_End, // must be last in the list
123 };
124
125 // do NOT insert into the middle of this list. Always add new types to the end of the list
127 {
129
130 #ifdef SUPPORT_OutputType_WS2811
131 OutputType_WS2811 = 1,
132 #endif // def SUPPORT_OutputType_WS2811
133
134 #ifdef SUPPORT_OutputType_GECE
135 OutputType_GECE = 2,
136 #endif // def SUPPORT_OutputType_GECE
137
138 #ifdef SUPPORT_OutputType_DMX
139 OutputType_DMX = 3,
140 #endif // def SUPPORT_OutputType_DMX
141
142 #ifdef SUPPORT_OutputType_Renard
143 OutputType_Renard = 4,
144 #endif // def SUPPORT_OutputType_Renard
145
146 #ifdef SUPPORT_OutputType_Serial
147 OutputType_Serial = 5,
148 #endif // def SUPPORT_OutputType_Serial
149
150 #ifdef SUPPORT_OutputType_Relay
151 OutputType_Relay = 6,
152 #endif // def SUPPORT_OutputType_Relay
153
154 #ifdef SUPPORT_OutputType_Servo_PCA9685
155 OutputType_Servo_PCA9685 = 7,
156 #endif // def SUPPORT_OutputType_Servo_PCA9685
157
158 #ifdef SUPPORT_OutputType_UCS1903
159 OutputType_UCS1903 = 8,
160 #endif // def SUPPORT_OutputType_UCS1903
161
162 #ifdef SUPPORT_OutputType_TM1814
163 OutputType_TM1814 = 9,
164 #endif // def SUPPORT_OutputType_TM1814
165
166 #ifdef SUPPORT_OutputType_WS2801
167 OutputType_WS2801 = 10,
168 #endif // def SUPPORT_OutputType_WS2801
169
170 #ifdef SUPPORT_OutputType_APA102
171 OutputType_APA102 = 11,
172 #endif // def SUPPORT_OutputType_APA102
173
174 #ifdef SUPPORT_OutputType_GS8208
175 OutputType_GS8208 = 12,
176 #endif // def SUPPORT_OutputType_GS8208
177
178 #ifdef SUPPORT_OutputType_UCS8903
179 OutputType_UCS8903 = 13,
180 #endif // def SUPPORT_OutputType_UCS8903
181
182 #ifdef SUPPORT_OutputType_TLS3001
183 OutputType_TLS3001 = 14,
184 #endif // def SUPPORT_OutputType_TLS3001
185
186 #ifdef SUPPORT_OutputType_GRINCH
187 OutputType_GRINCH = 15,
188 #endif // def SUPPORT_OutputType_GRINCH
189
190 // Add new types here
191 OutputType_End, // must be last
193 };
194
195#ifdef ARDUINO_ARCH_ESP8266
196# define OM_MAX_NUM_CHANNELS (1200 * 3)
197#else // ARDUINO_ARCH_ESP32
198# define OM_MAX_NUM_CHANNELS (3000 * 3)
199#endif // !def ARDUINO_ARCH_ESP32
200
209
210private:
227
228 // pointer(s) to the current active output drivers
230
231 // configuration parameter names for the channel manager within the config file
232 #define NO_CONFIG_NEEDED time_t(-1)
233 bool HasBeenInitialized = false;
235 bool ConfigInProgress = false;
236 bool OutputIsPaused = false;
237 bool BuildingNewConfig = false;
238
239 bool ProcessJsonConfig (JsonDocument & jsonConfig);
240 void CreateJsonConfig (JsonObject & jsonConfig);
242 void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver = true);
243 void CreateNewConfig();
244 void SetSerialUart();
245 bool FindJsonChannelConfig (JsonDocument& jsonConfig, e_OutputChannelIds ChanId, e_OutputType Type, JsonObject& ChanConfig);
246
248
250 uint32_t UsedBufferSize = 0;
251 gpio_num_t ConsoleTxGpio = gpio_num_t::GPIO_NUM_1;
252 gpio_num_t ConsoleRxGpio = gpio_num_t::GPIO_NUM_3;
253#if defined(ARDUINO_ARCH_ESP32)
254 TaskHandle_t myTaskHandle = NULL;
255 // uint32_t PollCount = 0;
256#endif // defined(ARDUINO_ARCH_ESP32)
257
258#define OM_IS_UART (CurrentOutput.PortType == OM_PortType_t::Uart)
259#define OM_IS_RMT (CurrentOutput.PortType == OM_PortType_t::Rmt)
260
261}; // c_OutputMgr
262
c_FileMgr FileMgr
Definition FileMgr.cpp:2180
#define OM_MAX_NUM_CHANNELS
Definition OutputMgr.hpp:198
#define NO_CONFIG_NEEDED
Definition OutputMgr.hpp:232
#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:1601
void DeleteFlashFile(const String &FileName)
Definition FileMgr.cpp:563
Definition OutputCommon.hpp:31
Definition OutputMgr.hpp:39
e_OutputChannelIds
Definition OutputMgr.hpp:68
@ OutputChannelId_End
Definition OutputMgr.hpp:121
@ OutputChannelId_Start
Definition OutputMgr.hpp:122
e_OutputType
Definition OutputMgr.hpp:127
@ OutputType_Disabled
Definition OutputMgr.hpp:128
@ OutputType_Start
Definition OutputMgr.hpp:192
@ OutputType_End
Definition OutputMgr.hpp:191
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:252
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:250
void GetStatus(JsonObject &jsonStatus)
Definition OutputMgr.cpp:463
uint8_t OutputBuffer[OM_MAX_NUM_CHANNELS]
Definition OutputMgr.hpp:249
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:1590
void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver=true)
Definition OutputMgr.cpp:496
bool BuildingNewConfig
Definition OutputMgr.hpp:237
time_t ConfigLoadNeeded
Definition OutputMgr.hpp:234
bool ConfigInProgress
Definition OutputMgr.hpp:235
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:202
@ Uart
Definition OutputMgr.hpp:203
@ Undefined
Definition OutputMgr.hpp:207
@ Spi
Definition OutputMgr.hpp:205
@ Relay
Definition OutputMgr.hpp:206
@ Rmt
Definition OutputMgr.hpp:204
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:1450
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:1466
gpio_num_t ConsoleTxGpio
Definition OutputMgr.hpp:251
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:1530
String ConfigFileName
Definition OutputMgr.hpp:247
DriverInfo_t OutputChannelDrivers[OutputChannelId_End]
Definition OutputMgr.hpp:229
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:1423
void Poll()
Call from loop(), renders output data.
Definition OutputMgr.cpp:1319
bool HasBeenInitialized
Definition OutputMgr.hpp:233
bool OutputIsPaused
Definition OutputMgr.hpp:236
Definition OutputMgr.hpp:212
gpio_num_t GpioPin
Definition OutputMgr.hpp:221
c_OutputCommon * pOutputChannelDriver
Definition OutputMgr.hpp:225
OM_PortType_t PortType
Definition OutputMgr.hpp:222
uint32_t OutputChannelSize
Definition OutputMgr.hpp:218
uint32_t OutputChannelEndOffset
Definition OutputMgr.hpp:219
uint32_t OutputBufferStartingOffset
Definition OutputMgr.hpp:213
uint32_t OutputBufferDataSize
Definition OutputMgr.hpp:214
uint32_t OutputBufferEndOffset
Definition OutputMgr.hpp:215
uart_port_t PortId
Definition OutputMgr.hpp:223
e_OutputChannelIds DriverId
Definition OutputMgr.hpp:224
uint32_t OutputChannelStartingOffset
Definition OutputMgr.hpp:217