ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputRelay.hpp
Go to the documentation of this file.
1#pragma once
2/******************************************************************
3*
4* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel (And Serial!) driver
5* Orginal ESPixelStickproject by 2015 Shelby Merrick
6*
7* Brought to you by:
8* Bill Porter
9* www.billporter.info
10*
11* See Readme for other info and version history
12*
13*
14*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19<http://www.gnu.org/licenses/>
20*
21*This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
22*To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or
23*send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
24******************************************************************
25*
26* This is a derived class that converts data in the output buffer into
27* Relay States and then outputs on a GPIO
28*
29*/
30#include "ESPixelStick.h"
31
32#ifdef SUPPORT_OutputType_Relay
33
34#include "OutputCommon.hpp"
35
36class c_OutputRelay : public c_OutputCommon
37{
38public:
39 struct RelayChannel_t
40 {
41 bool Enabled;
42 bool httpEnabled;
43 bool InvertOutput;
44 bool Pwm;
45 uint8_t OnOffTriggerLevel;
46 gpio_num_t GpioId;
47 uint8_t OnValue;
48 uint8_t OffValue;
49 uint8_t previousValue;
50#if defined(ARDUINO_ARCH_ESP32)
51 uint16_t PwmFrequency;
52#endif // defined(ARDUINO_ARCH_ESP32)
53 uint8_t ChannelIndex;
54 };
55
56 // These functions are inherited from c_OutputCommon
57 c_OutputRelay (c_OutputMgr::e_OutputChannelIds OutputChannelId,
58 gpio_num_t outputGpio,
59 uart_port_t uart,
60 c_OutputMgr::e_OutputType outputType);
61 virtual ~c_OutputRelay ();
62
63 // functions to be provided by the derived class
64 void Begin ();
65 bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
66 void GetConfig (ArduinoJson::JsonObject & jsonConfig);
67 uint32_t Poll ();
68#if defined(ARDUINO_ARCH_ESP32)
69 bool RmtPoll () {return false;}
70#endif // defined(ARDUINO_ARCH_ESP32)
71 void GetDriverName (String& sDriverName);
72 void GetStatus (ArduinoJson::JsonObject & jsonStatus);
73 uint32_t GetNumOutputBufferBytesNeeded () { return Num_Channels; }
74 uint32_t GetNumOutputBufferChannelsServiced () { return Num_Channels; }
75 bool ValidateGpio (gpio_num_t ConsoleTxGpio, gpio_num_t ConsoleRxGpio);
76 void RelayUpdate (uint8_t RelayId, String & NewValue, String & Response);
77
78private:
79# define OM_RELAY_CHANNEL_LIMIT 8
80# define OM_RELAY_UPDATE_INTERVAL_NAME CN_updateinterval
81# define OM_RELAY_CHANNEL_ENABLED_NAME CN_en
82# define OM_RELAY_CHANNEL_INVERT_NAME CN_inv
83# define OM_RELAY_CHANNEL_PWM_NAME CN_pwm
84
85 bool validate ();
86 void OutputValue(RelayChannel_t & currentRelay, uint8_t NewValue);
87
88 // config data
89 RelayChannel_t OutputList[OM_RELAY_CHANNEL_LIMIT];
90 uint16_t UpdateInterval = 0;
91
92 // non config data
93 String OutputName;
94 uint16_t Num_Channels = OM_RELAY_CHANNEL_LIMIT;
95
96}; // c_OutputRelay
97
98#endif // def SUPPORT_OutputType_Relay
Definition OutputCommon.hpp:31
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
virtual bool ValidateGpio(gpio_num_t ConsoleTxGpio, gpio_num_t ConsoleRxGpio)
Definition OutputCommon.cpp:149
virtual uint32_t GetNumOutputBufferChannelsServiced()=0
virtual void GetStatus(ArduinoJson::JsonObject &jsonStatus)=0
virtual uint32_t Poll()=0
Call from loop(), renders output data.
virtual uint32_t GetNumOutputBufferBytesNeeded()=0
virtual bool SetConfig(ArduinoJson::JsonObject &jsonConfig)
Set a new config in the driver.
Definition OutputCommon.cpp:84
virtual void GetConfig(ArduinoJson::JsonObject &jsonConfig)
Get the current config used by the driver.
Definition OutputCommon.cpp:101
e_OutputChannelIds
Definition OutputMgr.hpp:68
e_OutputType
Definition OutputMgr.hpp:127