| 206 | } |
| 207 | |
| 208 | void processKB_USB() { |
| 209 | int currentMillis = millis(); |
| 210 | char inchar = 0; |
| 211 | |
| 212 | // 1. Drain the hardware buffer continuously at loop speed |
| 213 | inchar = KB().updateKeypress(); |
| 214 | |
| 215 | // 2. Only process the actual input if the cooldown has expired |
| 216 | if (currentMillis - KBBounceMillis >= KB_COOLDOWN) { |
| 217 | if (inchar != 0) { |
| 218 | KBBounceMillis = currentMillis; // Reset the debounce timer |
| 219 | |
| 220 | // HANDLE INPUTS |
| 221 | // Home / Exit / App Switcher recieved |
| 222 | if (inchar == 12 || inchar == 8 || inchar == 19 || inchar == 28 || inchar == 23) { |
| 223 | USBAppShutdown(); |
| 224 | prefs.begin("PocketMage", false); |
| 225 | prefs.putInt("CurrentAppState", static_cast<int>(HOME)); |
| 226 | prefs.putBool("Seamless_Reboot", true); |
| 227 | prefs.end(); |
| 228 | esp_restart(); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // 3. Update OLED at 10FPS, completely independent of keyboard bounce |
| 234 | currentMillis = millis(); |
| 235 | if (currentMillis - OLEDFPSMillis >= (1000/10 /*OLED_MAX_FPS*/)) { |
| 236 | OLEDFPSMillis = currentMillis; |
| 237 | OLED().oledLine(currentLine, currentLine.length(), false); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | void einkHandler_USB() { |
| 242 | if (newState) { |
no test coverage detected