-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.cpp
59 lines (50 loc) · 980 Bytes
/
Buttons.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
#include "Buttons.h"
Button::Button()
{
}
Button::Button(int i, int t, bool r, int p)
{
id = i;
t1 = t;
repeat = r;
repeatPeriod = p;
timer = Timer();
}
//B1: returned when button pressed
//B10: returned when button released before t1
//B11: returned when timer just passed t1
//B100 returned when button released after t1
//B101 returned for a repeated event past t1
byte Button::getEvent(int bState)
{
if (bState == 1){
if (timer.t == -1){
timer.reset();
return B1;
} else {
timer.addTime();
}
if (timer.t > t1 && !overT1){
overT1 = true;
if (repeat){
timer.reset();
}
return B11;
}
if (repeat && overT1 && timer.t>repeatPeriod){
timer.reset();
return B101;
}
} else if (timer.t > 0){
overT1 = false;
if (timer.t < t1){
timer.t = -1;
return B10;
} else {
timer.t = -1;
return B100;
}
timer.t = -1;
}
return B0;
}