Decreased latency and improved reconnections

This commit is contained in:
Brikwerk 2021-09-22 23:35:30 -07:00
commit 639227ea1d
2 changed files with 4 additions and 4 deletions

View file

@ -242,7 +242,7 @@ class ControllerProtocol():
# Get how many ticks have passed in hex with overflow at 255
# Joy-Con uses 4.96ms as the timer tick rate
elapsed_ticks = int(delta_t // 4.96)
elapsed_ticks = int(delta_t * 4)
self.timer = (self.timer + elapsed_ticks) & 0xFF
self.report[2] = self.timer

View file

@ -165,7 +165,7 @@ class ControllerServer():
self.cached_msg = msg[3:]
# Send a blank packet every so often to keep the Switch
# from disconnecting from the controller.
elif self.tick == 660:
elif self.tick == 2400:
itr.sendall(msg)
self.tick = 0
# print(msg, "tick")
@ -179,7 +179,7 @@ class ControllerServer():
timer_end = time.perf_counter()
elapsed_time = timer_end - timer_start
sleep_time = 1/66 - elapsed_time
sleep_time = 1/240 - elapsed_time
if sleep_time >= 0:
time.sleep(sleep_time)
self.tick += 1
@ -289,7 +289,7 @@ class ControllerServer():
self.bt.remove_device(key)
connected_devices_count[key] = 0
time.sleep(0.25)
time.sleep(0.1)
def connect(self):
"""Configures as a specified controller, pairs with a Nintendo Switch,