I'd definitely appreciate testers once I get some work done. Actually, if 
you're on Linux, would you mind testing out the bit of code in the attached 
file? You'll have to open a joystick device first in pyglet, then pass it 
to the function. It'll should then give you an sdl2 style GUID. (I just did 
some crude conversion of the available id_*s in pyglet, but I imagine there 
might be a better way to get these values). 

Also, whether or your Windows/Mac/Linux, would you mind sending me the 
id_bustype, id_vendor, id_product, id_version, and name from your 
joysticks? I've no idea if these are the same on other platforms, but I 
will need to figure out how they get converted in any case. 

Thanks! 

On Thursday, October 22, 2015 at 1:57:53 PM UTC+9, Leif Theden wrote:
>
> Ah, I completely misread your post  :D.  Good luck!  That would be a great 
> addition to pyglet.  Let me know if you want a tester... I've got lost of 
> controllers to play with.
>
> On Wednesday, October 21, 2015 at 8:01:45 PM UTC-5, Benjamin Moran wrote:
>>
>> Thanks for the reply, Leif. 
>>
>> What I'm thinking is much simpler than that. I plan on leaving the 
>> existing joystick api in pyglet as-is, and implementing the game controller 
>> api as an abstraction over that (how it's done in SDL). 
>>
>> I've already hacked up a quick script that converts the pyglet joystick 
>> ids to the SDL GUIDs on Linux. I just need to code up the rest of the 
>> abstraction for the game controller buttons and sticks.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
__author__ = 'ben'


def sdl2_gamecontroller_guid(joystick):
    """
    :param joystick: This should be a pyglet Joystick device (Linux only for now)
    :return: The SDL style game controller GUID and device name.
    """
    js_bustype = joystick.device.id_bustype
    js_vendor = joystick.device.id_vendor
    js_product = joystick.device.id_product
    js_version = joystick.device.id_version
    js_name = joystick.device.name

    bustype_hex = format(js_bustype, "02x")[-2:]
    bustype_shifted = str(js_bustype >> 8)[-2:]
    vendor_hex = format(int(js_vendor, 16), "02x")[-2:]
    vendor_shifted = str(int(js_vendor, 16) >> 8)[-2:]
    product_hex = format(int(js_product, 16), "02x")[-2:]
    product_shifted = str(int(js_product, 16) >> 8)[-2:]
    version_hex = format(js_version, "02x")[-2:]
    version_shifted = str(js_version >> 8)[-2:]

    blank_guid = "{:0>2}{:0>2}0000{:0>2}{:0>2}0000{:0>2}{:0>2}0000{:0>2}{:0>2}0000"
    game_controller_guid = blank_guid.format(bustype_hex, bustype_shifted, vendor_hex, vendor_shifted,
                                             product_hex, product_shifted, version_hex, version_shifted)
    return "{} {}".format(game_controller_guid, js_name)

Reply via email to