-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedButton.hpp
57 lines (48 loc) · 1.62 KB
/
LedButton.hpp
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
#ifndef ledButtonHPP
#define ledButtonHPP
#include"Component.hpp"
#include"DimmableLed.hpp"
#include"Button.hpp"
template<int portNumber>
class LedButton: public Button<portNumber>
{
private:
DimmableLed& m_DimmableLed;
bool m_IsDecreasing = false;
public:
LedButton(DimmableLed& dimmableLed): Button<portNumber>("LedButton", false),m_DimmableLed(dimmableLed)
{}
LedButton(DimmableLed& dimmableLed, bool debug): Button<portNumber>("LedButton", debug),m_DimmableLed(dimmableLed)
{}
bool GetIsDecreasing() const{return m_IsDecreasing;}
virtual void OnShortButtonClick(){
if(Component::IsDebug())
Serial << Component::name() << ": Short Click\n";
if (m_IsDecreasing)
{
if (m_DimmableLed.GetIntensity() > 0)
m_DimmableLed.DecreaseLight();
if(Component::IsDebug())
Serial << Component::name() << ": intensity decrease\n";
}
else
{
m_DimmableLed.SwitchOff();
delay(300);
m_DimmableLed.IncreaseLight();
if(Component::IsDebug())
Serial << Component::name() << ": intensity increase\n";
}
}
virtual void OnLongButtonClick(){
if(Component::IsDebug())
Serial << Component::name() << ": Long Click ----- switch mode\n";
m_IsDecreasing = !m_IsDecreasing;
}
virtual void OnVeryLongButtonClick(){
if(Component::IsDebug())
Serial << Component::name() << ": Very Long Click\n";
m_DimmableLed.Blink();
}
};
#endif