-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypadBlocking.cpp
157 lines (113 loc) · 3.16 KB
/
keypadBlocking.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "keypadBlocking.h"
// Constructors
KeypadBlocking::KeypadBlocking(PinName r0, PinName r1, PinName r2, PinName r3, PinName c0, PinName c1, PinName c2,
PinName c3)
: keypad(r0, r1, r2, r3, c0, c1, c2, c3)
{
// register the callbacks that push keypad events from the internal object to the internal buffers
keypad.register_onpress(callback(this, &KeypadBlocking::push_press));
keypad.register_onrelease(callback(this, &KeypadBlocking::push_release));
keypad.register_onlongpress(callback(this, &KeypadBlocking::push_longpress));
}
// Public Methods
bool
KeypadBlocking::initialize() {
return keypad.initialize();
}
bool
KeypadBlocking::finalize() {
return keypad.finalize();
}
bool
KeypadBlocking::is_initialized() const {
return keypad.is_initialized();
}
uint32_t
KeypadBlocking::press_available() const {
return pressBuf.size();
}
uint32_t
KeypadBlocking::release_available() const {
return releaseBuf.size();
}
uint32_t
KeypadBlocking::longpress_available() const {
return longpressBuf.size();
}
bool
KeypadBlocking::peek_press(uint32_t *rptr, uint32_t *cptr) const {
// if the buffer is empty, return false, store the coordinates to the supplied locations otherwise
struct button_coord cur {};
if (!pressBuf.peek(cur)) {
return false;
}
*rptr = cur.r;
*cptr = cur.c;
return true;
}
bool
KeypadBlocking::pop_press() {
// if the buffer is empty, return false, store the coordinates to the supplied locations otherwise
struct button_coord cur {};
if (!pressBuf.pop(cur)) {
return false;
}
//*rptr = cur.r;
//*cptr = cur.c;
return true;
}
bool
KeypadBlocking::peek_release(uint32_t *rptr, uint32_t *cptr) const {
// if the buffer is empty, return false, store the coordinates to the supplied locations otherwise
struct button_coord cur {};
if (!releaseBuf.peek(cur)) {
return false;
}
*rptr = cur.r;
*cptr = cur.c;
return true;
}
bool
KeypadBlocking::pop_release() {
// if the buffer is empty, return false, store the coordinates to the supplied locations otherwise
struct button_coord cur {};
if (!releaseBuf.pop(cur)) {
return false;
}
//*rptr = cur.r;
//*cptr = cur.c;
return true;
}
bool
KeypadBlocking::peek_longpress(uint32_t *rptr, uint32_t *cptr) const {
// if the buffer is empty, return false, store the coordinates to the supplied locations otherwise
struct button_coord cur {};
if (!longpressBuf.peek(cur)) {
return false;
}
*rptr = cur.r;
*cptr = cur.c;
return true;
}
bool
KeypadBlocking::pop_longpress() {
// if the buffer is empty, return false, store the coordinates to the supplied locations otherwise
struct button_coord cur {};
if (!longpressBuf.pop(cur)) {
return false;
}
return true;
}
// Private Methods
void
KeypadBlocking::push_press(uint32_t r, uint32_t c) {
pressBuf.push({r, c});
}
void
KeypadBlocking::push_release(uint32_t r, uint32_t c) {
releaseBuf.push({r, c});
}
void
KeypadBlocking::push_longpress(uint32_t r, uint32_t c) {
longpressBuf.push({r, c});
}