WhiteMagic / JoystickGremlin

A tool for configuring and managing joystick devices.
http://whitemagic.github.io/JoystickGremlin/
GNU General Public License v3.0
322 stars 46 forks source link

Need an example getting value from another stick in current callback #246

Open muchimi opened 5 years ago

muchimi commented 5 years ago

I'm having some difficulty getting the value of a stick from the callback of another stick.

@deco.axis(1) def test_callback(event, joy, vjoy):

read current value from another stick

j = joy["{other stick device GUID here}"]  # blows up here with a "object has no attribute 'ctypes'
v = j.axis(1).value  
# do something useful here
if v > 0:
    vjoy[1].axis(1).value = v
else:
    vjoy[1].axis(1).value = event.value

I also get the same error if I just reference the joystick by index:

j = joy[1] # blows up with the same error -

Not sure why.

Looking for an example that lets me reference the other stick from the vjoy object . I'm doing something wrong for sure but not sure what, and not finding a good example of how to do that i in the custom plugin manual. Using Gremlin 13.3.

muchimi commented 5 years ago

Ok spelunking through the code, found this works:

> >
> >
> > tmthrottle = gremlin.input_devices.JoystickDecorator( TM_THROTTLE_NAME, TM_THROTTLE_GUID, MODE_ALL ) 
> > # where: TM_THROTTLE_GUID is a "{xxx.xxx.xxx.xxx.xxx}" string GUID
>  
> >         # read throttle
> >         j = joy[tmthrottle.device_guid]
> >         v = -j.axis(7).value
> > 

Any other reference blows up as the joystick proxy is only indexed by a GUID, and not by its string representation, and Python's UUID doesn't work here either as it looks like the GUID is the GUID class, not the UUID Python object.

WhiteMagic commented 5 years ago

I'll have to double check if there is an actual issue with that stuff, because I remember talking to someone else about something along similar lines. Though I don't remember if the end result was that it's a bug in Gremlin or that something was being done slightly incorrectly.

If the joystick access works correctly (something I have to double check) and all you need is to create a proper GUID object instance for the lookup from a string representation then the gremlin.profile.parse_guid function should do the trick.

muchimi commented 5 years ago

Yes the issue I was having, which I discovered looking at the source code is that the parameter for the device GUID has to be a Gremlin GUID, not a Python UUID or a string. What got me was the error I was getting in the script was totally unhelpful and misleading - it should really say "dummy you sent me a string, I need a GUID). The method I ended up using as shown in the code sample above works well because the decorator already has the device_guid property as a GUID (not a string). It thus made sense I think to use the decorator device_guid as the indexer.