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 copyright 2015 - 2026 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_OutputProtocol_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 (OM_OutputPortDefinition_t & OutputPortDefinition,
59 virtual ~c_OutputRelay ();
60
61 // functions to be provided by the derived class
62 void Begin ();
63 bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
64 void GetConfig (ArduinoJson::JsonObject & jsonConfig);
65 uint32_t Poll ();
66#if defined(ARDUINO_ARCH_ESP32)
67 bool RmtPoll () {return false;}
68#endif // defined(ARDUINO_ARCH_ESP32)
69 void GetDriverName (String& sDriverName);
70 void GetStatus (ArduinoJson::JsonObject & jsonStatus);
71 uint32_t GetNumOutputBufferBytesNeeded () { return Num_Channels; }
72 uint32_t GetNumOutputBufferChannelsServiced () { return Num_Channels; }
73 bool ValidateGpio (gpio_num_t ConsoleTxGpio, gpio_num_t ConsoleRxGpio);
74 void RelayUpdate (uint8_t RelayId, String & NewValue, String & Response);
75
76private:
77// # define OM_RELAY_CHANNEL_LIMIT 8
78# define OM_RELAY_CHANNEL_LIMIT 1
79# define OM_RELAY_UPDATE_INTERVAL_NAME CN_updateinterval
80// # define OM_RELAY_CHANNEL_ENABLED_NAME CN_en
81# define OM_RELAY_CHANNEL_INVERT_NAME CN_inv
82# define OM_RELAY_CHANNEL_PWM_NAME CN_pwm
83
84 bool validate ();
85 void OutputValue(RelayChannel_t & currentRelay, uint8_t NewValue);
86
87 // config data
88 RelayChannel_t OutputList[OM_RELAY_CHANNEL_LIMIT];
89 uint16_t UpdateInterval = 0;
90
91 // non config data
92 uint16_t Num_Channels = OM_RELAY_CHANNEL_LIMIT;
93
94}; // c_OutputRelay
95
96#endif // def SUPPORT_OutputProtocol_Relay
Definition OutputCommon.hpp:32
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:41
virtual bool ValidateGpio(gpio_num_t ConsoleTxGpio, gpio_num_t ConsoleRxGpio)
Definition OutputCommon.cpp:143
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:78
virtual void GetConfig(ArduinoJson::JsonObject &jsonConfig)
Get the current config used by the driver.
Definition OutputCommon.cpp:95
e_OutputProtocolType
Definition OutputMgr.hpp:78
Definition OutputMgrPortDefs.hpp:90