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
31#ifdef SUPPORT_I2S
32 #include "output/OutputI2S.hpp"
33#endif // def SUPPORT_I2S
34
35class c_OutputCommon;
36
37#ifdef UART_LAST
38# define NUM_UARTS UART_LAST
39#else
40# define NUM_UARTS 0
41#endif
42
44{
45private:
46 #ifdef ARDUINO_ARCH_ESP8266
47 #define OM_MAX_NUM_CHANNELS (1200 * 3)
48 #else // ARDUINO_ARCH_ESP32
49 #define OM_MAX_NUM_CHANNELS (3000 * 3)
50 #endif // !def ARDUINO_ARCH_ESP32
51#ifdef SUPPORT_I2S
52 c_OutputI2S OutputI2S;
53#endif // def SUPPORT_I2S
54
55public:
56 c_OutputMgr ();
57 virtual ~c_OutputMgr ();
58
59 void Begin ();
60 void Poll ();
62 void LoadConfig ();
63 void GetConfig (byte * Response, uint32_t maxlen);
64 void GetConfig (String & Response);
65 void SetConfig (const char * NewConfig);
66 void SetConfig (ArduinoJson::JsonDocument & NewConfig);
67 void GetStatus (JsonObject & jsonStatus);
68 IRAM_ATTR uint8_t * ISR_GetBufferAddress () { return pOutputBuffer; }
69 uint32_t GetBufferUsedSize () { return UsedBufferSize; }
70 uint32_t GetBufferSize () { return uint32_t(OM_MAX_NUM_CHANNELS); }
72 void PauseOutputs (bool NewState);
73 void GetDriverName (String & Name) { Name = "OutputMgr"; }
74 void WriteChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t * pData);
75 void ReadChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData);
76 void ClearBuffer ();
77 void TaskPoll ();
78 void RelayUpdate (uint8_t RelayId, String & NewValue, String & Response);
79 void ClearStatistics (void);
80 uint8_t GetNumPorts () {return NumOutputPorts;}
81 #ifdef SUPPORT_I2S
82 c_OutputI2S * GetI2sDriver () {return &OutputI2S;}
83 #endif // def SUPPORT_I2S
84
85// do NOT insert into the middle of this list. Always add new types to the end of the list
87 {
89
90 #ifdef SUPPORT_OutputProtocol_WS2811
91 OutputProtocol_WS2811 = 1,
92 #endif // def SUPPORT_OutputProtocol_WS2811
93
94 #ifdef SUPPORT_OutputProtocol_GECE
95 OutputProtocol_GECE = 2,
96 #endif // def SUPPORT_OutputProtocol_GECE
97
98 #ifdef SUPPORT_OutputProtocol_DMX
99 OutputProtocol_DMX = 3,
100 #endif // def SUPPORT_OutputProtocol_DMX
101
102 #ifdef SUPPORT_OutputProtocol_Renard
103 OutputProtocol_Renard = 4,
104 #endif // def SUPPORT_OutputProtocol_Renard
105
106 #ifdef SUPPORT_OutputProtocol_Serial
107 OutputProtocol_Serial = 5,
108 #endif // def SUPPORT_OutputProtocol_Serial
109
110 #ifdef SUPPORT_OutputProtocol_Relay
111 OutputProtocol_Relay = 6,
112 #endif // def SUPPORT_OutputProtocol_Relay
113
114 #ifdef SUPPORT_OutputProtocol_Servo_PCA9685
115 OutputProtocol_Servo_PCA9685 = 7,
116 #endif // def SUPPORT_OutputProtocol_Servo_PCA9685
117
118 #ifdef SUPPORT_OutputProtocol_UCS1903
119 OutputProtocol_UCS1903 = 8,
120 #endif // def SUPPORT_OutputProtocol_UCS1903
121
122 #ifdef SUPPORT_OutputProtocol_TM1814
123 OutputProtocol_TM1814 = 9,
124 #endif // def SUPPORT_OutputProtocol_TM1814
125
126 #ifdef SUPPORT_OutputProtocol_WS2801
127 OutputProtocol_WS2801 = 10,
128 #endif // def SUPPORT_OutputProtocol_WS2801
129
130 #ifdef SUPPORT_OutputProtocol_APA102
131 OutputProtocol_APA102 = 11,
132 #endif // def SUPPORT_OutputProtocol_APA102
133
134 #ifdef SUPPORT_OutputProtocol_GS8208
135 OutputProtocol_GS8208 = 12,
136 #endif // def SUPPORT_OutputProtocol_GS8208
137
138 #ifdef SUPPORT_OutputProtocol_UCS8903
139 OutputProtocol_UCS8903 = 13,
140 #endif // def SUPPORT_OutputProtocol_UCS8903
141
142 #ifdef SUPPORT_OutputProtocol_TLS3001
143 OutputProtocol_TLS3001 = 14,
144 #endif // def SUPPORT_OutputProtocol_TLS3001
145
146 #ifdef SUPPORT_OutputProtocol_GRINCH
147 OutputProtocol_GRINCH = 15,
148 #endif // def SUPPORT_OutputProtocol_GRINCH
149
150 #ifdef SUPPORT_OutputProtocol_FireGod
151 OutputProtocol_FireGod = 16,
152 #endif // def SUPPORT_OutputProtocol_FireGod
153
154 // Add new types here
155
156 // Must be last
158 };
159 uint32_t NumberOfOutputProtocols = uint32_t(0);
160
161private:
162
163 // pointer(s) to the current active output drivers
165
166 // configuration parameter names for the channel manager within the config file
167 #define NO_CONFIG_NEEDED time_t(-1)
168 bool HasBeenInitialized = false;
170 bool ConfigInProgress = false;
171 bool OutputIsPaused = false;
172 bool BuildingNewConfig = false;
173
174 bool ProcessJsonConfig (JsonDocument & jsonConfig);
175 void CreateJsonConfig (JsonObject & jsonConfig);
177 void InstantiateNewOutputChannel(uint32_t PortIndex, e_OutputProtocolType NewChannelType, bool StartDriver = true);
178 void CreateNewConfig();
179 void SetSerialUart();
180 bool FindJsonChannelConfig (JsonDocument& jsonConfig, OM_PortId_t PortId, JsonObject& ChanConfig);
181 bool SetPortDefnitionDefaults(uint32_t PortIndex, e_OutputProtocolType TargetProtocolType);
182
184
185 uint8_t *pOutputBuffer = nullptr;
186 uint32_t UsedBufferSize = 0;
187
188 #ifndef DEFAULT_CONSOLE_TX_GPIO
189 #define DEFAULT_CONSOLE_TX_GPIO gpio_num_t::GPIO_NUM_1
190 #define DEFAULT_CONSOLE_RX_GPIO gpio_num_t::GPIO_NUM_3
191 #endif // ndef DEFAULT_CONSOLE_TX_GPIO
192
195
196#if defined(ARDUINO_ARCH_ESP32)
197 TaskHandle_t myTaskHandle = NULL;
198 // uint32_t PollCount = 0;
199#endif // defined(ARDUINO_ARCH_ESP32)
200
201}; // c_OutputMgr
202
c_FileMgr FileMgr
Definition FileMgr.cpp:2531
#define OM_MAX_NUM_CHANNELS
Definition OutputMgr.hpp:49
#define DEFAULT_CONSOLE_RX_GPIO
Definition OutputMgr.hpp:190
#define NO_CONFIG_NEEDED
Definition OutputMgr.hpp:167
#define DEFAULT_CONSOLE_TX_GPIO
Definition OutputMgr.hpp:189
c_OutputMgr OutputMgr
Definition OutputMgr.cpp:1832
uint8_t OM_PortId_t
Definition OutputMgrPortDefs.hpp:71
void DeleteFlashFile(String FileName)
Definition FileMgr.cpp:646
Definition OutputCommon.hpp:32
Definition OutputMgr.hpp:44
uint32_t NumberOfOutputProtocols
Definition OutputMgr.hpp:159
uint8_t * pOutputBuffer
Definition OutputMgr.hpp:185
void GetDriverName(String &Name)
Definition OutputMgr.hpp:73
void LoadConfig()
Read the current configuration data from nvram.
Definition OutputMgr.cpp:1211
void CreateJsonConfig(JsonObject &jsonConfig)
Definition OutputMgr.cpp:400
gpio_num_t ConsoleRxGpio
Definition OutputMgr.hpp:194
void UpdateDisplayBufferReferences(void)
Definition OutputMgr.cpp:1575
void TaskPoll()
bool ProcessJsonConfig(JsonDocument &jsonConfig)
Definition OutputMgr.cpp:1341
c_OutputMgr()
< Start up the driver and put it into a safe mode
Definition OutputMgr.cpp:248
void ClearStatistics(void)
Definition OutputMgr.cpp:627
e_OutputProtocolType
Definition OutputMgr.hpp:87
@ OutputProtocol_Disabled
Definition OutputMgr.hpp:88
@ OutputProtocol_Last
Definition OutputMgr.hpp:157
void GetConfig(byte *Response, uint32_t maxlen)
Definition OutputMgr.cpp:594
virtual ~c_OutputMgr()
< deallocate any resources and put the output channels into a safe state
Definition OutputMgr.cpp:303
uint32_t UsedBufferSize
Definition OutputMgr.hpp:186
void GetStatus(JsonObject &jsonStatus)
Definition OutputMgr.cpp:605
uint8_t NumOutputPorts
Definition OutputMgr.hpp:164
void SetConfig(const char *NewConfig)
Save the current configuration data to nvram.
Definition OutputMgr.cpp:1446
void InstantiateNewOutputChannel(uint32_t PortIndex, e_OutputProtocolType NewChannelType, bool StartDriver=true)
Definition OutputMgr.cpp:655
void DeleteConfig()
Definition OutputMgr.hpp:71
IRAM_ATTR uint8_t * ISR_GetBufferAddress()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:68
void ClearBuffer()
Definition OutputMgr.cpp:1821
bool BuildingNewConfig
Definition OutputMgr.hpp:172
time_t ConfigLoadNeeded
Definition OutputMgr.hpp:169
bool SetPortDefnitionDefaults(uint32_t PortIndex, e_OutputProtocolType TargetProtocolType)
Definition OutputMgr.cpp:1118
uint8_t GetNumPorts()
Definition OutputMgr.hpp:80
bool ConfigInProgress
Definition OutputMgr.hpp:170
void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputMgr.cpp:321
void SetSerialUart()
Definition OutputMgr.cpp:1495
uint32_t GetBufferUsedSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:69
void PauseOutputs(bool NewState)
Definition OutputMgr.cpp:1678
uint32_t GetBufferSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:70
void WriteChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pData)
Definition OutputMgr.cpp:1695
gpio_num_t ConsoleTxGpio
Definition OutputMgr.hpp:193
void ScheduleLoadConfig()
Definition OutputMgr.hpp:61
void CreateNewConfig()
Definition OutputMgr.cpp:481
bool FindJsonChannelConfig(JsonDocument &jsonConfig, OM_PortId_t PortId, JsonObject &ChanConfig)
Definition OutputMgr.cpp:1250
void ReadChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData)
Definition OutputMgr.cpp:1760
String ConfigFileName
Definition OutputMgr.hpp:183
void RelayUpdate(uint8_t RelayId, String &NewValue, String &Response)
Definition OutputMgr.cpp:1647
void Poll()
Call from loop(), renders output data.
Definition OutputMgr.cpp:1541
bool HasBeenInitialized
Definition OutputMgr.hpp:168
bool OutputIsPaused
Definition OutputMgr.hpp:171