Accessing joysticks by name

Official forum for open source FreePIE discussion and development.
Post Reply
HarvesteR
One Eyed Hopeful
Posts: 19
Joined: Mon Jun 15, 2015 10:30 am

Accessing joysticks by name

Post by HarvesteR »

Hi,

I've been poking at the FreePIE source again.

I've noticed recently that because of the unhealthy number of input devices I have on my PC, I frequently find myself having to unplug them in order to make devices further on the list visible to games that only support a limited number of devices. However, because of this, the indices for each device frequently changes, forcing me to revise the indices on every game script here whenever I change the connected hardware.

To improve that situation, I tweaked FreePIE to allow me to write a couple of methods to allow finding and storing an accessor to a joystick, by name, like this:

Code: Select all

import harvutil

if (starting):
    global getSidePanel
    getSidePanel = harvutil.get_joystick_accessor("Saitek Side Panel Control Deck", joystick)

    global getPedals
    getPedals = harvutil.get_joystick_accessor("Saitek Pro Flight Rudder Pedals", joystick)

#steering
vJoy[0].y = getPedals().zRotation * 16.4 + \
                (getSidePanel().xRotation * 16.4 * (1 + (0.7 * abs(getSidePanel().yRotation) / 1000))) 

#accel/brakes
vJoy[0].x = (getSidePanel().yRotation * 16.4 * (1 + (0.7 * abs(getSidePanel().xRotation) / 1000))) + \
                filters.mapRange(getPedals().y, -1000, 1000, 0, -16354) + \
                filters.mapRange(getPedals().x, -1000, 1000, 0, 16354)
No more fumbling with device indices! :)

This can't be done in stock FreePIE v1.9.611.0, as joystick devices don't expose their names to python. I've added that field on my GH fork, and created a pull request for Anders to have a look at (whenever you've got time :) ):

https://github.com/AndersMalmgren/FreePIE/pull/73

Example code on how to use joystick accessors is included in the pull request description. If you want this feature right now, you can check out my fork and recompile. Then set up your game scripts as in the example.

Have fun!

Cheers
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Accessing joysticks by name

Post by CyberVillain »

Thanks for the idea, I have made a branch were FreePIE takes care of all the plumbing for this, now you can index on position in list or by name
HarvesteR
One Eyed Hopeful
Posts: 19
Joined: Mon Jun 15, 2015 10:30 am

Re: Accessing joysticks by name

Post by HarvesteR »

Checked out your branch! That is awesome! :D

Code: Select all

diagnostics.watch(joystick["Saitek Side Panel Control Deck"].x)
Doing this is now possible!

Many thanks!

Cheers
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Accessing joysticks by name

Post by CyberVillain »

Glad it worked for you.

You can also do

Code: Select all

pedals = joystick["Saitek Side Panel Control Deck"]
diagnostics.watch(pedals.x)
Our code completion in FreePIE isnt smart enough to help you with code completion on the pedals instance however
matzie
One Eyed Hopeful
Posts: 10
Joined: Thu Jan 14, 2016 3:59 am

Re: Accessing joysticks by name

Post by matzie »

I'd really like to make use of this feature, but I'm not experienced with dev on Windows and don't know how to build FreePIE from github. Is there a build / deps doc somewhere I can follow? I'm a Linux devops engineer, reluctantly using Windows for Star Citizen :-) Alternatively if someone could make me a binary installer from the IndexOnJoystickName branch I'd really appreciate it!

cheers

Matt
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Accessing joysticks by name

Post by CyberVillain »

Im overdue with a new release of FreePIE but my plan was to find time to incorprate the xbox input plugin into FreePIE before release. Give me a sec to build the version with name indexing
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Accessing joysticks by name

Post by CyberVillain »

Here it is, do not forget to unblock the dll othewise FreePIE will crash
You do not have the required permissions to view the files attached to this post.
matzie
One Eyed Hopeful
Posts: 10
Joined: Thu Jan 14, 2016 3:59 am

Re: Accessing joysticks by name

Post by matzie »

That's brilliant, thanks!

I've been playing with something today that I think will go nicely with this - classes for named buttons on various controllers, to provide syntactic sugar like this:

Code: Select all

class WarthogThrottle(NamedController):
	def __init__(self, joyId):
		super(WarthogThrottle,self).__init__(joyId=joyId)
		self.buttons={
						'micswitch':2,
						'lgwarn':21
					 }

if starting:

	throttle = WarthogThrottle(joyId=2) #this is why I wanted named controller support, as my joyId's change frequently :-)
	stick	 = WarthogStick  (joyId=3)
											
			
if throttle.lgwarn.getPressed():
	diagnostics.debug('Pressed L/G Warn')

vJoy[0].setButton(0,throttle.lgwarn() )   #__call__ in base class delegates to .getDown()

early days for this but I'll post it all soon when I've ironed out a few kinks. Currently making heavy use of functools.partial, which isn't the easiest for new coders to follow but hopefully the point of this is to provide a nice abstraction so we can get on with gaming instead of coding :-)

cheers

Matt
matzie
One Eyed Hopeful
Posts: 10
Joined: Thu Jan 14, 2016 3:59 am

Re: Accessing joysticks by name

