Logitech F310 Gamepad and FreePIE

Official forum for open source FreePIE discussion and development.
Post Reply
dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Hi all;
I have been using Freepie/TrackIR for many years with this controller (mostly the Borderlands series) and it works seamlessly. Track Ir gives me precision mous aiming and the gamepads makes moving in the game environment easier than a keyboard. when I touch a button on the F310 it overrides the TrackIR and vice versa. Not so with Battlefield 1 however, If I move too much x or y axis with the controller in this game I end up facing in a random direction. My workaround would be to map the "toggle = keyboard.getPressed(Key.Z)" script to the Left trigger on my Gamepad which controls aim so that it turn on when aiming and off when I exit aim mode (aim mode can be toggled in the game). Can this be done? I have no idea how the script works and have tried a couple of things using joypad[ and xbox360[ with no luck. I have been using the basic script example for trackIR which has served me well

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch
   
    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)   
     
    if (enabled): #if (enabled and hotkey)
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply

if starting:
    enabled = True
    multiply = 19
    trackIR.update += update

hotkey = mouse.rightButton
toggle = keyboard.getPressed(Key.Z)

if toggle:[/quote]
    enabled = not enabled
Please be nice I am not technically minded and just like playing games :)

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

I am afraid I am not sure what exactly are you trying to do... You want the Z key to be pressed as long as trigger is pressed?

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

I want the left trigger on my Gamepad to pause Track IR if that is possible, replacing key Z. Thanks for the reply.

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

I would try something like this:

Code: Select all

if not joystick["Gamepad F310 (Controller)"].getDown(0):
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply
 
You have to change the 0 in the function to the appropriate button.

Note that this should work if the gamepad is in DirectX mode (where triggers are buttons). For the InputX mode both the joystick name and the procedure must be a bit different, as in that mode triggers are analog.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Thanks Jabber. How do I found out what number is assigned to the left trigger on my Gamepad, any ideas? Also I don't think Battlefield 1 recognises the logitech in direct mode. The old Logitech gamepad software causes problems with Windows 11 or I would use that in direct mode. Still, I will give this a go if I can found out what number is assigned to the F310 trigger. Thanks for your time with this.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

OK,I found out it is (7) in direct mode. I am not sure where it goes in the script, this how it is at present.....

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch
   
    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)   
     
    if (enabled): #if (enabled and hotkey)
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply

if starting:
    enabled = True
    multiply = 19
    trackIR.update += update

hotkey = mouse.rightButton
toggle = keyboard.getPressed(Key.Z)

if not joystick["Gamepad F310 (Controller)"].getDown(7):
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply
 
if toggle:
    enabled = not enabled
The ""Gamepad F310 (Controller)" is red in FreePIE, and the script won't run. I probbably have it in the wrong place.

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

I assume that the keyboard toggle and hotkey are no longer required, otherwise it would be a bit complicated to have it both as a toggle and a hold:

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch
   
    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)   
     
    if not joystick["Gamepad F310 (Controller)"].getDown(7):
       mouse.deltaX = deltaYaw*multiply
       mouse.deltaY = -deltaPitch*multiply

if starting:
    multiply = 19
    trackIR.update += update
If the code does not run, open the controller interface in the Control Panel and check how your gamepad is listed.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

In direct mode it is Logitech dual Action. The script runs as I have it below except none of the controller buttons will pause the mouse. With (Controller) included it wont run at all. Also, I may be wasting your time, I can't get Battlefield 1 to recognise the Gamepad in D mode. The new games seem to accept the F310 as an xbox 360 in X mode only. Thanks for trying to help though and sorry to be a nuisance.

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch
   
    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)   
     
    if not joystick["Logitech Dual Action"].getDown(7):
       mouse.deltaX = deltaYaw*multiply
       mouse.deltaY = -deltaPitch*multiply

if starting:
    multiply = 19
    trackIR.update += update

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

