Skip to content

Commit 92a9030

Browse files
authored
Merge pull request #653 from tmarti2/improve-slowbongo
Improve slowbongo
2 parents e0d1f20 + 385e5c7 commit 92a9030

3 files changed

Lines changed: 156 additions & 180 deletions

File tree

slowbongo/Main.qml

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Item {
139139
}
140140

141141
if (root.useTappyMode) {
142-
root.onKeyPress(root.bassIntensity > root.bigBeatThreshold);
142+
root.musicEvent(root.bassIntensity > root.bigBeatThreshold);
143143
}
144144

145145
beatCooldownTimer.restart();
@@ -168,8 +168,8 @@ Item {
168168
onTriggered: root.catState = root.pendingCatState
169169
}
170170

171-
// === KEY PRESS HANDLER ===
172-
function onKeyPress(isBigHit = false) {
171+
// === MUSIC HANDLER ===
172+
function musicEvent(isBigHit = false) {
173173
if (root.paused) return;
174174
root.waiting = false;
175175

@@ -195,6 +195,65 @@ Item {
195195
waitingTimer.restart();
196196
}
197197

198+
// === KEY PRESS HANDLER ===
199+
function onKeyPress(isBigHit = false) {
200+
if (root.paused) return;
201+
root.waiting = false;
202+
203+
let targetState;
204+
if (isBigHit) {
205+
targetState = 3;
206+
} else {
207+
if (root.catState !== 0){
208+
targetState = 3;
209+
} else {
210+
root.leftWasLast = !root.leftWasLast;
211+
targetState = root.leftWasLast ? 1 : 2;
212+
}
213+
}
214+
215+
root.catState = targetState;
216+
waitingTimer.restart();
217+
}
218+
219+
function onKeyRelease(isBigHit = false) {
220+
if (root.paused) return;
221+
root.waiting = false;
222+
223+
let targetState;
224+
if (isBigHit) {
225+
targetState = 0;
226+
} else {
227+
if (root.catState === 3){
228+
targetState = root.leftWasLast ? 1 : 2;
229+
} else {
230+
targetState = 0;
231+
}
232+
}
233+
234+
root.catState = targetState;
235+
waitingTimer.restart();
236+
}
237+
238+
function onKeyRepeat(isBigHit = false){
239+
if (root.paused) return;
240+
root.waiting = false;
241+
242+
let targetState;
243+
if (root.catState !== 0) {
244+
targetState = root.catState;
245+
} else {
246+
if (isBigHit){
247+
targetState = 3;
248+
} else {
249+
targetState = root.leftWasLast ? 1 : 2;
250+
}
251+
}
252+
253+
root.catState = targetState;
254+
waitingTimer.restart();
255+
}
256+
198257
// === STATE CHANGE HANDLERS ===
199258
onPausedChanged: {
200259
if (root.paused) {
@@ -291,10 +350,20 @@ Item {
291350

292351
stdout: SplitParser {
293352
onRead: data => {
294-
if (data.includes("EV_KEY") && data.includes("value 1")) {
295-
// Detect spacebar for double slap (both paws)
296-
const isSpace = data.includes("KEY_SPACE");
297-
root.onKeyPress(isSpace);
353+
if (data.includes("EV_KEY")) {
354+
// Detect spacebar/enter for double slap (both paws)
355+
const isBigHit = data.includes("KEY_SPACE") || data.includes("KEY_ENTER");
356+
// Key pressed
357+
// Ignore BTN_TOOL_ events to avoid double events with touchpads
358+
if (data.includes("value 1") && !data.includes("BTN_TOOL_")){
359+
root.onKeyPress(isBigHit);
360+
// Key released
361+
} else if (data.includes("value 0")) {
362+
root.onKeyRelease(isBigHit);
363+
// Key repeat
364+
} else if (data.includes("value 2")) {
365+
root.onKeyRepeat(isBigHit);
366+
}
298367
}
299368
}
300369
}
@@ -356,9 +425,14 @@ Item {
356425
if (exitCode === 0) {
357426
Logger.i("Slow Bongo", "Device detected, restarting monitoring: " + deviceMonitor.modelData);
358427
evtestProc.running = true;
359-
} else if (deviceMonitor.retryCount <= deviceMonitor.retryIntervals.length) {
360-
Logger.i("Slow Bongo", "Device not found, will check again: " + deviceMonitor.modelData);
428+
} else if (deviceMonitor.retryCount < deviceMonitor.retryIntervals.length) {
429+
deviceMonitor.retryCount++;;
430+
const interval = deviceMonitor.retryIntervals[deviceMonitor.retryCount - 1];
431+
Logger.i("Slow Bongo", "Device " + deviceMonitor.modelData + " not found, will retry in " + Math.floor(interval / 1000) + "s (attempt " + deviceMonitor.retryCount + "/" + deviceMonitor.retryIntervals.length + ")");
432+
restartTimer.interval = interval;
361433
restartTimer.start();
434+
} else {
435+
Logger.w("Slow Bongo", "Max retries reached for device: " + deviceMonitor.modelData + ". Giving up.");
362436
}
363437
}
364438
}

0 commit comments

Comments
 (0)