If that controller is compatible (it probably is) then it should be as easy as setting a reference to the Microsoft.Xna.Framework (you will need to first download and install XNA game studio 3.0 SDK which is free)
Once you do that, you will be able to set the above reference in your code.
Then (as far as sending rumble) it should be as simple as
Code:
GamePad.SetVibration(PlayerIndex.One, 1, 1)
the two 1 values being passed are for the left and right motor (assuming it has 2 vibration motors like the 360 controller does) I would imagine if it only has 1, then one of those values is ignored. The intensity of the vibration is any value from 0.0 (none) to 1.0 (max vibration)
If that controller is compatible (it probably is) then it should be as easy as setting a reference to the Microsoft.Xna.Framework (you will need to first download and install XNA game studio 3.0 SDK which is free)
Once you do that, you will be able to set the above reference in your code.
Then (as far as sending rumble) it should be as simple as
Code:
GamePad.SetVibration(PlayerIndex.One, 1, 1)
the two 1 values being passed are for the left and right motor (assuming it has 2 vibration motors like the 360 controller does) I would imagine if it only has 1, then one of those values is ignored. The intensity of the vibration is any value from 0.0 (none) to 1.0 (max vibration)
I have done Tools -> Add reference -> Microsoft.XNA.Framework.
I then put the following code
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GamePad.SetVibration(PlayerIndex.One, 1, 1)
End Sub
But it says "Name 'GamePad' is not declared" and "Name 'PlayerIndex' is not declared".
It has been a little while since I have worked with it, and I was working with a controller that I knew was supported. However you could try running it in a loop and see if has any effect when you do that.
The application I used it for was polling, meaning it was constantly evaluating the controller state to apply whatever actions were needed.
Maybe it is the controller that is not supported - Im pretty sure that XNA is for Xbox 360 controllers. The one I'm using relies on DirectInput which I don't think the 360 needs??
XNA is basically a wrapper around DirectInput. XNA is actually a wrapper around DirectX. There is no such thing as "managed directx" anymore. It was merged into XNA.
I believe the XNA classes work with ANY device that supports direct input. The rumble thing COULD be different though.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With GamePad.GetState(PlayerIndex.One)
If .Buttons.A = ButtonState.Pressed Then
MessageBox.Show("Button A is pressed")
Else
MessageBox.Show("Button A is NOT pressed, or this doesn't work")
End If
End With
End Sub
as you can see this is code for a button click event. So run your app and on your gamepad, hold down the A button, and then click the button on the form with the mouse. Which message does it give you?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With GamePad.GetState(PlayerIndex.One)
If .Buttons.A = ButtonState.Pressed Then
MessageBox.Show("Button A is pressed")
Else
MessageBox.Show("Button A is NOT pressed, or this doesn't work")
End If
End With
End Sub
as you can see this is code for a button click event. So run your app and on your gamepad, hold down the A button, and then click the button on the form with the mouse. Which message does it give you?
I get "Button A is NOT pressed" if I run that code, no matter which button I push on the xbox controller.
do you know if this controller is setup and installed correctly in Windows? Does it work in games? Does it show up in game controllers in the control panel?
The controller is set up fine. Windows recognises it and I already have some code in my project that gets data from the thumbsticks and recognises button presses.
that code looks the same as what I gave you, so perhaps the original xbox controller simply does not support sending rumble commands. I know it has rumble abilities, but maybe it was something non standard when the original xbox came out. I know this all works fine with a 360 controller, because I have used them personally.
It definitely supports rumble because there is a program in the DirectX SDK that makes the controller rumble depending on where you have moved the mouse - the only problem is that it is written in C#/++ (not sure which) rather than VB.
Also, the XBCD driver that I am using has a little utility with it that allows you to activate the rumble. Come to think of it I think you can activate the rumble from the Windows game controllers control panel applet.
try using just this code to see if you get notifications of button presses when you press one of the A,B,X,Y buttons.
Code:
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ControllerTimer As New Timer
ControllerTimer.Interval = 100
AddHandler ControllerTimer.Tick, AddressOf TimerTick
ControllerTimer.Start()
End Sub
Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs)
If GamePad.GetState(PlayerIndex.One).Buttons.A = ButtonState.Pressed Then
MessageBox.Show("A button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.B = ButtonState.Pressed Then
MessageBox.Show("B button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.X = ButtonState.Pressed Then
MessageBox.Show("X button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.Y = ButtonState.Pressed Then
MessageBox.Show("Y button")
End If
End Sub
End Class
try using just this code to see if you get notifications of button presses when you press one of the A,B,X,Y buttons.
Code:
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ControllerTimer As New Timer
ControllerTimer.Interval = 100
AddHandler ControllerTimer.Tick, AddressOf TimerTick
ControllerTimer.Start()
End Sub
Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs)
If GamePad.GetState(PlayerIndex.One).Buttons.A = ButtonState.Pressed Then
MessageBox.Show("A button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.B = ButtonState.Pressed Then
MessageBox.Show("B button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.X = ButtonState.Pressed Then
MessageBox.Show("X button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.Y = ButtonState.Pressed Then
MessageBox.Show("Y button")
End If
End Sub
End Class
You are probably correct about the original controller not being supported by XNA. I took another look, and it isn't DirectInput that is required of the device, it is XInput (the replacement for DirectInput). So this means that XNA doesn't require the 360 controller per say, but it does require a controller that was built with xinput in mind, which I would imagine the companies that still make these devices for games (like logitech) support now in their new devices.
So it does look like to use the old XBOX controller, you would have to find or create some sort of DirectInput wrapper to expose it to .NET.
You are probably correct about the original controller not being supported by XNA. I took another look, and it isn't DirectInput that is required of the device, it is XInput (the replacement for DirectInput). So this means that XNA doesn't require the 360 controller per say, but it does require a controller that was built with xinput in mind, which I would imagine the companies that still make these devices for games (like logitech) support now in their new devices.
So it does look like to use the old XBOX controller, you would have to find or create some sort of DirectInput wrapper to expose it to .NET.
Or you know... you could get a 360 controller
The code that I linked to in an earlier post, that's a DirectInput wrapper isn't it?
Presumably if I can get input from the controller there isn't much more that needs to be done to send force feedback commands too? (I believe force feedback is part of DirectInput)?
I can't view the zip file because I am not a member there. If you want you can upload the zip here and I can look. My guess is it is either making direct calls to DirectX, or it is using MDX (managed direct x) which is now discontiuned in favor of XNA (Managed Direct X 2.0 was cancelled and rolled into XNA)
You can probably still get the 1.1 version of MDX though if you look around MS site for a download.
My code is identical to the attached code except I have added the following on the bottom:
Oh, and the code for button 1 doesnt work
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
applicationDevice.SendForceFeedbackCommand(ForceFeedbackCommand.SetActuatorsOn)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If labelButtons.Text <> ("") Then
Label3.Text = ("Success")
Else : Label3.Text = ("Fail")
End If