.[solved] How are DEVICE_IDs for joysticks generated? [message #5666] |
Sun, 16 September 2018 10:10 |
|
Hi,
I'm trying to write a frontend to onfigure my joypads for mednafen, but I can't figure out where mednafen gets the ID for the joypad.
Is there some formula by which it is created, or any way to read it from the system or get it from sdl?
I'm on linux (manjaro).
A big thank you in advance :3
[Updated on: Mon, 17 September 2018 14:16]
|
|
Re: How are DEVICE_IDs for joysticks generated? [message #5667 is a reply to message #5666 ] |
Sun, 16 September 2018 21:25 |
|
On Linux, joystick ID's are built as follow:
Example: 0x0003046dc21d40140008000b00000000
- First four: bustype (0003)
- Next four: vendor (046d)
- Next four: product (c21d)
- Next four: version (4014)
- Next four: number of axes in hexadecimal (0008)
- Next four: number of buttons in hexadecimal (000b)
- Last eight: zeroes (it will be increased if there are duplicates)
You can get the data from Sysfs (on Manjaro it is into /sys/class/input, with others distros it may vary)
|
|
Re: How are DEVICE_IDs for joysticks generated? [message #5668 is a reply to message #5667 ] |
Mon, 17 September 2018 00:28 |
|
Thank you, I'll try it this evening.
Right now I just parsed mednafen, but getting it fro, the system would be so much cleaner
def getMednafenJoypadIds():
# Start Mednafen without a valid rom to load the nes emulator module,
# and catch the output of its joypad ID.
# The compare thode to the joypad names we get from input and attach them.
output = subprocess.Popen( shlex.split( 'mednafen -remote "###TEST###" "notexistinggamerom.nes"'), cwd = os.path.join( os.path.expanduser( '~')), stderr=subprocess.STDOUT,stdout=subprocess.PIPE).communicate()[0].decode("utf8").split('###TEST###')
for line in output:
if line[0:22] == 'status_message " ID: ':
guid, name = line[22:-5].split(' - ')
for device in devices.gamepads:
if device.name == name:
device.guid = guid
[Updated on: Mon, 17 September 2018 00:29]
|
|
Re: How are DEVICE_IDs for joysticks generated? [message #5669 is a reply to message #5668 ] |
Mon, 17 September 2018 01:11 |
|
The problem with this approach is that various joysticks can have the same name but they always have different ID so you don't know which match.
|
|
Re: How are DEVICE_IDs for joysticks generated? [message #5672 is a reply to message #5666 ] |
Mon, 17 September 2018 14:15 |
|
Hence my wish to replace that crutch
Thank you, this was really helpful, I just digged in and now it all makes sense
|
|