MCPcopy Create free account
hub / github.com/BruceDevices/firmware / InputHandler

Function InputHandler

boards/m5stack-sticks3/interface.cpp:145–189  ·  view source on GitHub ↗

** Function: InputHandler ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/

Source from the content-addressed store, hash-verified

143** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
144**********************************************************************/
145void InputHandler(void) {
146 static unsigned long tm = 0;
147 static bool dwLongFired = false;
148 unsigned long now = millis();
149 if (now - tm < 200 && !LongPress) return;
150 if (!wakeUpScreen()) AnyKeyPress = true;
151 else return;
152
153 bool selPressed = (digitalRead(SEL_BTN) == BTN_ACT);
154 bool dwPressed = dw_is_down;
155 bool dwWaiting = dw_waiting;
156 bool dwDoubleReady = dw_double_ready;
157 unsigned long dwPressStart = dw_press_ms;
158 unsigned long dwFirstRelease = dw_first_release_ms;
159
160 AnyKeyPress = selPressed || dwPressed || dwWaiting || dwDoubleReady;
161
162 if (selPressed) {
163 SelPress = true;
164 tm = now;
165 }
166 if (dwPressed) {
167 if (!dwLongFired && (now - dwPressStart) > kDwLongPressMs) {
168 EscPress = true;
169 dwLongFired = true;
170 dw_waiting = false;
171 dw_double_ready = false;
172 dw_long_seen = true;
173 tm = now;
174 }
175 } else if (dwLongFired) {
176 dwLongFired = false;
177 }
178
179 if (dwDoubleReady) {
180 PrevPress = true;
181 dw_double_ready = false;
182 dw_waiting = false;
183 tm = now;
184 } else if (dwWaiting && !dwPressed && (now - dwFirstRelease) > kDwDoublePressWindowMs) {
185 NextPress = true;
186 dw_waiting = false;
187 tm = now;
188 }
189}
190
191/*********************************************************************
192** Function: powerOff

Callers

nothing calls this directly

Calls 2

millisFunction · 0.85
wakeUpScreenFunction · 0.85

Tested by

no test coverage detected