Exemplo n.º 1
0
    def main(self):
        '''foo bar'''

        try:
            device = inputs.devices.gamepads[0]
        except IndexError:
            raise inputs.UnpluggedError("No gamepad found.")

        while self.running:
            #print('waiting start')
            # print(device)

            # this is a hack because python inputs only exposes blocking interface meant
            # to be iterated on.
            device._GamePad__check_state()
            events = device._do_iter()
            if events is None:
                continue

            for event in events:
                # print(event)
                self.process(event)

            #print('waiting done')
            time.sleep(0.05)
        print('wait loop exited')
Exemplo n.º 2
0
 def _get_gamepad(self):
     """Get a gamepad object."""
     try:
         devices = inputs.DeviceManager()
         self.gamepad = devices.gamepads[0]
     except IndexError:
         raise inputs.UnpluggedError('No gamepad found.')
Exemplo n.º 3
0
 def _get_gamepad(self):
     """Get a gamepad object."""
     while (not self.gamepad):
         try:
             self.gamepad = inputs.devices.gamepads[0]
         except IndexError:
             print("gamepad not connected, polling for connection")
             raise inputs.UnpluggedError("No gamepad found.")
             time.sleep(.05)  # refreshing at 20 Hz for gamepad connection
Exemplo n.º 4
0
 def __init__(self, connection):
     self.connection = connection
     try:
         self.gamepad = inputs.devices.gamepads[0]
     except IndexError:
         raise inputs.UnpluggedError("No gamepad found.")
     self.button_translation = {
         'BTN_SOUTH': 'A',
         'BTN_EAST': 'B',
         'BTN_WEST': 'X',
         'BTN_NORTH': 'Y',
         'BTN_TL': 'LB',
         'BTN_TR': 'RB',
         'BTN_START': 'SELECT',
         'BTN_SELECT': 'START',
         'ABS_HAT0X': 'DX',
         'ABS_HAT0Y': 'DY',
         'ABS_X': 'LSX',
         'ABS_Y': 'LSY',
         'ABS_RX': 'RSX',
         'ABS_RY': 'RSY',
         'ABS_Z': 'LT',
         'ABS_RZ': 'RT',
         'BTN_THUMBR': 'RSB',
         'BTN_THUMBL': 'LSB'
     }
     self.state = {
         'A': 0,
         'B': 0,
         'X': 0,
         'Y': 0,
         'LB': 0,
         'RB': 0,
         'START': 0,
         'SELECT': 0,
         'DX': 0,
         'DY': 0,
         'LT': 0,
         'RT': 0,
         'LSX': 0,
         'LSY': 0,
         'LSB': 0,
         'RSX': 0,
         'RSY': 0,
         'RSB': 0
     }
Exemplo n.º 5
0
 def _get_gamepad(self):
     """Get a gamepad object."""
     try:
         self.gamepad = inputs.devices.gamepads[0]
     except IndexError:
         raise inputs.UnpluggedError("No gamepad found.")
Exemplo n.º 6
0
 def init_gamepad(self):
     try:
         self.gamepad = inputs.devices.gamepads[0]
     except IndexError:
         raise inputs.UnpluggedError("Gamepad not found.")