PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Joystick Button Position senden



Projekt 2252
19.02.2011, 19:21
Hallo Leute ich weiß nicht ob das hir richtig ist da es um SharpDevelop und bascom geht aber ich hoffe es :D. Meine Frage ist wie ich es im Code bei Develop so hinbekomme das ich die Position der Buttons sende ich habe es bis jetzt so versucht:

SerialPort1.Write(state.buttonxxx)
serialPort1.Write(chr(13))

aber beim ausführen kommt immer : buttonxxx is not a member of
Microsoft.DirectX.JoystickState.(BC30456)

Wäre nett, wenn ihr mir weiterhelfen könntet .
Gruß Tjark

hegg
22.02.2011, 00:12
hi,

bin auch grad an so nem projekt. hier die loesung allerdings in vb, sollte jedoch ich c# nich viel anders sein

SerialPort1.Write(state.GetButtons(0) & chr(13)) 'button 1
SerialPort1.Write(state.GetButtons(1) & chr(13)) 'button 2
SerialPort1.Write(state.GetButtons(2) & chr(13)) 'button 3
SerialPort1.Write(state.GetButtons(3) & chr(13)) 'button 4

mfg mario

Projekt 2252
03.01.2012, 23:01
Ok und wie benutze ich die Befehle jetzt in Basecom also wie kann ich dem Controller sagen wenn Button1 gedrückt wird......
Gruß Tjark

Projekt 2252
15.05.2012, 22:15
So Jetzt ist er endlich Fertig Alles 4 Achsen und die Button Position :D
Gruß Tjark

'
' Erstellt mit SharpDevelop.
' Benutzer: Tjark Möller •.•
' Datum: 03.03.2012
' Zeit: 20:32
'
' Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
'
Imports System
Imports System.Windows.Forms
Imports Microsoft.DirectX.DirectInput
Imports Microsoft.DirectX




Public Partial Class MainForm
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
serialport1.open
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
Private applicationDevice As Device = Nothing
Public Shared state As New JoystickState()




Public Function InitDirectInput() As Boolean



dim instance As DeviceInstance
For Each instance In Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)
applicationDevice = New Device(instance.InstanceGuid)
Exit For
Next instance


applicationDevice.SetDataFormat(DeviceDataFormat.J oystick)
applicationDevice.SetCooperativeLevel(Me, CooperativeLevelFlags.Exclusive Or CooperativeLevelFlags.Foreground)
Dim d As DeviceObjectInstance
For Each d In applicationDevice.Objects
If 0 <> (d.ObjectId And CInt(DeviceObjectTypeFlags.Axis)) Then
' Set the range for the axis.
applicationDevice.Properties.SetRange(ParameterHow .ById, d.ObjectId, New InputRange(+1000, +2000))
End If
Next d
Return True
End Function 'InitDirectInput
Public Sub GetData()
If Nothing Is applicationDevice Then
Return
End If
Try
applicationDevice.Poll()
Catch inputex As InputException
If TypeOf inputex Is NotAcquiredException Or TypeOf inputex Is InputLostException Then
Try
applicationDevice.Acquire()
Catch
Return
End Try
End If
End Try
Try
state = applicationDevice.CurrentJoystickState
Catch
Return
End Try



End Sub



Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
InitDirectInput
End Sub

Sub Timer1Tick(ByVal sender As Object, ByVal e As EventArgs)
GetData()
label1.Text="X = "+state.X.ToString()
label2.Text="Y = "+state.Y.ToString()
label3.Text="Z = "+state.Z.ToString()
label4.Text="Rz = "+state.Rz.ToString()
Label5.Text ="Button1 = "+state.GetButtons(0).Tostring
if serialport1.IsOpen then
serialport1.Write ("X" + (state.X).tostring + Chr(13))
serialport1.Write ("Y" + (state.Y).tostring + Chr(13))
serialport1.Write ("Z" + (state.Z).tostring + Chr(13))
serialport1.Write ("Rz" + (state.Rz).tostring + Chr(13))
SerialPort1.Write(state.GetButtons(0) & chr(13))
end if
End Sub


Sub Label1Click(ByVal sender As Object, ByVal e As EventArgs)

End Sub
End Class