MCPcopy Create free account
hub / github.com/bmorcelli/Launcher / InputHandler

Function InputHandler

boards/m5stack-cardputer/interface.cpp:157–405  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

155** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
156**********************************************************************/
157void InputHandler(void) {
158 static unsigned long tm = 0;
159 static unsigned long nextRepeatTime = 0;
160 static unsigned long prevRepeatTime = 0;
161 static unsigned long upRepeatTime = 0;
162 static unsigned long downRepeatTime = 0;
163
164 static bool sel = false;
165 static bool prev = false;
166 static bool next = false;
167 static bool up = false;
168 static bool down = false;
169 static bool esc = false;
170
171 if (!UseTCA8418 && launcherMillis() - tm < 200 && !LongPress) return;
172
173 if (launcherGpioRead(0) == LOW) { // GPIO0 button, shoulder button
174 tm = launcherMillis();
175 AnyKeyPress = true;
176 if (!wakeUpScreen()) yield();
177 else return;
178 SelPress = true;
179 AnyKeyPress = true;
180 }
181 if (UseTCA8418) {
182 bool keyEventHandled = false;
183 bool nextPulse = false;
184 bool prevPulse = false;
185 bool upPulse = false;
186 bool downPulse = false;
187 bool delPulse = false;
188 bool keyPulse = false;
189 keyStroke pendingKey;
190
191 if (kb_interrupt) {
192 // Drain the FIFO now. Processing one TCA8418 event per 200 ms made quick taps
193 // pile up and replay later as delayed navigation.
194 bool wokeScreen = false;
195 while (tca.available() > 0) {
196 int keyEvent = tca.getEvent();
197 bool pressed = (keyEvent & 0x80); // Bit 7: 1 Pressed, 0 Released
198 uint8_t value = keyEvent & 0x7F; // Bits 0-6: key value
199
200 // Map raw value to physical position
201 uint8_t row, col;
202 mapRawKeyToPhysical(value, row, col);
203
204 // launcherConsolePrintf("Key event: raw=%d, pressed=%d, row=%d, col=%d\n", value, pressed,
205 // row, col);
206
207 if (row >= 4 || col >= 14) continue;
208
209 // wakeUpScreen() is stateful — it returns true only on the first call when
210 // the screen is actually sleeping. Track the result so that all remaining
211 // events in the same FIFO burst are also discarded, not just the first one.
212 if (!wokeScreen) wokeScreen = wakeUpScreen();
213 if (wokeScreen) continue;
214

Callers

nothing calls this directly

Calls 10

launcherMillisFunction · 0.85
launcherGpioReadFunction · 0.85
wakeUpScreenFunction · 0.85
mapRawKeyToPhysicalFunction · 0.85
isPressedMethod · 0.80
isKeyPressedMethod · 0.80
handleSpecialKeysFunction · 0.70
getKeyCharFunction · 0.70
ClearMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected