GlovePIE to FreePIE script conversion

Official forum for open source FreePIE discussion and development.
Post Reply
Mars
One Eyed Hopeful
Posts: 39
Joined: Tue May 14, 2013 3:49 pm

GlovePIE to FreePIE script conversion

Post by Mars »

Hi again,

I've been using the following GlovePIE script to map the mini joystick axis on my Logitech G940 as mouse (the Logitech profiler software allows mapping the mini-stick button as mouse button):

Code: Select all

mouse.DirectInputX = mouse.DirectInputX + 30*deadzone(joystick.dial)
mouse.DirectInputY = mouse.DirectInputY + 30*deadzone(joystick.slider)
I'd like to convert this into its FreePIE equivalent so I can incorporate it into my Zeiss Cinemizer Headtracking script so I don't have to run both GlovePIE & FreePIE. Looked at all the examples but not quite sure what I should be using for this.

Regards

Mars

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

Re: GlovePIE to FreePIE script conversion

Post by CyberVillain »

Mars wrote:Hi again,

I've been using the following GlovePIE script to map the mini joystick axis on my Logitech G940 as mouse (the Logitech profiler software allows mapping the mini-stick button as mouse button):

Code: Select all

mouse.DirectInputX = mouse.DirectInputX + 30*deadzone(joystick.dial)
mouse.DirectInputY = mouse.DirectInputY + 30*deadzone(joystick.slider)
I'd like to convert this into its FreePIE equivalent so I can incorporate it into my Zeiss Cinemizer Headtracking script so I don't have to run both GlovePIE & FreePIE. Looked at all the examples but not quite sure what I should be using for this.

Regards

Mars
Something like this maybe? You will have to test with different values for deadZone and deltaFactor

Code: Select all

if starting:
	deadZone = 10
	deltaFactor = 50

mouse.deltaX = filters.deadband(joystick[0].sliders[0], deadZone) / deltaFactor
Dial maybe is a slider[1] you will have to test, I do not have a joystick test with right now

Mars
One Eyed Hopeful
Posts: 39
Joined: Tue May 14, 2013 3:49 pm

Re: GlovePIE to FreePIE script conversion

Post by Mars »

Thanks!

Mars
One Eyed Hopeful
Posts: 39
Joined: Tue May 14, 2013 3:49 pm

Re: GlovePIE to FreePIE script conversion

Post by Mars »

The following works except the Y axis constantly drifts down and does not center after the ministick is used:

Code: Select all

mouse.deltaX = filters.deadband(joystick[0].sliders[1], deadZone) / deltaFactor
mouse.deltaY = filters.deadband(joystick[0].sliders[0], deadZone) / deltaFactor

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

Re: GlovePIE to FreePIE script conversion

Post by CyberVillain »

Mars wrote:The following works except the Y axis constantly drifts down and does not center after the ministick is used:

Code: Select all

mouse.deltaX = filters.deadband(joystick[0].sliders[1], deadZone) / deltaFactor
mouse.deltaY = filters.deadband(joystick[0].sliders[0], deadZone) / deltaFactor
increased deadzone? maybe you will have to have different deadzones for the two axis, if they differ to much in drift

edit: this worked perfect for my Logitech Rumblepad

Code: Select all

if starting:
	deadZone = 100
	deltaFactor = 1000

mouse.deltaX = filters.deadband(joystick[0].x, deadZone) / deltaFactor
mouse.deltaY = filters.deadband(joystick[0].y, deadZone) / deltaFactor

Mars
One Eyed Hopeful
Posts: 39
Joined: Tue May 14, 2013 3:49 pm

Re: GlovePIE to FreePIE script conversion

Post by Mars »

Yes it simply needed higher values:

deadZone = 200
deltaFactor = 500

Cheers!

Cyborg11
One Eyed Hopeful
Posts: 3
Joined: Tue Sep 17, 2013 4:40 pm

Re: GlovePIE to FreePIE script conversion

Post by Cyborg11 »

Hello guys,

sorry for highjacking this thread but I thought I don't need to open a new thread only for one question.

What is the FreePIE equivalent to this GlovePIE code?

Code: Select all

PPJoy1.analog2 = (MapRange(-Joystick.Z, -1, 1, 0, 1))
I need a solution for VJoy.

Thanks in Advance. :)

Ideka
One Eyed Hopeful
Posts: 1
Joined: Tue Sep 17, 2013 8:49 pm

