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 uint8_t* GetBufferAddress () { return pOutputBuffer; }
62 uint32_t GetBufferUsedSize () { return UsedBufferSize; }
63 uint32_t GetBufferSize () { return uint32_t(OM_MAX_NUM_CHANNELS); }
65 void PauseOutputs (bool NewState);
66 void GetDriverName (String & Name) { Name = "OutputMgr"; }
67 void WriteChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t * pData);
68 void ReadChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData);
69 void ClearBuffer ();
70 void TaskPoll ();
71 void RelayUpdate (uint8_t RelayId, String & NewValue, String & Response);
72 void ClearStatistics (void);
73 uint8_t GetNumPorts () {return NumOutputPorts;}
74
75 // do NOT insert into the middle of this list. Always add new types to the end of the list
77 {
79
80 #ifdef SUPPORT_OutputProtocol_WS2811
81 OutputProtocol_WS2811 = 1,
82 #endif // def SUPPORT_OutputProtocol_WS2811
83
84 #ifdef SUPPORT_OutputProtocol_GECE
85 OutputProtocol_GECE = 2,
86 #endif // def SUPPORT_OutputProtocol_GECE
87
88 #ifdef SUPPORT_OutputProtocol_DMX
89 OutputProtocol_DMX = 3,
90 #endif // def SUPPORT_OutputProtocol_DMX
91
92 #ifdef SUPPORT_OutputProtocol_Renard
93 OutputProtocol_Renard = 4,
94 #endif // def SUPPORT_OutputProtocol_Renard
95
96 #ifdef SUPPORT_OutputProtocol_Serial
97 OutputProtocol_Serial = 5,
98 #endif // def SUPPORT_OutputProtocol_Serial
99
100 #ifdef SUPPORT_OutputProtocol_Relay
101 OutputProtocol_Relay = 6,
102 #endif // def SUPPORT_OutputProtocol_Relay
103
104 #ifdef SUPPORT_OutputProtocol_Servo_PCA9685
105 OutputProtocol_Servo_PCA9685 = 7,
106 #endif // def SUPPORT_OutputProtocol_Servo_PCA9685
107
108 #ifdef SUPPORT_OutputProtocol_UCS1903
109 OutputProtocol_UCS1903 = 8,
110 #endif // def SUPPORT_OutputProtocol_UCS1903
111
112 #ifdef SUPPORT_OutputProtocol_TM1814
113 OutputProtocol_TM1814 = 9,
114 #endif // def SUPPORT_OutputProtocol_TM1814
115
116 #ifdef SUPPORT_OutputProtocol_WS2801
117 OutputProtocol_WS2801 = 10,
118 #endif // def SUPPORT_OutputProtocol_WS2801
119
120 #ifdef SUPPORT_OutputProtocol_APA102
121 OutputProtocol_APA102 = 11,
122 #endif // def SUPPORT_OutputProtocol_APA102
123
124 #ifdef SUPPORT_OutputProtocol_GS8208
125 OutputProtocol_GS8208 = 12,
126 #endif // def SUPPORT_OutputProtocol_GS8208
127
128 #ifdef SUPPORT_OutputProtocol_UCS8903
129 OutputProtocol_UCS8903 = 13,
130 #endif // def SUPPORT_OutputProtocol_UCS8903
131
132 #ifdef SUPPORT_OutputProtocol_TLS3001
133 OutputProtocol_TLS3001 = 14,
134 #endif // def SUPPORT_OutputProtocol_TLS3001
135
136 #ifdef SUPPORT_OutputProtocol_GRINCH
137 OutputProtocol_GRINCH = 15,
138 #endif // def SUPPORT_OutputProtocol_GRINCH
139
140 #ifdef SUPPORT_OutputProtocol_FireGod
141 OutputProtocol_FireGod = 16,
142 #endif // def SUPPORT_OutputProtocol_FireGod
143
144 // Add new types here
145
146 // Must be last
148 };
149 uint32_t NumberOfOutputProtocols = uint32_t(0);
150
151private:
152
153 // pointer(s) to the current active output drivers
155
156 // configuration parameter names for the channel manager within the config file
157 #define NO_CONFIG_NEEDED time_t(-1)
158 bool HasBeenInitialized = false;
160 bool ConfigInProgress = false;
161 bool OutputIsPaused = false;
162 bool BuildingNewConfig = false;
163
164 bool ProcessJsonConfig (JsonDocument & jsonConfig);
165 void CreateJsonConfig (JsonObject & jsonConfig);
167 void InstantiateNewOutputChannel(uint32_t PortIndex, e_OutputProtocolType NewChannelType, bool StartDriver = true);
168 void CreateNewConfig();
169 void SetSerialUart();
170 bool FindJsonChannelConfig (JsonDocument& jsonConfig, OM_PortId_t PortId, JsonObject& ChanConfig);
171 bool SetPortDefnitionDefaults(uint32_t PortIndex, e_OutputProtocolType TargetProtocolType);
172
174
175 uint8_t *pOutputBuffer = nullptr;
176 uint32_t UsedBufferSize = 0;
177
178 #ifndef DEFAULT_CONSOLE_TX_GPIO
179 #define DEFAULT_CONSOLE_TX_GPIO gpio_num_t::GPIO_NUM_1
180 #define DEFAULT_CONSOLE_RX_GPIO gpio_num_t::GPIO_NUM_3
181 #endif // ndef DEFAULT_CONSOLE_TX_GPIO
182
185
186#if defined(ARDUINO_ARCH_ESP32)
187 TaskHandle_t myTaskHandle = NULL;
188 // uint32_t PollCount = 0;
189#endif // defined(ARDUINO_ARCH_ESP32)
190
191}; // c_OutputMgr
192
c_FileMgr FileMgr
Definition FileMgr.cpp:2531
#define OM_MAX_NUM_CHANNELS
Definition OutputMgr.hpp:45
#define DEFAULT_CONSOLE_RX_GPIO
Definition OutputMgr.hpp:180
#define NO_CONFIG_NEEDED
Definition OutputMgr.hpp:157
#define DEFAULT_CONSOLE_TX_GPIO
Definition OutputMgr.hpp:179
c_OutputMgr OutputMgr
Definition OutputMgr.cpp:1831
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
uint32_t NumberOfOutputProtocols
Definition OutputMgr.hpp:149
uint8_t * pOutputBuffer
Definition OutputMgr.hpp:175
void GetDriverName(String &Name)
Definition OutputMgr.hpp:66
void LoadConfig()
Read the current configuration data from nvram.
Definition OutputMgr.cpp:1210
void CreateJsonConfig(JsonObject &jsonConfig)
Definition OutputMgr.cpp:395
gpio_num_t ConsoleRxGpio
Definition OutputMgr.hpp:184
void UpdateDisplayBufferReferences(void)
Definition OutputMgr.cpp:1574
void TaskPoll()
bool ProcessJsonConfig(JsonDocument &jsonConfig)
Definition OutputMgr.cpp:1340
c_OutputMgr()
< Start up the driver and put it into a safe mode
Definition OutputMgr.cpp:247
void ClearStatistics(void)
Definition OutputMgr.cpp:622
e_OutputProtocolType
Definition OutputMgr.hpp:77
@ OutputProtocol_Disabled
Definition OutputMgr.hpp:78
@ OutputProtocol_Last
Definition OutputMgr.hpp:147
void GetConfig(byte *Response, uint32_t maxlen)
Definition OutputMgr.cpp:589
virtual ~c_OutputMgr()
< deallocate any resources and put the output channels into a safe state
Definition OutputMgr.cpp:302
uint32_t UsedBufferSize
Definition OutputMgr.hpp:176
void GetStatus(JsonObject &jsonStatus)
Definition OutputMgr.cpp:600
uint8_t NumOutputPorts
Definition OutputMgr.hpp:154
void SetConfig(const char *NewConfig)
Save the current configuration data to nvram.
Definition OutputMgr.cpp:1445
void InstantiateNewOutputChannel(uint32_t PortIndex, e_OutputProtocolType NewChannelType, bool StartDriver=true)
Definition OutputMgr.cpp:654
void DeleteConfig()
Definition OutputMgr.hpp:64
void ClearBuffer()
Definition OutputMgr.cpp:1820
bool BuildingNewConfig
Definition OutputMgr.hpp:162
time_t ConfigLoadNeeded
Definition OutputMgr.hpp:159
bool SetPortDefnitionDefaults(uint32_t PortIndex, e_OutputProtocolType TargetProtocolType)
Definition OutputMgr.cpp:1117
uint8_t GetNumPorts()
Definition OutputMgr.hpp:73
bool ConfigInProgress
Definition OutputMgr.hpp:160
void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputMgr.cpp:320
void SetSerialUart()
Definition OutputMgr.cpp:1494
uint32_t GetBufferUsedSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:62
void PauseOutputs(bool NewState)
Definition OutputMgr.cpp:1677
uint32_t GetBufferSize()
Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:63
void WriteChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pData)
Definition OutputMgr.cpp:1694
gpio_num_t ConsoleTxGpio
Definition OutputMgr.hpp:183
void ScheduleLoadConfig()
Definition OutputMgr.hpp:54
void CreateNewConfig()
Definition OutputMgr.cpp:476
bool FindJsonChannelConfig(JsonDocument &jsonConfig, OM_PortId_t PortId, JsonObject &ChanConfig)
Definition OutputMgr.cpp:1249
void ReadChannelData(uint32_t StartChannelId, uint32_t ChannelCount, uint8_t *pTargetData)
Definition OutputMgr.cpp:1759
String ConfigFileName
Definition OutputMgr.hpp:173
uint8_t * GetBufferAddress()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputMgr.hpp:61
void RelayUpdate(uint8_t RelayId, String &NewValue, String &Response)
Definition OutputMgr.cpp:1646
void Poll()
Call from loop(), renders output data.
Definition OutputMgr.cpp:1540
bool HasBeenInitialized
Definition OutputMgr.hpp:158
bool OutputIsPaused
Definition OutputMgr.hpp:161