They must have changed the firmware, as my F310 reported as above.

In InputX mode it gets a bit more complicated, as triggers are reported as an axis. First you have to figure out what axis it is and what value it reports. Use:
diagnostics.watch(joystick["name_of_your_controller_in_X_mode"].selected_axis)

It should give you the value in the diagnostics tab.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Use: diagnostics.watch(joystick["name_of_your_controller_in_X_mode"].selected_axis)

Hey? I am sorry Jabber I don't know even the basics of script writing or how and where to get that to work. I want to have Track IR working while using aim mode and off while not using aim with this particular game because using TIR with the joypad in BF1 causes problems. I am using Windows 11 which had issues with the old Logitech Gamepad software that you could use to map keys in Direct mode and as far as I know this is my only option other than using a foot pedal to emulate a keyboard key (z) to get TIR to pause but combining the aim (left trigger) on my joypad with on/off toggle seemed to be the way to go.

[Edit] In the Properties for the joypad, the left trigger is Z Axis.

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

I understand that it might be difficult, but I am afraid that my help will be limited without actual access to the hardware. The best way is to experiment, it is really hard to actually do some permanent damage. At worst it will not work...

Run a script with only that line:

diagnostics.watch(joystick["Logitech Dual Action"].z)

On the right side of FreePIE window you have three tabs: Console, Error and Watch. If Watch is selected, running that script should display the values given when fully pressing left trigger.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

It's a no go. I can't get the script to run. I tried the script exactly how you have it and without the inverted commas as well. I also replaced Logitech Dual Action with Gamepad F310 which is what windows seems to call the device when in x mode and no luck there either with or without the inverted commas. Logitech Dual Action is for D mode. When I try to run the script, the watch window closes and script is not running.

I've made a foot pedal out of an old keyboard and a piece of cardboard and am using that to pause/start track IR when aiming with the joypad. It can be complicated especially when people are shooting at me. I will probably have to get used to the just the controller without FreePIE and Track IR when playing a lot of these new games unfortunately. At least it can still work (sort of) with most games, Rage 2 would crash when using Track IR and FreePIE but that was a buggy game anyway so I had to play that controller only.

Thanks anyway jabber if you can point me to some kind of tutorial that explains the parameters and how FreePIE works maybe I can fiddle with it another time without bothering you.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

OK, I was able to almost get what I wanted by modifying the Track IR mouse emulation example and replacing hotkey = mouse.rightButton with hotkey = joystick["Logitech Dual Action"].getDown(6). The value for the left trigger is 6 not 7 and I say almost because this works for D mode which is not accepted by most of my newer games. I f I could find the correct value for the trigger in X mode this will do exactly what I want by activating TrackIR only when I depress the left trigger. Unfortunately, I still can't get the diagnostic to work. Bummer!!

I am very close though which is encouraging.

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch

    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)

    if (enabled and hotkey):
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply

if starting:
    enabled = False
    multiply = 20
    trackIR.update += update

hotkey = joystick["Logitech Dual Action"].getDown(6)
toggle = keyboard.getPressed(Key.Z)

if toggle:
    enabled = not enabled

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

I finaly got the diagnostic to work using your script diagnostics.watch(joystick["Logitech Dual Action"].z). It gave me some readings for the Right-Hand joystick which is Z axis for the gamepad in D mode according to the properties. It must go by a name other than Gamepad F310 because it wont work when I replace Logitech Dual Action with Gamepad F310.
Last edited by dsmith71 on Fri Dec 09, 2022 6:41 pm, edited 1 time in total.

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

The controller has different names in DirectX mode and InputX mode. To check the name of the controller in InputX mode, switch to it and open the Control Panel window, the one in the first picture here:

https://www.top-password.com/blog/open- ... indows-10/

Alternately, you can also just use a number, e.g. joystick[0]. I use names because I usually have several controllers and Windows inconsistently assigns them numbers, but if you have only one, that should work.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

