Hi all,
I need a simple filter to filter joystick input. I came across some in the internet but since I lack filter theory, it makes it a bit difficult to understand what's going on and hence to implement.
Is there anybody that can help me here please?
Thanks a lot
You are not specifying the programmer language you are using.
Here is a complete example with VB.Net 2008
- first of all you need to implement the Joystick environment in order to read Data
'ON TOP
Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Integer, ByRef pji As JOYINFOEX) As Integer
<StructLayout(LayoutKind.Sequential)> _
Public Structure JOYINFOEX
Public dwSize As Integer
Public dwFlags As Integer
Public dwXpos As Integer
Public dwYpos As Integer
Public dwZpos As Integer
Public dwRpos As Integer
Public dwUpos As Integer
Public dwVpos As Integer
Public dwButton As Integer
Public dwButtonsNumber As Integer
Public dwPOV As Integer
Public dwReserved1 As Integer
Public dwReserved2 As Integer
End Structure
' WITHIN YOUR TIMER SECTION
' READ THE JOYSTICK VALUE
Call joyGetPosEx(0, myjoyEX)
Dim btnnumbers As Integer = 0
Dim DummyInt As Integer = 0
With myjoyEX
'you can read the Data declared with the Structure JOYINFOEX
'Label1 = .dwXpos.ToString
'etc. etc...
'Joystick Button number value
DummyInt = .dwButton
'show value as reference
Me.TextBox1.Text = .dwButton.ToString("0")
'Number of Joystick Buttons pressed together
btnnumbers = .dwButtonsNumber
F2.TextBox2.Text = btnnumbers.ToString("0")
End With
'read joystick then delay in any Sub, avoid too fast reading within this Timer
'YOU MUST FIRST READ THE SINGLE JOYSTICK BUTTON VALUES
'EXAMPLE: the 'Shift State' lever with the SAITEK X52 should return value 32
' the Button 'FIRE A' could return value 4
' The combination of 'Fire A' + Shift state would be then vale 36
' You read all buttons and POV values
' you read the X, Y values as declard
'FILTER OUT
'btn_1, btn_2 include the values assigned when you start your program
'you could use a ?.ini Text-File where you write your joystick values
'Use the 2 TextBox1 + TextBox2 for a visual data reading and create your 'ini.file'
'on program start read the '?.ini' data into the btn_1 ...... variables
Select Case UCase(DummyInt)
Case btn_1 'shift + Fire A
'in base of the total Value call your Sub-Function to do something.....
ApHdgClick()
Case btn_2 'shift + Fire B
Panel2Open()
Case btn_3 '32800
Panel3Open()
End Select
Private Sub ApHdgClick()
On Error Resume Next
'Example of Transmit Event with FSX Simconnect
fsx_simconnect.TransmitClientEvent(DEFINITIONS.Struct1, EVENT_ID.EVENT_HEADINGOnOff, 0, hSimconnect.group1, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)
''''''''''' Delay - This is very important ''''''''''''''
System.Threading.Thread.Sleep(300)
End Sub
regards,