30
30
import uinput
31
31
32
32
from argparse import ArgumentParser
33
- from ctypes import create_string_buffer , byref , POINTER , c_int
33
+ from ctypes import create_string_buffer , byref
34
34
from configparser import ConfigParser
35
35
from sdl2 import joystick , events , version , \
36
36
SDL_WasInit , SDL_Init , SDL_QuitSubSystem , SDL_GetError , \
39
39
SDL_JOYDEVICEADDED , SDL_JOYDEVICEREMOVED , SDL_QUIT , \
40
40
SDL_JOYBUTTONDOWN , SDL_JOYBUTTONUP , SDL_JOYHATMOTION , SDL_JOYAXISMOTION , \
41
41
SDL_GetTicks
42
- from sdl2 .dll import _bind , nullfunc
43
- from sdl2 .stdinc import Uint16
44
42
45
43
logging .basicConfig (level = logging .INFO , format = u"%(asctime)s %(levelname)-6s %(message)s" )
46
44
LOG = logging .getLogger (__name__ )
@@ -120,19 +118,15 @@ class InputDev(object):
120
118
Class representing a joystick device config.
121
119
Maps the inputs of the device to event names
122
120
name: the device's name
123
- guid: the GUID, as returned by SDL
124
- pid: the ProductID of the device
125
- vid: the VendorID of the device
121
+ guid: the GUID, as retuned by SDL
126
122
hats - a dictionary of { <HatNo>: list(<HatValue>, <Event>) }
127
123
buttons - a dict of { <ButtonNo>: <Event> }
128
124
axis - a dict of { <AxisNo>: list(<AxisDirection>, <Event>) }
129
125
"""
130
126
131
- def __init__ (self , _name : str , _vid : int , _pid : int ):
127
+ def __init__ (self , _name : str , _guid : str ):
132
128
self .name = _name
133
- self .guid = None
134
- self .vid = _vid
135
- self .pid = _pid
129
+ self .guid = _guid
136
130
self .axis = {}
137
131
self .buttons = {}
138
132
self .hats = {}
@@ -159,7 +153,7 @@ def get_axis_event(self, index: int, value: int) -> list:
159
153
return None
160
154
161
155
def __str__ (self ) -> str :
162
- return str (f'{ self .name } (P: { self . pid } , V: { self . vid } ) , hats: { self .hats } , buttons: { self .buttons } , axis: { self .axis } ' )
156
+ return str (f'{ self .name } , hats: { self .hats } , buttons: { self .buttons } , axis: { self .axis } ' )
163
157
164
158
165
159
def generic_event_map (input : str , event_map : dict ) -> str :
@@ -233,7 +227,7 @@ def get_all_ra_config(def_buttons: list) -> list:
233
227
"""
234
228
ra_config_list = []
235
229
# add a generic mapping at index 0, to be used for un-configured joysticks
236
- generic_dev = InputDev ("*" , None , None )
230
+ generic_dev = InputDev ("*" , "*" )
237
231
generic_dev .add_mappings (
238
232
{}, # no axis
239
233
{0 : 'b' , 1 : 'a' , 3 : 'y' , 4 : 'x' }, # 4 buttons
@@ -242,7 +236,7 @@ def get_all_ra_config(def_buttons: list) -> list:
242
236
ra_config_list .append (generic_dev )
243
237
js_cfg_dir = CONFIG_DIR + '/all/retroarch-joypads/'
244
238
245
- config = ConfigParser (delimiters = "=" , strict = False , interpolation = None , converters = { 'int' : ( lambda s : s . strip ( '"' ))} )
239
+ config = ConfigParser (delimiters = "=" , strict = False , interpolation = None )
246
240
for file in os .listdir (js_cfg_dir ):
247
241
# skip non '.cfg' files
248
242
if not file .endswith ('.cfg' ) or file .startswith ('.' ):
@@ -253,12 +247,8 @@ def get_all_ra_config(def_buttons: list) -> list:
253
247
config .clear ()
254
248
# ConfigParser needs a section, make up a section to appease it
255
249
config .read_string ('[device]\n ' + cfg_file .read ())
256
- LOG .debug (f'Parsing config "{ file } "' )
257
250
conf_vals = config ['device' ]
258
251
dev_name = conf_vals ['input_device' ].strip ('"' )
259
- # fallback to None if there are no PID/VID in the configuration
260
- dev_vid = conf_vals .getint ('input_vendor_id' , None )
261
- dev_pid = conf_vals .getint ('input_product_id' , None )
262
252
263
253
# translate the RetroArch inputs from the configuration file
264
254
axis , buttons , hats = {}, {}, {}
@@ -278,10 +268,9 @@ def get_all_ra_config(def_buttons: list) -> list:
278
268
axis .setdefault (input_index , []).append ((input_value , event_name ))
279
269
else :
280
270
continue
281
- ra_dev_config = InputDev (dev_name , dev_vid , dev_pid )
271
+ ra_dev_config = InputDev (dev_name , None )
282
272
ra_dev_config .add_mappings (axis , buttons , hats )
283
273
ra_config_list .append (ra_dev_config )
284
- LOG .debug (f'Added config for "{ dev_name } " from "{ file } "' )
285
274
except Exception as e :
286
275
LOG .warning (f'Parsing error for { file } : { e } ' )
287
276
continue
@@ -381,16 +370,12 @@ def handle_new_input(e: SDL_Event, axis_norm_value: int = 0) -> bool:
381
370
stick = joystick .SDL_JoystickOpen (event .jdevice .which )
382
371
name = joystick .SDL_JoystickName (stick ).decode ('utf-8' )
383
372
guid = create_string_buffer (33 )
384
- vid = joystick .SDL_JoystickGetVendor (stick )
385
- pid = joystick .SDL_JoystickGetProduct (stick )
386
-
387
373
_SDL_JoystickGetGUIDString (joystick .SDL_JoystickGetGUID (stick ), guid , 33 )
388
- LOG .debug (f'Joystick #{ joystick .SDL_JoystickInstanceID (stick )} { name } (P: { pid } , V: { vid } ) added' )
374
+ LOG .debug (f'Joystick #{ joystick .SDL_JoystickInstanceID (stick )} { name } added' )
389
375
conf_found = False
390
- # try to find a configuration for the joystick, based on name, GUID and Vendor/Product IDs
376
+ # try to find a configuration for the joystick
391
377
for key , dev_conf in enumerate (configs ):
392
- if dev_conf .name == str (name ) or dev_conf .guid == guid .value .decode () or \
393
- (dev_conf .pid == str (pid ) and dev_conf .vid == str (vid )):
378
+ if dev_conf .name == str (name ) or dev_conf .guid == guid .value .decode ():
394
379
# Add the matching joystick configuration to the watched list
395
380
active_devices [joystick .SDL_JoystickInstanceID (stick )] = (key , stick )
396
381
LOG .debug (f'Added configuration for known device { configs [key ]} ' )
@@ -612,16 +597,6 @@ def signal_handler(signum, frame):
612
597
if joystick .SDL_NumJoysticks () < 1 :
613
598
LOG .debug (f'No available joystick devices found on startup' )
614
599
615
- # 'SDL_JoystickGetVendor' and 'SDL_JoystickGetProduct' are not in PySDL2 before 0.9.6
616
- # so add a local implementation for them when they're not found
617
- if 'SDL_JoystickGetVendor' not in dir (joystick ):
618
- LOG .debug (f'Function "SDL_JoystickGetVendor" not found in PySDL2 { wrapper_version } , adding a local definition for it' )
619
- joystick .SDL_JoystickGetVendor = _bind ("SDL_JoystickGetVendor" , [POINTER (joystick .SDL_Joystick )], Uint16 , nullfunc )
620
-
621
- if 'SDL_JoystickGetProduct' not in dir (joystick ):
622
- LOG .debug (f'Function "SDL_JoystickGetProduct" not found in PySDL2 { wrapper_version } , adding a local definition for it' )
623
- joystick .SDL_JoystickGetProduct = _bind ("SDL_JoystickGetProduct" , [POINTER (joystick .SDL_Joystick )], Uint16 , nullfunc )
624
-
625
600
event_loop (configs , joy_map )
626
601
627
602
SDL_QuitSubSystem (SDL_INIT_JOYSTICK )
0 commit comments