ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputCommon.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputCommon.hpp - Output base class
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2021, 2022 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 base class used to manage the output port. It provides a common API
20* for use by the factory class to manage the object.
21*/
22
23#include "ESPixelStick.h"
24#include "OutputMgr.hpp"
25
26#ifdef ARDUINO_ARCH_ESP32
27# include <driver/uart.h>
28#endif
29
31{
32public:
34 gpio_num_t outputGpio,
35 uart_port_t uart,
36 c_OutputMgr::e_OutputType outputType);
37 virtual ~c_OutputCommon ();
38
41
42 // functions to be provided by the derived class
43 virtual void Begin () {}
44 virtual bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
45 virtual void GetConfig (ArduinoJson::JsonObject & jsonConfig);
46 virtual uint32_t Poll () = 0;
47#ifdef ARDUINO_ARCH_ESP32
48 virtual bool RmtPoll () = 0;
49#endif // def ARDUINO_ARCH_ESP32
50 virtual void GetDriverName (String & sDriverName) = 0;
52 uint8_t * GetBufferAddress () { return pOutputBuffer;}
53 uint32_t GetBufferUsedSize () { return OutputBufferSize;}
54 gpio_num_t GetOutputGpio () { return DataPin; }
56 virtual void GetStatus (ArduinoJson::JsonObject & jsonStatus) = 0;
57 virtual void BaseGetStatus (ArduinoJson::JsonObject & jsonStatus);
58 void SetOutputBufferAddress (uint8_t* pNewOutputBuffer) { pOutputBuffer = pNewOutputBuffer; }
59 virtual void SetOutputBufferSize (uint32_t NewOutputBufferSize) { OutputBufferSize = NewOutputBufferSize; };
60 virtual uint32_t GetNumOutputBufferBytesNeeded () = 0;
61 virtual uint32_t GetNumOutputBufferChannelsServiced () = 0;
62 virtual void PauseOutput (bool NewState) {Paused = NewState;}
63 virtual void ClearBuffer ();
64 virtual void WriteChannelData (uint32_t StartChannelId, uint32_t ChannelCount, byte *pSourceData);
65 virtual void ReadChannelData (uint32_t StartChannelId, uint32_t ChannelCount, byte *pTargetData);
66 virtual bool ValidateGpio (gpio_num_t ConsoleTxGpio, gpio_num_t ConsoleRxGpio);
67 virtual bool DriverIsSendingIntensityData() {return false;}
68 virtual uint32_t GetFrameTimeMs() {return 1 + (ActualFrameDurationMicroSec / 1000); }
69 bool IsPaused() {return Paused;}
70
71protected:
72
73 gpio_num_t DataPin = gpio_num_t (-1);
74 uart_port_t UartId = uart_port_t (-1);
75 OTYPE_t OutputType = OTYPE_t::OutputType_Disabled;
76 OID_t OutputChannelId = OID_t::OutputChannelId_End;
77 bool HasBeenInitialized = false;
78 uint32_t FrameDurationInMicroSec = 25000;
79 uint32_t ActualFrameDurationMicroSec = 50000; // Default time for relays is every 50ms
80 uint8_t * pOutputBuffer = nullptr;
81 uint32_t OutputBufferSize = 0;
82 uint32_t FrameCount = 0;
83 bool Paused = false;
84
85 virtual void ReportNewFrame ();
86
87 inline bool canRefresh ()
88 {
89 bool response = false;
90 uint32_t Now = micros ();
91 uint32_t FrameTimeDeltaInMicroSec = Now - FrameStartTimeInMicroSec; // how many us since the frame started
92
93 // did the counter wrap?
95 {
96 FrameTimeDeltaInMicroSec = Now + (0 - FrameStartTimeInMicroSec);
97 }
98
99 if(FrameTimeDeltaInMicroSec > FrameDurationInMicroSec)
100 {
101 response = true;
102 }
103 return response;
104 }
105
106private:
108
109}; // c_OutputCommon
Definition OutputCommon.hpp:31
uint32_t FrameStartTimeInMicroSec
Definition OutputCommon.hpp:107
void SetOutputBufferAddress(uint8_t *pNewOutputBuffer)
Definition OutputCommon.hpp:58
virtual ~c_OutputCommon()
Definition OutputCommon.cpp:50
OID_t GetOutputChannelId()
return the output channel number
Definition OutputCommon.hpp:51
uint32_t ActualFrameDurationMicroSec
Definition OutputCommon.hpp:79
virtual void GetDriverName(String &sDriverName)=0
get the name for the instantiated driver
virtual void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputCommon.hpp:43
uint32_t FrameCount
Definition OutputCommon.hpp:82
OID_t OutputChannelId
Definition OutputCommon.hpp:76
c_OutputMgr::e_OutputChannelIds OID_t
Definition OutputCommon.hpp:39
uint8_t * pOutputBuffer
Definition OutputCommon.hpp:80
bool Paused
Definition OutputCommon.hpp:83
virtual bool ValidateGpio(gpio_num_t ConsoleTxGpio, gpio_num_t ConsoleRxGpio)
Definition OutputCommon.cpp:150
bool canRefresh()
Definition OutputCommon.hpp:87
virtual uint32_t GetFrameTimeMs()
Definition OutputCommon.hpp:68
c_OutputCommon(c_OutputMgr::e_OutputChannelIds OutputChannelId, gpio_num_t outputGpio, uart_port_t uart, c_OutputMgr::e_OutputType outputType)
< Start up the driver and put it into a safe mode
Definition OutputCommon.cpp:28
virtual uint32_t GetNumOutputBufferChannelsServiced()=0
virtual bool DriverIsSendingIntensityData()
Definition OutputCommon.hpp:67
uint32_t OutputBufferSize
Definition OutputCommon.hpp:81
uart_port_t UartId
Definition OutputCommon.hpp:74
uint32_t FrameDurationInMicroSec
Definition OutputCommon.hpp:78
virtual void PauseOutput(bool NewState)
Definition OutputCommon.hpp:62
uint8_t * GetBufferAddress()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputCommon.hpp:52
virtual void WriteChannelData(uint32_t StartChannelId, uint32_t ChannelCount, byte *pSourceData)
Definition OutputCommon.cpp:124
virtual void BaseGetStatus(ArduinoJson::JsonObject &jsonStatus)
Definition OutputCommon.cpp:68
OTYPE_t OutputType
Definition OutputCommon.hpp:75
bool IsPaused()
Definition OutputCommon.hpp:69
c_OutputMgr::e_OutputType OTYPE_t
Definition OutputCommon.hpp:40
virtual void GetStatus(ArduinoJson::JsonObject &jsonStatus)=0
virtual uint32_t Poll()=0
Call from loop(), renders output data.
gpio_num_t GetOutputGpio()
Definition OutputCommon.hpp:54
gpio_num_t DataPin
Definition OutputCommon.hpp:73
virtual uint32_t GetNumOutputBufferBytesNeeded()=0
uint32_t GetBufferUsedSize()
Get the address of the buffer into which the E1.31 handler will stuff data.
Definition OutputCommon.hpp:53
virtual bool SetConfig(ArduinoJson::JsonObject &jsonConfig)
Set a new config in the driver.
Definition OutputCommon.cpp:94
OTYPE_t GetOutputType()
Have the instance report its type.
Definition OutputCommon.hpp:55
virtual void ReadChannelData(uint32_t StartChannelId, uint32_t ChannelCount, byte *pTargetData)
Definition OutputCommon.cpp:137
virtual void ClearBuffer()
Definition OutputCommon.cpp:58
virtual void ReportNewFrame()
Definition OutputCommon.cpp:80
virtual void GetConfig(ArduinoJson::JsonObject &jsonConfig)
Get the current config used by the driver.
Definition OutputCommon.cpp:111
virtual void SetOutputBufferSize(uint32_t NewOutputBufferSize)
Definition OutputCommon.hpp:59
bool HasBeenInitialized
Definition OutputCommon.hpp:77
e_OutputChannelIds
Definition OutputMgr.hpp:67
e_OutputType
Definition OutputMgr.hpp:126