** Function: InputHandler ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/
| 68 | ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress |
| 69 | **********************************************************************/ |
| 70 | void InputHandler(void) { |
| 71 | static unsigned long tm = 0; |
| 72 | constexpr unsigned long kInputDebounceMs = 75; |
| 73 | if (launcherMillis() - tm < kInputDebounceMs && !LongPress) return; |
| 74 | |
| 75 | checkPowerSaveTime(); |
| 76 | |
| 77 | static bool buttonWasDown = false; |
| 78 | static unsigned long buttonDownAt = 0; |
| 79 | static uint8_t drawn = 2; |
| 80 | constexpr unsigned long kSelectPressMs = 550; |
| 81 | constexpr unsigned long kBackPressMs = 1200; |
| 82 | constexpr unsigned long kDoublePressIntervalMs = 300; |
| 83 | |
| 84 | // Variables for double press detection |
| 85 | static unsigned long lastButtonReleaseTime = 0; |
| 86 | static int clickCount = 0; |
| 87 | static bool pendingNextPress = false; |
| 88 | static unsigned long pendingTime = 0; |
| 89 | |
| 90 | // Check for pending NextPress timeout |
| 91 | if (pendingNextPress && launcherMillis() - pendingTime > kDoublePressIntervalMs) { |
| 92 | NextPress = true; |
| 93 | pendingNextPress = false; |
| 94 | } |
| 95 | |
| 96 | bool buttonDown = (launcherGpioRead(SEL_BTN) == LOW); |
| 97 | |
| 98 | if (buttonDown && !buttonWasDown) { |
| 99 | buttonWasDown = true; |
| 100 | buttonDownAt = launcherMillis(); |
| 101 | tm = launcherMillis(); |
| 102 | AnyKeyPress = true; |
| 103 | LongPress = false; |
| 104 | if (wakeUpScreen()) return; |
| 105 | } |
| 106 | |
| 107 | if (buttonDown) { |
| 108 | AnyKeyPress = true; |
| 109 | if (launcherMillis() - buttonDownAt >= kSelectPressMs) { |
| 110 | LongPress = true; |
| 111 | if (drawn > 1) { |
| 112 | tft->fillRect(tftWidth - 3, 0, 3, tftHeight, GREENYELLOW); |
| 113 | tft->fillRect(0, tftHeight - 3, tftWidth, 3, GREENYELLOW); |
| 114 | drawn = 1; |
| 115 | } |
| 116 | } |
| 117 | if (launcherMillis() - buttonDownAt >= kBackPressMs && drawn > 0) { |
| 118 | tft->fillRect(tftWidth - 3, 0, 3, tftHeight, RED); |
| 119 | tft->fillRect(0, tftHeight - 3, tftWidth, 3, RED); |
| 120 | drawn = 0; |
| 121 | } |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (buttonWasDown) { |
| 126 | buttonWasDown = false; |
| 127 | unsigned long heldMs = launcherMillis() - buttonDownAt; |
nothing calls this directly
no test coverage detected