-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJamRacerJoystickHandler.py
26 lines (21 loc) · 1.06 KB
/
JamRacerJoystickHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pygame
from InputTrustUSBGamepad import *
class JamRacerJoystickHandler(object):
'''A class to handle the initialisation and usage of USB joypads'''
def __init__(self):
pygame.joystick.init()
self.joysticks = []
if pygame.joystick.get_count() > 0:
# Enumerate joysticks
logging.debug("Found " + str(pygame.joystick.get_count()) + " input devices")
for index in range(0, pygame.joystick.get_count()):
this_joystick = pygame.joystick.Joystick(index)
this_joystick.init()
joyname = this_joystick.get_name()
logging.info("Found input device: " + joyname)
if 'ragon' in joyname:
self.joysticks.append(TrustUSBJoypadController(this_joystick, "Trust USB Gamepad (" + joyname + ")"))
else:
self.joysticks.append(PyGameJoystickController(this_joystick, joyname))
else:
raise JoystickNotConnectedException("No joysticks are attached")