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

Function InputHandler

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

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

Source from the content-addressed store, hash-verified

74** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
75**********************************************************************/
76void InputHandler(void) {
77 static uint32_t btnBFirstReleaseMs = 0;
78 static bool btnBWaitingSecondClick = false;
79 static bool btnBLongPressFired = false;
80
81 M5.update();
82
83 bool emitNext = false;
84 bool emitPrev = false;
85 bool emitEsc = false;
86 uint32_t now = launcherMillis();
87 bool btnAActive = M5.BtnA.isPressed() || M5.BtnA.isHolding();
88 bool btnBActive = M5.BtnB.isPressed() || M5.BtnB.isHolding();
89
90 if (M5.BtnB.wasPressed()) btnBLongPressFired = false;
91
92 if (btnBActive && !btnBLongPressFired && M5.BtnB.pressedFor(kBtnBLongPressMs)) {
93 btnBLongPressFired = true;
94 btnBWaitingSecondClick = false;
95 emitEsc = true;
96 }
97
98 if (M5.BtnB.wasReleased()) {
99 if (btnBLongPressFired) {
100 btnBLongPressFired = false;
101 } else if (btnBWaitingSecondClick && now - btnBFirstReleaseMs <= kBtnBDoublePressWindowMs) {
102 btnBWaitingSecondClick = false;
103 emitPrev = true;
104 } else {
105 btnBWaitingSecondClick = true;
106 btnBFirstReleaseMs = now;
107 }
108 }
109
110 if (btnBWaitingSecondClick && !btnBActive && now - btnBFirstReleaseMs > kBtnBDoublePressWindowMs) {
111 btnBWaitingSecondClick = false;
112 emitNext = true;
113 }
114
115 AnyKeyPress = btnAActive || btnBActive || btnBWaitingSecondClick || M5.BtnA.wasClicked() || emitNext ||
116 emitPrev || emitEsc;
117 if (!AnyKeyPress) return;
118
119 if ((btnAActive || btnBActive) && wakeUpScreen()) return;
120
121 if (M5.BtnA.wasClicked()) SelPress = true;
122 if (emitNext) NextPress = true;
123 if (emitPrev) PrevPress = true;
124 if (emitEsc) EscPress = true;
125}
126
127/*********************************************************************
128** Function: powerOff

Callers

nothing calls this directly

Calls 4

launcherMillisFunction · 0.85
wakeUpScreenFunction · 0.85
isPressedMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected