-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitch.cpp
68 lines (55 loc) · 1.31 KB
/
Switch.cpp
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
#include "Switch.h"
class Button;
uint8_t Switch::ID = 1;
/*!
* \brief Sets the callback class for this manager.
* \param callback Pointer to the callback handler
* \return True if the callback was set
*/
bool Switch::cb(SwitchCallbackFunctionHandler *callback)
{
if (callback == NULL)
return false;
m_callback = callback;
return true;
}
/*!
* \brief Sets the callback function for this manager.
* \param callback Pointer to the callback function
* \return True if the callback was set
*/
bool Switch::cb(
SwitchCallbackFunctionHandler::SwitchCallbackFunction callback)
{
if (callback == NULL)
return false;
m_callback = new SwitchCallbackFunctionHandler(callback);
return true;
}
void Switch::callback(Button* b) {
if (m_callback) m_callback->handleSwitchEvent(this, b);
}
// Add new button to this switch
Switch& Switch::b(uint8_t pin, bool activeLow, bool pullUp,
uint32_t debounceDelay)
{
if (m_bls) {
m_bls->add(pin, activeLow, pullUp, debounceDelay);
}
return *this;
}
// Add new relay to this switch
Switch& Switch::r(uint8_t pin, bool activeLow) {
if (m_rls) {
m_rls->add(pin, activeLow);
}
return *this;
}
uint8_t Switch::toggle() {
changeState(!m_state);
return m_state;
}
void Switch::changeState(uint8_t state) {
m_state = state;
m_rls->set(state);
}