Improved connection reliability

This commit is contained in:
Brikwerk 2021-09-25 22:10:06 -07:00
commit 639f83f9b2

View file

@ -165,7 +165,7 @@ class ControllerServer():
self.cached_msg = msg[3:] self.cached_msg = msg[3:]
# Send a blank packet every so often to keep the Switch # Send a blank packet every so often to keep the Switch
# from disconnecting from the controller. # from disconnecting from the controller.
elif self.tick == 2400: elif self.tick >= 1320:
itr.sendall(msg) itr.sendall(msg)
self.tick = 0 self.tick = 0
# print(msg, "tick") # print(msg, "tick")
@ -179,7 +179,12 @@ class ControllerServer():
timer_end = time.perf_counter() timer_end = time.perf_counter()
elapsed_time = timer_end - timer_start elapsed_time = timer_end - timer_start
sleep_time = 1/240 - elapsed_time duration_end = time.perf_counter()
duration_elapsed = duration_end - duration_start
duration_start = duration_end
self.durations.append(duration_elapsed)
sleep_time = 1/132 - duration_elapsed
if sleep_time >= 0: if sleep_time >= 0:
time.sleep(sleep_time) time.sleep(sleep_time)
self.tick += 1 self.tick += 1
@ -259,6 +264,7 @@ class ControllerServer():
return itr, ctrl return itr, ctrl
def connection_reset_watchdog(self): def connection_reset_watchdog(self):
connected_devices = [] connected_devices = []
connected_devices_count = {} connected_devices_count = {}
while self._crw_running: while self._crw_running:
@ -296,6 +302,12 @@ class ControllerServer():
and creates/accepts sockets for communication with the Switch. and creates/accepts sockets for communication with the Switch.
""" """
# The controller server will continue attempting to connect
# to any Nintendo Switch until the connection procedure fully
# succeeds. This prevents situations where the Switch will
# disconnect during a connection.
while True:
try:
self.state["state"] = "connecting" self.state["state"] = "connecting"
# Creating control and interrupt sockets # Creating control and interrupt sockets
@ -384,6 +396,10 @@ class ControllerServer():
else: else:
time.sleep(1/15) time.sleep(1/15)
break
except OSError as e:
self.logger.debug(e)
self.input.exited_grip_order_menu = False self.input.exited_grip_order_menu = False
return itr, ctrl return itr, ctrl