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, 2026 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 "OutputMgrPortDefs.hpp"
27#include "memdebug.h"
28#include "FileMgr.hpp"
29#include <TimeLib.h>
30
31class c_OutputCommon;
32
33#ifdef UART_LAST
34# define NUM_UARTS UART_LAST
35#else
36# define NUM_UARTS 0
37#endif
38
40{
41private:
42 #ifdef ARDUINO_ARCH_ESP8266
43 #define OM_MAX_NUM_CHANNELS (1200 * 3)
44 #else // ARDUINO_ARCH_ESP32
45 #define OM_MAX_NUM_CHANNELS (3000 * 3)
46 #endif // !def ARDUINO_ARCH_ESP32
47
48public:
49 c_OutputMgr ();
50 virtual ~c_OutputMgr ();
51
52 void Begin ();
53 void Poll ();
55 void LoadConfig ();
56 void GetConfig (byte * Response, uint32_t maxlen);
57 void GetConfig (String & Response);
58 void SetConfig (const char * NewConfig);
59 void SetConfig (ArduinoJson::JsonDocument & NewConfig);
60 void GetStatus (JsonObject & jsonStatus);
61// void GetPortCounts (uint16_t& PixelCount, uint16_t& SerialCount) {PixelCount = uint16_t(OutputPortId_End); SerialCount = uint16_t(NUM_UARTS); }
62 uint8_t* GetBufferAddress () { return pOutputBuffer; }
63 uint32_t GetBufferUsedSize () { return UsedBufferSize; }
64 uint32_t GetBufferSize () { return uint32_t(OM_MAX_NUM_CHANNELS); }
66 void PauseOutputs (bool NewState);
67 void GetDriverName (String & Name) { Name = "OutputMgr"; }
68 void WriteChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t * pData);
69 void ReadChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData);
70 void ClearBuffer ();
71 void TaskPoll ();
72 void RelayUpdate (uint8_t RelayId, String & NewValue, String & Response);
73 void ClearStatistics (void);
74 uint8_t GetNumPorts () {return NumOutputPorts;}
75
76 // do NOT insert into the middle of this list. Always add new types to the end of the list
78 {
80
81 #ifdef SUPPORT_OutputProtocol_WS2811
82 OutputProtocol_WS2811 = 1,
83 #endif // def SUPPORT_OutputProtocol_WS2811
84
85 #ifdef SUPPORT_OutputProtocol_GECE
86 OutputProtocol_GECE = 2,
87 #endif // def SUPPORT_OutputProtocol_GECE
88
89 #ifdef SUPPORT_OutputProtocol_DMX
90 OutputProtocol_DMX = 3,
91 #endif // def SUPPORT_OutputProtocol_DMX
92
93 #ifdef SUPPORT_OutputProtocol_Renard
94 OutputProtocol_Renard = 4,
95 #endif // def SUPPORT_OutputProtocol_Renard
96
97 #ifdef SUPPORT_OutputProtocol_Serial
98 OutputProtocol_Serial = 5,
99 #endif // def SUPPORT_OutputProtocol_Serial
100
101 #ifdef SUPPORT_OutputProtocol_Relay
102 OutputProtocol_Relay = 6,
103 #endif // def SUPPORT_OutputProtocol_Relay
104
105 #ifdef SUPPORT_OutputProtocol_Servo_PCA9685
106 OutputProtocol_Servo_PCA9685 = 7,
107 #endif // def SUPPORT_OutputProtocol_Servo_PCA9685
108
109 #ifdef SUPPORT_OutputProtocol_UCS1903
110 OutputProtocol_UCS1903 = 8,
111 #endif // def SUPPORT_OutputProtocol_UCS1903
112
113 #ifdef SUPPORT_OutputProtocol_TM1814
114 OutputProtocol_TM1814 = 9,
115 #endif // def SUPPORT_OutputProtocol_TM1814
116
117 #ifdef SUPPORT_OutputProtocol_WS2801
118 OutputProtocol_WS2801 = 10,
119 #endif // def SUPPORT_OutputProtocol_WS2801
120
121 #ifdef SUPPORT_OutputProtocol_APA102
122 OutputProtocol_APA102 = 11,
123 #endif // def SUPPORT_OutputProtocol_APA102
124
125 #ifdef SUPPORT_OutputProtocol_GS8208
126 OutputProtocol_GS8208 = 12,
127 #endif // def SUPPORT_OutputProtocol_GS8208
128
129 #ifdef SUPPORT_OutputProtocol_UCS8903
130 OutputProtocol_UCS8903 = 13,
131 #endif // def SUPPORT_OutputProtocol_UCS8903
132
133 #ifdef SUPPORT_OutputProtocol_TLS3001
134 OutputType_TLS3001 = 14,
135 #endif // def SUPPORT_OutputProtocol_TLS3001
136
137 #ifdef SUPPORT_OutputProtocol_GRINCH
138 OutputProtocol_GRINCH = 15,
139 #endif // def SUPPORT_OutputProtocol_GRINCH
140
141 #ifdef SUPPORT_OutputProtocol_FireGod
142 OutputProtocol_FireGod = 16,
143 #endif // def SUPPORT_OutputProtocol_FireGod
144
145 // Add new types here
146 };
147 uint32_t OutputType_End = uint32_t(-1);
148
149 // must be 16 byte aligned. Determined by upshifting the max size of all drivers
150 #define OutputDriverMemorySize 1200
152private:
168
169 // pointer(s) to the current active output drivers
171 uint8_t NumOutputPorts = 0;
172 uint32_t SizeOfTable = 0;
173
174 // configuration parameter names for the channel manager within the config file
175 #define NO_CONFIG_NEEDED time_t(-1)
176 bool HasBeenInitialized = false;
178 bool ConfigInProgress = false;
179 bool OutputIsPaused = false;
180 bool BuildingNewConfig = false;
181
182 bool ProcessJsonConfig (JsonDocument & jsonConfig);
183 void CreateJsonConfig (JsonObject & jsonConfig);
185 void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputProtocolType NewChannelType, bool StartDriver = true);
186 void CreateNewConfig();
187 void SetSerialUart();
188 bool FindJsonChannelConfig (JsonDocument& jsonConfig, OM_PortId_t PortId, e_OutputProtocolType Type, JsonObject& ChanConfig);
189 bool SetPortDefnitionDefaults(DriverInfo_t & CurrentOutput, e_OutputProtocolType TargetProtocolType);
190
192
193 uint8_t *pOutputBuffer = nullptr;
194 uint32_t UsedBufferSize = 0;
195
196 #ifndef DEFAULT_CONSOLE_TX_GPIO
197 #define DEFAULT_CONSOLE_TX_GPIO gpio_num_t::GPIO_NUM_1
198 #define DEFAULT_CONSOLE_RX_GPIO gpio_num_t::GPIO_NUM_3
199 #endif // ndef DEFAULT_CONSOLE_TX_GPIO
200
203
204#if defined(ARDUINO_ARCH_ESP32)
205 TaskHandle_t myTaskHandle = NULL;
206 // uint32_t PollCount = 0;
207#endif // defined(ARDUINO_ARCH_ESP32)
208
209}; // c_OutputMgr
210
c_FileMgr FileMgr
Definition FileMgr.cpp:2531
#define OM_MAX_NUM_CHANNELS
Definition OutputMgr.hpp:45
#define DEFAULT_CONSOLE_RX_GPIO
Definition OutputMgr.hpp:198
#define NO_CONFIG_NEEDED
Definition OutputMgr.hpp:175
#define DEFAULT_CONSOLE_TX_GPIO
Definition OutputMgr.hpp:197
#define OutputDriverMemorySize
Definition OutputMgr.hpp:150
c_OutputMgr OutputMgr
Definition OutputMgr.cpp:1705
uint8_t OM_PortId_t
Definition OutputMgrPortDefs.hpp:71
void DeleteFlashFile(String FileName)
Definition FileMgr.cpp:646
Definition OutputCommon.hpp:32
Definition OutputMgr.hpp:40
uint8_t * pOutputBuffer
Definition OutputMgr.hpp:193
uint32_t SizeOfTable
Definition OutputMgr.hpp:172
void GetDriverName(String &Name)
Definition OutputMgr.hpp:67
void LoadConfig()
Read the current configuration data from nvram.
Definition OutputMgr.cpp:1087
void CreateJsonConfig(JsonObject &jsonConfig)
Definition OutputMgr.cpp:295
gpio_num_t ConsoleRxGpio
Definition OutputMgr.hpp:202
void UpdateDisplayBufferReferences(void)
Definition OutputMgr.cpp:1451
void TaskPoll()
bool ProcessJsonConfig(JsonDocument &jsonConfig)
Definition OutputMgr.cpp:1218
bool FindJsonChannelConfig(JsonDocument &jsonConfig, OM_PortId_t PortId, e_OutputProtocolType Type, JsonObject &ChanConfig)
Definition OutputMgr.cpp:1126
c_OutputMgr()
< Start up the driver and put it into a safe mode
Definition OutputMgr.cpp:156
void ClearStatistics(void)
Definition OutputMgr.cpp:523
e_OutputProtocolType
Definition OutputMgr.hpp:78
@ OutputProtocol_Disabled
Definition OutputMgr.hpp:79
void GetConfig(byte *Response, uint32_t maxlen)
Definition OutputMgr.cpp:490
virtual ~c_OutputMgr()
< deallocate any resources and put the output channels into a safe state
Definition OutputMgr.cpp:201
uint32_t UsedBufferSize
Definition OutputMgr.hpp:194
void GetStatus(JsonObject &jsonStatus)
Definition OutputMgr.cpp:501
uint8_t NumOutputPorts
Definition OutputMgr.hpp:171
bool SetPortDefnitionDefaults(DriverInfo_t &CurrentOutput, e_OutputProtocolType TargetProtocolType)
Definition OutputMgr.cpp:995
void SetConfig(const char *NewConfig)
Save the current configuration data to nvram.
Definition OutputMgr.cpp:1322
void DeleteConfig()
Definition OutputMgr.hpp:65
void ClearBuffer()
Definition OutputMgr.cpp:1694
bool BuildingNewConfig
Definition OutputMgr.hpp:180
void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputProtocolType NewChannelType, bool StartDriver=true)
Definition OutputMgr.cpp:555
time_t ConfigLoadNeeded
Definition OutputMgr.hpp:177
uint8_t GetNumPorts()
Definition OutputMgr.hpp:74
bool ConfigInProgress
Definition OutputMgr.hpp:178
void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputMgr.cpp:218
void SetSerialUart()
Definition OutputMgr.cpp:1371
uint32_t GetBufferUsedSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:63
uint32_t GetDriverSize()
Definition OutputMgr.hpp:151
void PauseOutputs(bool NewState)
Definition OutputMgr.cpp:1551
DriverInfo_t * pOutputChannelDrivers
Definition OutputMgr.hpp:170
uint32_t OutputType_End
Definition OutputMgr.hpp:147
uint32_t GetBufferSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:64
void WriteChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pData)
Definition OutputMgr.cpp:1568
gpio_num_t ConsoleTxGpio
Definition OutputMgr.hpp:201
void ScheduleLoadConfig()
Definition OutputMgr.hpp:54
void CreateNewConfig()
Definition OutputMgr.cpp:376
void ReadChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData)
Definition OutputMgr.cpp:1633
String ConfigFileName
Definition OutputMgr.hpp:191
uint8_t * GetBufferAddress()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:62
void RelayUpdate(uint8_t RelayId, String &NewValue, String &Response)
Definition OutputMgr.cpp:1523
void Poll()
Call from loop(), renders output data.
Definition OutputMgr.cpp:1417
bool HasBeenInitialized
Definition OutputMgr.hpp:176
bool OutputIsPaused
Definition OutputMgr.hpp:179
Definition OutputMgrPortDefs.hpp:90
Definition OutputMgr.hpp:154
uint8_t DriverId
Definition OutputMgr.hpp:165
bool OutputDriverInUse
Definition OutputMgr.hpp:166
uint32_t OutputChannelSize
Definition OutputMgr.hpp:161
byte OutputDriver[OutputDriverMemorySize]
Definition OutputMgr.hpp:155
OM_OutputPortDefinition_t PortDefinition
Definition OutputMgr.hpp:164
uint32_t OutputChannelEndOffset
Definition OutputMgr.hpp:162
uint32_t OutputBufferStartingOffset
Definition OutputMgr.hpp:156
uint32_t OutputBufferDataSize
Definition OutputMgr.hpp:157
uint32_t OutputBufferEndOffset
Definition OutputMgr.hpp:158
uint32_t OutputChannelStartingOffset
Definition OutputMgr.hpp:160