-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuperButton.cpp
52 lines (49 loc) · 1.44 KB
/
SuperButton.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
/*****************************************************************************
* Multifunctional Arduino button *
* Autor: Vyacheslav Azarov <[email protected]> *
* Licensed by GNU GPL V3 from 29 June 2007 *
* ***************************************************************************/
#include "SuperButton.hpp"
SuperButton::SuperButton(uint8_t pin, uint8_t guardtime,
uint16_t doubletime, uint16_t longertime):
Buttonkey(pin, guardtime)
{
this->doubletime = doubletime; this->longertime = longertime;
state = DETECT_SINGLE;
}
SuperButton::Press SuperButton::pressed(void)
{
switch (state)
{
case DETECT_SINGLE: if (Buttonkey::pressed())
{
timeout.begin(doubletime);
state = DETECT_DOUBLE;
}
break;
case DETECT_DOUBLE:
if (Buttonkey::released()) state = DETECT_SECOND;
else
if (!timeout.remain())
{
timeout.begin(longertime);
state = DETECT_LONGER;
}
break;
case DETECT_SECOND:
state = DETECT_SINGLE;
if (Buttonkey::pressed()) return DOUBLE;
if (!timeout.remain()) return SINGLE;
state = DETECT_SECOND;
break;
case DETECT_LONGER:
state = DETECT_SINGLE;
if (Buttonkey::released()) return SINGLE;
if (!timeout.remain()) return LONGER;
state = DETECT_LONGER;
break;
default: state = DETECT_SINGLE;
}
return NO;
}
/* Developed in Zaporizhzhya 2017 */