MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
relay.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Myron Rodrigues
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _RELAY_H_
18 #define _RELAY_H_
19 
20 #include <Arduino.h>
21 
22 enum class Switch : bool { ON = HIGH, OFF = LOW };
23 
28 class Relay
29 {
30 public:
31  virtual void begin(Switch sw) = 0;
32 
33  virtual void set(Switch state) = 0;
34 
35  virtual int get_state() = 0;
36 
37  virtual void toggle() = 0;
38 };
39 
44 class RelayAH : public Relay
45 {
46 private:
47  int pin_;
48 
49 public:
55  RelayAH(int pin);
56 
62  void begin(Switch sw);
63 
69  void set(Switch state);
70 
76  int get_state();
77 
82  void toggle();
83 };
84 
85 // active low
86 class RelayAL : public Relay
87 {
88 private:
89  int pin_;
90 
91 public:
97  RelayAL(int pin);
98 
104  void begin(Switch sw);
105 
111  void set(Switch state);
112 
118  int get_state();
119 
124  void toggle();
125 };
126 
127 #endif
Active high relay.
Definition: relay.h:45
int get_state()
Get the current state.
Definition: relay.cpp:27
RelayAH(int pin)
Construct a new active high relay.
Definition: relay.cpp:17
void begin(Switch sw)
initialise pin and set initial relay state
Definition: relay.cpp:19
void set(Switch state)
set relay state
Definition: relay.cpp:25
void toggle()
Toggle the relay.
Definition: relay.cpp:29
Definition: relay.h:87
void set(Switch state)
set relay state
Definition: relay.cpp:44
int get_state()
Get the current state.
Definition: relay.cpp:46
RelayAL(int pin)
Construct a new active low relay.
Definition: relay.cpp:36
void begin(Switch sw)
initialise pin and set initial relay state
Definition: relay.cpp:38
void toggle()
Toggle the relay.
Definition: relay.cpp:51
Abstract relay class.
Definition: relay.h:29
virtual void toggle()=0
virtual int get_state()=0
virtual void begin(Switch sw)=0
virtual void set(Switch state)=0
Definition: utility.h:39
Switch
Definition: relay.h:22