Post by matzie »

My initial work on this (named controls) is now up on Github here: https://github.com/WastedTruth/ACTools

Things are likely to change a lot in the next few days so consider this a preview :-)
FrenchyKiel
One Eyed Hopeful
Posts: 47
Joined: Thu Oct 03, 2013 7:10 am

Re: Accessing joysticks by name

Post by FrenchyKiel »

its good job..

for the leds of throttle warthog i have found a solution with HIDSHARP to control the led. i put the code on github soon (new plugin inside freepie, plugin named 'warthog')
so no need to use target
matzie
One Eyed Hopeful
Posts: 10
Joined: Thu Jan 14, 2016 3:59 am

Re: Accessing joysticks by name

Post by matzie »

Thanks FrenchyKiel, that sounds great and I'm looking forward to seeing your code - though as I'm not really familiar with windows dev or .net etc, I'll probably look to replicate that feature in pure python, using your work as a guide. I was expecting control of the LEDs to be the only thing I'd need TARGET for - not that I'm particularly opposed to it, but I wanted this NamedControllers stuff to work for anything, not just TM kit.

Here's a discussion about my code on Reddit, with a few more comments and examples: https://www.reddit.com/r/hotas/comments ... r_freepie/
zeeker
One Eyed Hopeful
Posts: 3
Joined: Fri Dec 20, 2013 12:58 am

Re: Accessing joysticks by name

Post by zeeker »

:woot
If, i have multiple devices of the same joystick, like two Logitech Attack 3, or some Genius Joystick named "USB 3-Axis 4-Button Joystick" or an adapter for Two or Four Ps2 Gamepads, like the Mayflash, "TigerGame PS/PS2 Game Controller Adapter".

How we can identify them separately in a freepie script code?
You do not have the required permissions to view the files attached to this post.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Accessing joysticks by name

Post by CyberVillain »

You will have to use positional index for those, sorry

edit: Maybe there is some serial number or somethign that we can access, dont know, will check :D
HarvesteR
One Eyed Hopeful
Posts: 19
Joined: Mon Jun 15, 2015 10:30 am

Re: Accessing joysticks by name

Post by HarvesteR »

Devices have instance ids, which (IINM), are unique even if their names aren't. Not sure exactly how to expose that to scripts though, I don't think those ids are peristent across sessions. There are other ids on the device class though, something in there might be what you need.

Cheers!
Dave_
One Eyed Hopeful
Posts: 3
Joined: Fri May 18, 2018 6:59 am

Re: Accessing joysticks by name

Post by Dave_ »

Hi all!

FreePie turned out to be very very useful for customizing controls, customize headtracking, have joystick/throttle beeps etc.etc.

I really liked the idea of being able to access joysticks by name instead of an index which sometimes changes but after searching the web i couldn't find a snippet where it's being used with the 1.10 build. The code here results in errors, how do i use the name-indexed joysticks? I'm trying to get it to work with my X-55 stick/throttle, works fine if i index the stick/throttle. I also noticed windows reports different names for the X-55 gear, in device manager the stick is named 'X-55 Rhino Stick' but under Printers and Devices it's listed as 'Pro Flight X-55 Rhino Stick'. Which name should be used (in working name-indexed code)?
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Accessing joysticks by name

Post by Jabberwock »

Here is some code that works for me:

Code: Select all

GT = joystick["Game-Trak V1.3"]
vJ = vJoy[0] 
diagnostics.watch(GT.yRotation + GT.y)
vJ.x = filters.ensureMapRange(GT.zRotation - GT.z, 500, -500, -16382, 16382)
vJ.y = filters.ensureMapRange(GT.yRotation + GT.y, -2000, 2000, -16382, 16382)
I always use the name given in the controller configuration window. Note though that I am still on Windows 7.
Dave_
One Eyed Hopeful
Posts: 3
Joined: Fri May 18, 2018 6:59 am

Re: Accessing joysticks by name

Post by Dave_ »

Thank you!

I'm trying this:

Code: Select all

global stick;
stick = joystick["Pro Flight X-55 Rhino Stick"];
diagnostics.watch(stick.x);
Then i get a System.MissingMemberException 'NoneType' has no attribute 'x'. I can only assume the name is wrong, tried what's in the code and 'X-55 Rhino Stick', 'X-55 Rhino Stick (Bulk)', 'X-55 Rhino Stick (HID)' but those fail. I'm on windows 10 and i don't see any other name for the stick anywhere.
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Accessing joysticks by name

Post by Jabberwock »

Can you check the registry? For example, the name for GameTrak is here (the last part is different for each controller driver) under the OEMName entry:

HKEY_CURRENT_USER\System\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM\VID_0982&PID_0982

I believe it is the source for the names in this window:

Image
Dave_
One Eyed Hopeful
Posts: 3
Joined: Fri May 18, 2018 6:59 am

Re: Accessing joysticks by name

Post by Dave_ »

Yes that's it! It was 'Saitek Pro Flight X-55 Rhino Stick', thank you!! :D
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Accessing joysticks by name

Post by Jabberwock »

Glad I could help. :)

So the stick actually functions in the system under three names? With that price tag one might think they would hire a decent software guy...
Post Reply

Return to “FreePIE”