Added slow frequency mode
This commit is contained in:
parent
18e46646b7
commit
b838bfe9ee
2 changed files with 31 additions and 9 deletions
|
|
@ -47,6 +47,10 @@ class InputParser():
|
|||
|
||||
self.controller_input = None
|
||||
|
||||
# Whether or not input has been entered
|
||||
# that would close the "Change Grip/Order" menu
|
||||
self.exited_grip_order_menu = False
|
||||
|
||||
def buffer_macro(self, macro, macro_id):
|
||||
|
||||
# Doesn't have any info
|
||||
|
|
@ -195,6 +199,11 @@ class InputParser():
|
|||
if len(macro_input) < 2:
|
||||
return
|
||||
|
||||
# Check if the Grip/Order menu would be closed
|
||||
if not self.exited_grip_order_menu and (
|
||||
'A' in macro_input or 'B' in macro_input or 'HOME' in macro_input):
|
||||
self.exited_grip_order_menu = True
|
||||
|
||||
# Arrays representing the 3 button bytes in the
|
||||
# standard input report as binary.
|
||||
upper = ['0'] * 8
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ class ControllerServer():
|
|||
|
||||
self.input = InputParser(self.protocol)
|
||||
|
||||
self.slow_input_frequency = False
|
||||
|
||||
def run(self, reconnect_address=None):
|
||||
"""Runs the mainloop of the controller server.
|
||||
|
||||
|
|
@ -144,16 +146,24 @@ class ControllerServer():
|
|||
timer_end = time.perf_counter()
|
||||
elapsed_time = (timer_end - timer_start)
|
||||
|
||||
# Respond at 120Hz for Pro Controller
|
||||
# or 60Hz for Joy-Cons.
|
||||
# Sleep timers are compensated with the elapsed command
|
||||
# processing time.
|
||||
if self.controller_type == ControllerTypes.PRO_CONTROLLER:
|
||||
if elapsed_time < 1/120:
|
||||
time.sleep(1/120 - elapsed_time)
|
||||
if self.slow_input_frequency:
|
||||
# Check if we can switch out of slow frequency input
|
||||
if self.input.exited_grip_order_menu:
|
||||
self.slow_input_frequency = False
|
||||
|
||||
if elapsed_time < 1/15:
|
||||
time.sleep(1/15 - elapsed_time)
|
||||
else:
|
||||
if elapsed_time < 1/60:
|
||||
time.sleep(1/60 - elapsed_time)
|
||||
# Respond at 120Hz for Pro Controller
|
||||
# or 60Hz for Joy-Cons.
|
||||
# Sleep timers are compensated with the elapsed command
|
||||
# processing time.
|
||||
if self.controller_type == ControllerTypes.PRO_CONTROLLER:
|
||||
if elapsed_time < 1/120:
|
||||
time.sleep(1/120 - elapsed_time)
|
||||
else:
|
||||
if elapsed_time < 1/60:
|
||||
time.sleep(1/60 - elapsed_time)
|
||||
|
||||
def save_connection(self, error, state=None):
|
||||
|
||||
|
|
@ -290,6 +300,9 @@ class ControllerServer():
|
|||
# Pairing cycle responds optimally on a 15Hz loop
|
||||
time.sleep(1/15)
|
||||
|
||||
self.slow_input_frequency = True
|
||||
self.input.exited_grip_order_menu = False
|
||||
|
||||
return itr, ctrl
|
||||
|
||||
def reconnect(self, reconnect_address):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue