(joystick=None)
Poll the joystick slowly (beginning at 1 sample per second)
    and monitor the packet stream for missed packets, indicating
    that the sample rate is too slow to avoid missing packets.
    Missed packets will translate to a lost information about the
    joystick state.
    As missed packets are registered, increase the sample rate until
    the target reliability is reached.
Poll the joystick slowly (beginning at 1 sample per second)
    and monitor the packet stream for missed packets, indicating
    that the sample rate is too slow to avoid missing packets.
    Missed packets will translate to a lost information about the
    joystick state.
    As missed packets are registered, increase the sample rate until
    the target reliability is reached.
Poll the joystick slowly ( beginning at 1 sample per second ) and monitor the packet stream for missed packets indicating that the sample rate is too slow to avoid missing packets . Missed packets will translate to a lost information about the joystick state . As missed packets are registered increase the sample rate until the target reliability is reached .
def determine_optimal_sample_rate(joystick=None):
    """
    Poll the joystick slowly (beginning at 1 sample per second)
    and monitor the packet stream for missed packets, indicating
    that the sample rate is too slow to avoid missing packets.
    Missed packets will translate to a lost information about the
    joystick state.
    As missed packets are registered, increase the sample rate until
    the target reliability is reached.
    """
    # in my experience, you want to probe at 200-2000Hz for optimal
    #  performance
    if joystick is None:
        joystick = XInputJoystick.enumerate_devices()[0]

    j = joystick

    print("Move the joystick or generate button events characteristic of your app")
    print("Hit Ctrl-C or press button 6 (<, Back) to quit.")

    # here I use the joystick object to store some state data that
    #  would otherwise not be in scope in the event handlers

    # begin at 1Hz and work up until missed messages are eliminated
    j.probe_frequency = 1  # Hz
    j.quit = False
    j.target_reliability = .99  # okay to lose 1 in 100 messages

    @j.event
    def on_button(button, pressed):
        # flag the process to quit if the < button ('back') is pressed.
        j.quit = (button == 6 and pressed)

    @j.event
    def on_missed_packet(number):
        print('missed %(number)d packets' % vars())
        total = j.received_packets + j.missed_packets
        reliability = j.received_packets / float(total)
        if reliability < j.target_reliability:
            j.missed_packets = j.received_packets = 0
            j.probe_frequency *= 1.5

    while not j.quit:
        j.dispatch_events()
        time.sleep(1.0 / j.probe_frequency)
    print("final probe frequency was %s Hz" % j.probe_frequency)
def determine_optimal_sample_rate ( joystick = None ) : # in my experience, you want to probe at 200-2000Hz for optimal #  performance if joystick is None : joystick = XInputJoystick . enumerate_devices ( ) [ 0 ] j = joystick print ( "Move the joystick or generate button events characteristic of your app" ) print ( "Hit Ctrl-C or press button 6 (<, Back) to quit." ) # here I use the joystick object to store some state data that #  would otherwise not be in scope in the event handlers # begin at 1Hz and work up until missed messages are eliminated j . probe_frequency = 1 # Hz j . quit = False j . target_reliability = .99 # okay to lose 1 in 100 messages @ j . event def on_button ( button , pressed ) : # flag the process to quit if the < button ('back') is pressed. j . quit = ( button == 6 and pressed ) @ j . event def on_missed_packet ( number ) : print ( 'missed %(number)d packets' % vars ( ) ) total = j . received_packets + j . missed_packets reliability = j . received_packets / float ( total ) if reliability < j . target_reliability : j . missed_packets = j . received_packets = 0 j . probe_frequency *= 1.5 while not j . quit : j . dispatch_events ( ) time . sleep ( 1.0 / j . probe_frequency ) print ( "final probe frequency was %s Hz" % j . probe_frequency )