Bug with joystick

Just starting out? Need help? Post your questions and find answers here.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Bug with joystick

Post by dobro »

chez moi j'ai un probleme avec la fonction (I have a problem with the function)
Dz=JoystickAxisZ(0,#PB_Relative) et Dz=JoystickAxisZ(0,#PB_Absolute)

sur mon ThrustMaster T-Flight Stick X (On my ThrustMaster T-Flight Stick X)
Image




la fonction concernant la rotation du manche dans l'axe des Z (Axe de Lacet ) (The function concerning the rotation of the stick in the Z axis (Lace axis))
Image

Dz=JoystickAxisZ(0,#PB_Relative) me renvoi 1 ou -1
alors que (while )
Dz=JoystickAxisZ(0,#PB_Absolute) me renvoi rien du tout ! (Send me nothing at all!)


code exemple : (Example code:)

Code: Select all

; English forum: http://purebasic.myforums.net/viewtopic.php?t=8572&highlight=
; Author: waffle
; Date: 01. December 2003
;I did this to use a joystick with starfleet command
;works with windows too
;AOE has problems with it
;norms global mouser using joystick
Quit.l=0
If InitJoystick()=0
		MessageRequester("Mouser Error","No controller detected",#MB_ICONSTOP)
		End
EndIf
holdingX.l=0
holdingY.l=0
holddelayX.l=0
holddelayY.l=0
lbhold.l=0
rbhold.l=0
Repeat
		If ExamineJoystick(0)
				dx=JoystickAxisX(0,#PB_Absolute)
				dy=JoystickAxisY(0,#PB_Absolute)
				Dz=JoystickAxisZ(0,#PB_Relative)  ; Absolute dont Work !!!! 
				bouton1=JoystickButton(0,1) 
				bouton2= JoystickButton(0,2)
				bouton3=JoystickButton(0,3)
				bouton4=JoystickButton(0,4)
				bouton5=JoystickButton(0,5)
				bouton6=JoystickButton(0,6)
				bouton7=JoystickButton(0,7)
				bouton8=JoystickButton(0,8)
				bouton9=JoystickButton(0,9)
				bouton10=JoystickButton(0,10)
				bouton11=JoystickButton(0,11)
				bouton12=JoystickButton(0,12)
				If bouton1>0 Or bouton2>0
						debug "bouton 1 " +str(bouton1)
						debug "bouton2 " +str(bouton2)
				Endif
				If Dx>0 or DX<0
						debug "X" +str(DX)
				Endif
					If Dy>0 or Dy<0
						debug "Y"+str(DY)
				Endif
				If Dz>0 or Dz<0
						debug "Z" +str(Dz)
				Endif
				
		Endif
Until Quit
; ExecutableFormat=Windows
; EOF
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Bug with joystick

Post by Fred »

I don't have such a Joystick to test and the XBox gamepad works as expected. Is there a joystick emulator we could use to test this ?
benubi
Enthusiast
Enthusiast
Posts: 113
Joined: Tue Mar 29, 2005 4:01 pm

Re: Bug with joystick

Post by benubi »

C'est normal, I believe.

You forgot the 2nd Parameter (Pad) which should be 0 probably.

If you want to call the Joystick functions with the flag you will have to include the pad parameter before.

I suppose the Pad parameter didn't exist back in 2003.

Btw. #pb_absolute = 0, #pb_relative = 1

It read the Z axis from the 2nd pad (0=first, 1=second).

Code: Select all

; English forum: http://purebasic.myforums.net/viewtopic.php?t=8572&highlight=
; Author: waffle
; Date: 01. December 2003
;I did this to use a joystick with starfleet command
;works with windows too
;AOE has problems with it
;norms global mouser using joystick
Quit.l=0
If InitJoystick()=0
		MessageRequester("Mouser Error","No controller detected",#MB_ICONSTOP)
		End
EndIf
holdingX.l=0
holdingY.l=0
holddelayX.l=0
holddelayY.l=0
lbhold.l=0
rbhold.l=0
Repeat
		If ExamineJoystick(0)
				dx=JoystickAxisX(0,0,#PB_Absolute)
				dy=JoystickAxisY(0,0,#PB_Absolute)
				Dz=JoystickAxisZ(0,0,#PB_Relative)  ; Absolute dont Work !!!! 
				bouton1=JoystickButton(0,1) 
				bouton2= JoystickButton(0,2)
				bouton3=JoystickButton(0,3)
				bouton4=JoystickButton(0,4)
				bouton5=JoystickButton(0,5)
				bouton6=JoystickButton(0,6)
				bouton7=JoystickButton(0,7)
				bouton8=JoystickButton(0,8)
				bouton9=JoystickButton(0,9)
				bouton10=JoystickButton(0,10)
				bouton11=JoystickButton(0,11)
				bouton12=JoystickButton(0,12)
				If bouton1>0 Or bouton2>0
						debug "bouton 1 " +str(bouton1)
						debug "bouton2 " +str(bouton2)
				Endif
				If Dx>0 or DX<0
						debug "X" +str(DX)
				Endif
					If Dy>0 or Dy<0
						debug "Y"+str(DY)
				Endif
				If Dz>0 or Dz<0
						debug "Z" +str(Dz)
				Endif
				
		Endif
Until Quit
; ExecutableFormat=Windows
; EOF
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Bug with joystick

Post by Fred »

You're right, i missed it as well while reading the code. Thanks !
Post Reply