MCPcopy Create free account
hub / github.com/JibbSmart/JoyShockMapper / ProcessButtonPress

Method ProcessButtonPress

JoyShockMapper/src/main.cpp:178–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176 }
177
178 void ProcessButtonPress(bool pressed, chrono::steady_clock::time_point time_now, float turbo_ms, float hold_ms)
179 {
180 auto elapsed_time = GetPressDurationMS(time_now);
181 if (pressed)
182 {
183 if (_turboCount == 0)
184 {
185 if (elapsed_time > MAGIC_INSTANT_DURATION)
186 {
187 CheckInstantRelease(BtnEvent::OnPress);
188 }
189 if (elapsed_time > hold_ms)
190 {
191 _keyToRelease->ProcessEvent(BtnEvent::OnHold, *this, _nameToRelease);
192 _keyToRelease->ProcessEvent(BtnEvent::OnTurbo, *this, _nameToRelease);
193 _turboCount++;
194 }
195 }
196 else
197 {
198 if (elapsed_time > hold_ms + MAGIC_INSTANT_DURATION)
199 {
200 CheckInstantRelease(BtnEvent::OnHold);
201 }
202 if (floorf((elapsed_time - hold_ms) / turbo_ms) >= _turboCount)
203 {
204 _keyToRelease->ProcessEvent(BtnEvent::OnTurbo, *this, _nameToRelease);
205 _turboCount++;
206 }
207 if (elapsed_time > hold_ms + _turboCount * turbo_ms + MAGIC_INSTANT_DURATION)
208 {
209 CheckInstantRelease(BtnEvent::OnTurbo);
210 }
211 }
212 }
213 else // not pressed
214 {
215 _keyToRelease->ProcessEvent(BtnEvent::OnRelease, *this, _nameToRelease);
216 if (_turboCount == 0)
217 {
218 _keyToRelease->ProcessEvent(BtnEvent::OnTap, *this, _nameToRelease);
219 _btnState = BtnState::TapRelease;
220 _press_times = time_now; // Start counting tap duration
221 }
222 else
223 {
224 _keyToRelease->ProcessEvent(BtnEvent::OnHoldRelease, *this, _nameToRelease);
225 if (_instantReleaseQueue.empty())
226 {
227 _btnState = BtnState::NoPress;
228 ClearKey();
229 }
230 else
231 {
232 _btnState = BtnState::InstRelease;
233 _press_times = time_now; // Start counting tap duration
234 }
235 }

Callers 1

handleButtonChangeMethod · 0.80

Calls 1

ProcessEventMethod · 0.80

Tested by

no test coverage detected