-
Notifications
You must be signed in to change notification settings - Fork 0
/
Relay.h
72 lines (57 loc) · 1.65 KB
/
Relay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef _RELAY_H
#define _RELAY_H
#include <inttypes.h>
class Relay {
public:
Relay(uint8_t pin, bool activeLow);
virtual ~Relay() {};
/*!
* \brief Sets a relay state.
*/
void setState(uint8_t state) { setPhysicalState(state); };
/*!
* \brief Determines if the relay is currently active.
* \return True of button is active
*/
bool isActive() const { return getPhysicalState(); }
/*!
* \brief Returns the time of the last state change.
* \return Time in ms
*/
uint32_t lastStateChange() const { return m_lastStateChange; }
/*!
* \brief Returns the duration for which the relay was last active.
* \return Duration in ms
*/
uint32_t lastActiveDuration() const { return m_lastActiveDuration; }
/*!
* \brief Gets the pin the relay is attached to.
* \return Pin number
*/
uint8_t getPin() const { return m_pin; }
/*!
* \brief Determines if the pin logic is active low.
* \return True if active low
*/
bool isActiveLow() const { return m_activeLow; }
Relay* next() const { return m_next; }
void setNext(Relay* next) { m_next = next; }
protected:
/*!
* \brief Gets the current physical state of the relay.
* \return True if button state is high
*/
uint8_t getPhysicalState() const;
/*!
* \brief Sets the physical state of the relay.
*/
void setPhysicalState(uint8_t state);
private:
uint32_t m_lastStateChange; //!< Time of last state change
uint32_t m_lastActiveDuration; //!< Duration of last active state
uint8_t m_pin; //!< Pin relay is attached to
bool m_activeLow; //!< If the relay logic is active low
Relay* m_next;
static bool defaultActiveLow;
};
#endif