x360 support/config

Blitz3D Forums/Blitz3D Programming/x360 support/config

ok i'm writing a config prog for my new controllers and i have a problem. the d-pad registers as a hat and i'm using joyhat() to return a number to draw a line with but it wont return the number.
heres the code
Graphics 400,300
SetBuffer BackBuffer()
AutoMidHandle True
cont= LoadImage("controller.bmp")
Const left_stick_pos=88,right_stick_pos=124
Const hat_x=160,hat_y=100
Repeat

ju#=JoyU()
judir=JoyUDir()
jv#=JoyV()
jvdir=JoyVDir()
jyaw#=JoyYaw()
jpitch#=JoyPitch()
jroll#=JoyRoll()
jz#=JoyZ()
jx#=JoyX()
jy#=JoyY()
jxdir#=JoyXDir()
jydir#=JoyYDir()
jzdir#=JoyZDir()
jhat=JoyHat()
button=GetJoy()

DrawImage cont,200,100

 If button <> 0 Then
  Select button
   Case button=1
    Text 0,214, "you hit the A button"
   Case button=2
    Text 0,214,"you hit the B button"
  End Select
 End If
;left stick
If jydir#<>0 Or jxdir#<>0
 Color 255,0,0
 Line 145,left_stick_pos,jx#*200,jy#*200
 Text 0,214,jy#+"   "+jx#
End If
;right stick
If jyaw#<>0 Or jpitch#<>0 
 Color 255,0,0
 Line 230,right_stick_pos,jpitch#*100,jyaw#*100
 Text 0,234,jyaw#+"   "+jpitch#
End If
;Z-triggers
If jzdir#<>0 
 Color 0,0,255
 Line 200,30,200+(-jz#*100),30
 Text 0,254,jz#
End If
;joyhat stuff
 Select jhat
  Case jhat=0
   Color 255,0,0
   Line hat_x,hat_y,hat_x,hat_y-50
   Text 0,274,jhat
   Delay 100
 End Select


Flip
Delay 100
Color 255,255,255
Cls
Forever

and you will need to save both the code and this picture properly if you want to see the cool graphics the way there supposed to be. you need to save it as a bmp named controller.bmp


anyone?

The XBox 360 pad only runs with XInput, not fully DirectInput ... you sadly decided for the wrong pad to work with DX7 - DX9c 07 (the same as owners of other pads have problems with XInput oriented games in most cases)

Is this the same problem as Mr John Pickford is experiencing?

http://www.blitzmax.com/Community/posts.php?topic=77723

Is this post related ?
http://www.blitzbasic.com/Community/posts.php?topic=71496
http://www.blitzbasic.com/Community/posts.php?topic=69681

ok, d-pad isn't totally nesecary but i have ran the joyhat() example and it returns a degree e.g. 180,90,45 so i don't know why my line command isn't working.

try case jhat=0 -> case 0

Not wishing to rain on anyones parade...

May I recommend getting the Joytech rumblepad 2 - and use Pepsi's dll and library - you won't go far wrong and I think rumble is supported too?

It has a complete library of commands which works beautifully.

IPete2.

Just to correct some mis-information,...the 360 pad is awesome, I've had no issues with it. The only thing you don't have access to in DX7 is the rumble features.

The hat on mine is returning -1 in the neutral position, and 0,45,90,... around the different positions.

your current code only checks if joyhat = 0 (up)

edit: removed sample joyhat() code,... see example in next post below.


Also, you may want to consider doing a setup similar to this:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1592

That only uses the analog sticks and triggers, but this method allows you to map *any* controller for your game, instead of having to hard code each controller. It would not be too hard to expand the buttons and hat into this as well.

your line command is not working because your code doesn't have any thing to do.

currently you are only checking if jhat=0 which would be the up position. none of the other angles are being checked for.

edit: here is a code sample that does what you need.




Graphics 400,300,0,2
SetBuffer BackBuffer()

hat_posX= 200
hat_posY= 150
length = 20

While Not KeyHit(1)

	hatvalue = JoyHat()

	If Hatvalue > -1
		Line hat_posX,hat_posY,hat_posX + (Sin(hatvalue) * length),hat_posy - (Cos(hatvalue) * length)

		;these convert the x/y  hat values into -1,0,or 1 (there is probably a better way to do this)

		Text 50,30,"Joyhat() X: " + Int(Sin(hatvalue))
		Text 50,45,"Joyhat() Y: " + Int(Cos(hatvalue))
	
		; X values: right = 1 left = -1
		; Y values: up = 1 down = -1
		
	EndIf

	Text 50,10,"Joyhat() value : " + hatvalue

	Flip
	Cls
Wend