Skip to content

Commit 9366aac

Browse files
committed
do not block while delaying switch
1 parent 6c2bef4 commit 9366aac

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/hhd/device/claw/base.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ def prepare(m):
365365

366366
logger.info("Emulated controller launched, have fun!")
367367
prev = 0
368+
woke_up = 0
368369
while not should_exit.is_set() and not updated.is_set():
369370
start = time.perf_counter()
370371
# Add timeout to call consumers a minimum amount of times per second
@@ -378,18 +379,19 @@ def prepare(m):
378379
if id(d) in to_run:
379380
evs.extend(d.produce(r))
380381

382+
# Detect wakeup through pause
381383
if start - prev > 1:
382-
# After wakeup, the controller waits a bit until it
383-
# realizes it woke up and switches to desktop mode.
384-
# Therefore we need to wait otherwise we race it and
385-
# end up stuck in desktop mode.
386-
if prev:
387-
time.sleep(3)
384+
woke_up = start
385+
prev = start
386+
387+
# After wakeup, the controller waits a bit until it
388+
# realizes it woke up and switches to desktop mode.
389+
# Therefore we need to wait otherwise we race it and
390+
# end up stuck in desktop mode.
391+
if woke_up is not None and start - woke_up > 3:
388392
logger.info("Setting controller to dinput mode.")
389393
d_vend.set_dinput_mode()
390-
prev = time.perf_counter()
391-
else:
392-
prev = start
394+
woke_up = None
393395

394396
evs = multiplexer.process(evs)
395397
if evs:

0 commit comments

Comments
 (0)