Help with FreePIE and Xbox360 controller

Official forum for open source FreePIE discussion and development.
Post Reply
lifer86
One Eyed Hopeful
Posts: 4
Joined: Sun Feb 23, 2014 1:25 pm

Help with FreePIE and Xbox360 controller

Post by lifer86 »

I know FreePie is supposed to support Xbox360 controllers by default and I have found a few examples here on the forum but so far I have not been able to make any of them work. Whenever I call upon any of the Xbox360 controller's properties I get "Object has no attribute". Looking through the source of the Xbox360 plugin I can see that I am naming the attributes correctly.

Running:

Code: Select all

def update():
	
	#LMouseClick  
	mouse.leftButton = xbox360.rightTrigger
	#RMouseClick  Zoom In 
	mouse.rightButton = xbox360.leftTrigger
Returns 6: 'GlobalIndexer[XBox360PluginGlobal]' object has no attribute 'rightTrigger'

I know I am probably missing something really simple (as usual), but any help would be appreciated. Thanks.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with FreePIE and Xbox360 controller

Post by CyberVillain »

We support multiple controller so the correct syntax is xbox360[0].rightTrigger
lifer86
One Eyed Hopeful
Posts: 4
Joined: Sun Feb 23, 2014 1:25 pm

Re: Help with FreePIE and Xbox360 controller

Post by lifer86 »

Thank you. I was able to get the script to run, but it doesn't appear to be doing anything at the moment. I have one controller connected and I tried using controller IDs 0-5.

This is the whole script:

Code: Select all

def update():
	
	#LMouseClick  
	mouse.leftButton = xbox360[0].rightTrigger
	#RMouseClick  Zoom In 
	mouse.rightButton = xbox360[0].leftTrigger

	#Esc    Menu
	keyboard.setKey(Key.Escape, xbox360[0].start)
      
	#Space	Jump
	keyboard.setKey(Key.Space, xbox360[0].a)
   
	#R		Reload
	keyboard.setKey(Key.R, xbox360[0].x)
   
	#X		Stance
	keyboard.setKey(Key.X, xbox360[0].b)
   
	#Movement   
	keyboard.setKey(Key.A, xbox360[0].leftStickX < -0.2) #strafe-left
	keyboard.setKey(Key.S, xbox360[0].leftStickY < -0.2) #backward
	keyboard.setKey(Key.D, xbox360[0].leftStickX > 0.2) #strafe-right
	keyboard.setKey(Key.W, xbox360[0].leftStickY > 0.2) #forward   
   
	#MouseLook
	if (math.abs(xbox360.RightStickX) > 0.2):
   		mouse.DeltaX = (xbox360[0].RightStickX - 0.2) * MOUSE_MAX_SPEED
	
	if (math.abs(xbox360.RightStickY) > 0.2):
   		mouse.DeltaY = -(xbox360[0].RightStickY - 0.2) * MOUSE_MAX_SPEED
	   
if starting:
	MOUSE_MAX_SPEED = 1
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with FreePIE and Xbox360 controller

Post by CyberVillain »

You need to hook up the update event on the Xbox plugin to your update function
lifer86
One Eyed Hopeful
Posts: 4
Joined: Sun Feb 23, 2014 1:25 pm

Re: Help with FreePIE and Xbox360 controller

Post by lifer86 »

Sorry for asking so many questions, but I don't seem to be having much luck with this, how do I hook the update event on the Xbox plugin to my update function?

I can see in some of the example scripts that there is a line in the starting section

Code: Select all

android[0].update += update
but when trying to use something similar with the Xbox plugin

Code: Select all

xbox360[0].update += update
It returns

Code: Select all

37: 'XBox360PluginGlobal' object has no attribute 'update'
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with FreePIE and Xbox360 controller

Post by CyberVillain »

Ah, sorry, im not the author of that plugin so no expert on it. Looks like it does not have a update event

So remove the def update() function

or call it on the last line like

Code: Select all

update()
lifer86
One Eyed Hopeful
Posts: 4
Joined: Sun Feb 23, 2014 1:25 pm

Re: Help with FreePIE and Xbox360 controller

Post by lifer86 »

Thanks, I managed to get the basic functionality of my script working. I have one more question though. In my GlovePIE script I had set up some functions to perform after a button on the Xbox 360 controller was held for a period of time (200ms), do you know if there is a way to do this in FreePIE?

The code that worked for me in GlovePIE was as follows

Code: Select all

mouse.MiddleButton = Released(XInput.A) and not Released(HeldDown(XInput.A, 200ms))
keyboard.V = HeldDown(XInput.A, 200ms)
From messing around in FreePIE it doesn't look as if there are any key states for the Xbox360 controller like there are for the keyboard (getKeyDown, getPressed etc) so I am at a loss on how to implement something like that in FreePIE.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with FreePIE and Xbox360 controller

Post by CyberVillain »

Looks like they have missed getPressed functionality in that plugin. We do not have support for detecing if a button have been pressed a ceratin amount of time no.

You can do it like

Code: Select all

import time

if starting:
	pressed = False
	triggered = False
	started = time.time()

if keyboard.getKeyDown(Key.A) and not pressed:	
	pressed = True
	started = time.time()
	
if pressed and not triggered and time.time() - started >= 0.5: #500 ms
	triggered = True
	diagnostics.debug("Triggered")
	
if not keyboard.getKeyDown(Key.A):
	pressed = False
	triggered = False
Post Reply

Return to “FreePIE”