Re: GlovePIE to FreePIE script conversion

Post by Ideka »

FreePIE may have a function for that built in already, but I wouldn't know so here you go, put this function somewhere:

Code: Select all

def map_range(n, lu, hu, lm, hm):
    return lm + (hm - lm) * float(n - lu) / (hu - lu)
And then you can probably do something like:

Code: Select all

ppJoy[0].setAxis(AxisTypes.X, map_range(-joystick[0].sliders[0], -1, 1, 0, 1))
Not sure about that. The function should work though.

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

Re: GlovePIE to FreePIE script conversion

Post by CyberVillain »

There is no generic util function built in as of current version (Will fix for next release). But both the ppJoy, Joystick plugin has its own range functions so you could do

Code: Select all

if starting:
	joystick[0].setRange(min, max)
	ppJoy[0].setRange(min, max)
If you are usign vJoy you have to get a little more creative because it does not have a setRange function. The range of the vJoy SDK is int16 so do

Code: Select all

from System import Int16

if starting:
	joystick[0].setRange(Int16.MinValue, Int16.MaxValue)
edit: btw, ther i a 5 minute time limit in current version of Vjoy SDK use this dll to disable that
https://github.com/AndersMalmgren/FreeP ... y/VJoy.dll

Cyborg11
One Eyed Hopeful
Posts: 3
Joined: Tue Sep 17, 2013 4:40 pm

Re: GlovePIE to FreePIE script conversion

Post by Cyborg11 »

@Ideka: Thanks for your map_range function. It works great even with vJoy. :)

@CyberVillain: Thanks for the dll. How does the setRange function work? I can't specify an axis with this command so does that mean that all axis are mapped to this range? Maybe I missunderstood this function. :)

I'm using the function provided by Ideka for my script and the axis is mapped correct.
But it doesn't update because the function is in the starting block of the script but I didn't find a way to update the vjoy like other devices such as freetrack.update, etc.

Code: Select all

def map_range(n, lu, hu, lm, hm):
	return lm + (hm - lm) * float(n - lu) / (hu - lu)

if starting:
	vJoy[0].z = map_range(joystick[0].z, 1000, -1000, 0, 1000)
	diagnostics.watch(vJoy[0].z)
Personally I would use a while loop as long as the script runs but is there a better way to do that in Python / FreePie? I'm new at Python but have experience in Java.
EDIT: This loop works but my vJoy doesn't update:

Code: Select all

def map_range(n, lu, hu, lm, hm):
	return lm + (hm - lm) * float(n - lu) / (hu - lu)

def update():
	while (1) :
		vJoy[0].z = map_range(joystick[0].z, 1000, -1000, 0, 1000)

if starting:
	update

diagnostics.watch(vJoy[0].z)
diagnostics.watch(joystick[0].z)

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

Re: GlovePIE to FreePIE script conversion

Post by CyberVillain »

Cyborg11 wrote:...
vJoy is a write only plugin so no update, and joystick uses polling under the hood so now update event there either. So you need to use old fashion polling. The problem with your script is that you use the if starting block. Remove that and it willl work. if starting is only fired the first time and not for the rest. You do not need a while loop since thats taken care of by FreePie. Jus tremove the starting and your set.

And yes setRange is for all axis. Your example above with 1000 wont work very well for vJoy since it expects small int (Int16)

This script should work

Code: Select all

from System import Int16

if starting:
   joystick[0].setRange(Int16.MinValue, Int16.MaxValue)

vJoy[0].z = joystick[0].z
Or with Ideka map range

Code: Select all

from System import Int16

vJoy[0].z = map_range(joystick[0].z, -1000, 1000, Int16.MinValue, Int16.MaxValue)
you cant use while loops like that, it will make FreePIE script thread hang.

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

Re: GlovePIE to FreePIE script conversion

Post by CyberVillain »

filters.mapRange added to FreePIE source, will be in next version

https://github.com/AndersMalmgren/FreeP ... 0b41b73fd1

Cyborg11
One Eyed Hopeful
Posts: 3
Joined: Tue Sep 17, 2013 4:40 pm

Re: GlovePIE to FreePIE script conversion

Post by Cyborg11 »

Thanks for your help. :)

It's very good to have an better alternative to GlovePIE. 8-)

Post Reply

Return to “FreePIE”