It says Controller (Gamepad F310). Gamepad F310 is what I have been using as a name and it don't work so I will try your suggestion. Thanks again jabber.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Your suggestion worked and as I depress the left trigger it shows a range of values from 0 - 1000 on Z axis. Now what do I do with that information.? :D

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

In my earlier example which worked in D mode I replaced the line: joystick["Logitech Dual Action"].getDown(6) with joystick[0].getDown(z), joystick[0].getDown(.z), joystick["Gamepad F310"].getDown(z) and joystick["Gamepad F310"].getDown(.z). none of these work. Sure wish I knew what I was doing. Lol!

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

The following script enables Track IR with my Logitech F310 joypad in X mode for buttons 1-9. NOT the Axes however. So Controller (Gamepad F310) is how my system recognises the controller, that is now sorted. I just need to find what label is given to the trigger in X mode. Even though the diagnostic worked for "z" as the trigger button, it doesn't work elsewhere. hmmmmmmm.........

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch

    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)

    if (hotkey):
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply

if starting:
    enabled = True
    multiply = 20
    trackIR.update += update

hotkey = joystick["Controller (Gamepad F310)"].getDown(9)

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Running the diagnostic as below shows the left trigger as working so it should be z....shouldn't it? Except it don't work in my other script for enabling TrackIR. Grrrrrrrr!!

Code: Select all

diagnostics.watch(joystick["Controller (Gamepad F310)"].z)

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Success!!! :D :D :D :D I transferred part of the script that worked which was used for diagnosing the Z Axis (Left Trigger) assigning it to the Hotkey and it works!!!! I have no idea why but now TrackIR Pauses when my finger is NOT on the Left trigger and activates when I aim (depress left trigger). Thanks for your help with this Jabber, i don't know where you are but I solved the problem with some perseverance :D :D

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch

    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)

    if (hotkey):
        mouse.deltaX = deltaYaw*multiply
        mouse.deltaY = -deltaPitch*multiply

if starting:
    enabled = True
    multiply = 20
    trackIR.update += update

hotkey = (joystick["Controller (Gamepad F310)"].z)
[Edit] After testing this script in Battlefield 1 I realised that the right trigger also activates Track IR when depressed. After running the diagnostic script from earlier on Axis Z again, I found that LT return the values 0-1000 and RT is 0- -1000 so they are both the same axis. I have no idea how to isolate this to LT only and it is actually useful this way not having to aim to use TrackIR, I will leave it as is.
Last edited by dsmith71 on Sun Dec 11, 2022 10:23 pm, edited 1 time in total.

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

Sorry for not responding earlier, but I was away...

Do not get it wrong, but it would really save you a lot of time to read about the basics, as then you would know what you are doing. But I might also have been a more thorough in my explanations...

The difference between DirectX and InputX is that one outputs the triggers as binary values and the other as an axis. So e.g. the function:

Code: Select all

joystick["Gamepad F310 (Controller)"].getDown(7)
returns a binary value of the press of the button (or boolean, true/false value) - if it is 1 (true), then the button is depressed, if 0, it is not pressed.

The function

Code: Select all

diagnostics.watch(joystick["Controller (Gamepad F310)"].z)
returns the value as an analog value - it shows how much left or right trigger is pressed. If none of the triggers are pressed, it is zero. If left is pressed, then it goes to positive values up to 1000. If right is pressed, it goes from 0 to -1000.

In DirectX we had our condition:

Code: Select all

if not joystick["Logitech Dual Action"].getDown(7)
this means: if the value of pressing is NOT true, then do the mouse thing. But if it is true (i.e. the button is pressed), stop doing that (i.e. pause TrackIR). We could also write:

Code: Select all

if joystick["Logitech Dual Action"].getDown(7) == 0
it would be exactly the same.

For the axis it could not work, of course, as we need to test the specific value. When the left trigger is fully pressed, then it is 1000. So the mouse functions should only work if the value is different than this one. Given that it is the extreme value, we can just check if the actual value is lower than this one:

Code: Select all

def update():
    yaw = trackIR.yaw
    pitch = trackIR.pitch
   
    deltaYaw = filters.delta(yaw)
    deltaPitch = filters.delta(pitch)   
     
    if (joystick["Controller (Gamepad F310)"].z) < 1000:
       mouse.deltaX = deltaYaw*multiply
       mouse.deltaY = -deltaPitch*multiply

if starting:
    multiply = 19
    trackIR.update += update
Of course, given that the value is analog, you do not even have to press it fully - to make it work when it is pressed two/thirds of the way, you can use e.g. < 750.

The problem is that if you press the left trigger AND the right trigger, the value will not be 1000 anymore. If you press both fully, the value will be zero again - as the left trigger adds to the value and the right one subtracts. This is because both triggers work as a single axis.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

Thanks for the explanation Jabber and I am thinking now there is one more script that would be even more useful than using the LT to start TIR. I want to try and make TIR pause when moving the right Gamepad Stick up/down and left/right (in X mode of course). This is because there are a few games, including Battlefield 1 that get confused if I try and use Right stick while TIR is working. I end up facing in a random direction which is usually with my back to the people shooting at me and that is really annoying. The Script I came up with most recently is a work-around for it but I have to remember to release the trigger before using right stick otherwise I do some kind of pirouette in the game LOL! I just finished work so my head is a bit too fuzzy to take in all you have told me ATM, it will have to wait until the weekend.
Jabberwock wrote: Sun Dec 11, 2022 6:18 am Do not get it wrong, but it would really save you a lot of time to read about the basics, as then you would know what you are doing.

I did ask earlier on this thread if someone could point me to a Tutorial or instructions. I am especially interested now in making one final script so solve the problem I just mentioned. If you can link me to instructions for FreePIE script that would be awesome, I had a look on Github but couldn't find it there. Thank you once again.

Jabberwock
Cross Eyed!
Posts: 182
Joined: Mon Mar 02, 2015 3:58 pm

Re: Logitech F310 Gamepad and FreePIE

Post by Jabberwock »

If you know nothing about programming, you should know that FreePIE uses Python for scripting. A very general source can be found here:

https://www.python.org/about/gettingstarted/

Note though that FreePIE uses still Python 2, so there might be some slight syntax differences from Python 3.

Specifically for FreePIE, start with this page:

https://andersmalmgren.github.io/FreePIE/

Read the page linked at Scripting, it details some specifics. I suppose you have seen the script examples, but they are still worth studying.

The script you have in mind should be relatively simple, you just need to check whether one of the stick axes OR the other one is different than zero. If you need further help, just ask, I pop in here from time to time. Unfortunately, FreePIE is not as popular as it once was, it seems I am one of the few people who still do. I am not sure why, as scripting is still quite useful in games and there are few comparable solutions.

dsmith71
One Eyed Hopeful
Posts: 17
Joined: Thu Dec 01, 2022 7:38 pm

Re: Logitech F310 Gamepad and FreePIE

Post by dsmith71 »

You've been a great help Jabber thank you.
Jabberwock wrote: Mon Dec 12, 2022 2:41 am The script you have in mind should be relatively simple, you just need to check whether one of the stick axes OR the other one is different than zero. If you need further help, just ask, I pop in here from time to time. Unfortunately, FreePIE is not as popular as it once was, it seems I am one of the few people who still do. I am not sure why, as scripting is still quite useful in games and there are few comparable solutions.
I don't know why it is not popular either, using TrackIR with a joypad is the best way IMO to play a shooter game when it works which is most of the time. I thought the Axes were X & Y for the right stick but it seems that is for the left stick on the F310. I will delve into it more on the weekend when there is more time and will have questions I am sure then.

Post Reply

Return to “FreePIE”