No announcement yet.

Phidgets 8/8/8 and the Joystick sensor

  • Filter
  • Time
  • Show
Clear All
new posts

  • Phidgets 8/8/8 and the Joystick sensor

    Hi there

    i just got my Mini Joystick Sensor for the phidgets 8/8/8 hw yesterday and wanted to see if i could use it as a mouse mainly for Roadrunner for me, but should work fine in any frontend.....just for fun mostly. I did some simple VB6 code using the phidgetslibrary, maybe some can use it, at least as a starting point. One thing that is missing is hooking up the button in the joystick for mouseclick, maybe with a timer for right click or something, like the touchscreen drivers do.

    It works in any resolution

    Option Explicit
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Private WithEvents PM As PhidgetManager
    Dim SensorX As Long
    Dim SensorY As Long
    Dim SensorXCenter As Long
    Dim SensorYCenter As Long
    Dim SensorXMin As Long
    Dim SensorXMax As Long
    Dim SensorYMin As Long
    Dim SensorYMax As Long
    Dim ResolutionX As Long
    Dim ResolutionY As Long
    Dim ConvertX As Double
    Dim ConvertY As Double

    Dim WithEvents IFKit As PhidgetInterfaceKit

    Private Sub Command1_Click()
    MsgBox ("Slip Joysticket helt,ok")
    SensorXCenter = IFKit.SensorValue(4)
    SensorYCenter = IFKit.SensorValue(5)
    MsgBox ("Right,ok")
    SensorXMax = IFKit.SensorValue(4)
    MsgBox ("Left,ok")
    SensorXMin = IFKit.SensorValue(4)
    MsgBox ("Up,ok")
    SensorYMin = IFKit.SensorValue(5)
    MsgBox ("Down,ok")
    SensorYMax = IFKit.SensorValue(5)

    ConvertX = ResolutionX / (SensorXMax - SensorXMin)
    ConvertY = ResolutionY / (SensorYMax - SensorYMin)

    Text1.Text = "XCenter" & " " & SensorXCenter & "YCenter" & " " & SensorYCenter & vbCrLf & "Xmin" & " " & SensorXMin & "Xmax" & " " & SensorXMax & vbCrLf & "Ymin" & " " & SensorYMin & "Ymax" & " " & SensorYMax & vbCrLf & "ConvertX" & ConvertX & "ConvertY" & ConvertY
    End Sub
    Private Sub Form_Load()
    Set PM = New PhidgetManager 'Get the phidget manager going
    SensorXCenter = 500
    SensorYCenter = 500
    SensorXMin = 0
    SensorXMax = 1000
    SensorYMin = 0
    SensorYMax = 1000
    ConvertX = 1
    ConvertY = 1

    ResolutionX = Screen.Width / Screen.TwipsPerPixelX
    ResolutionY = Screen.Height / Screen.TwipsPerPixelY

    End Sub
    'An InterfaceKit was found. Start everything up
    Private Sub PM_OnAttach(ByVal PHIDGET As PHIDGET.IPhidget)
    Dim I As Long
    If PHIDGET.DeviceType <> "PhidgetInterfaceKit" Then Exit Sub
    Set IFKit = PHIDGET
    'make the sensors less sensitive so that we don't get flooded with events
    For I = 0 To IFKit.NumSensors - 1
    IFKit.SensorChangeTrigger(I) = 5
    Next I
    End Sub
    ' Call this whenever phidget gets changed sensor data
    Private Sub IFKit_OnSensorChange(ByVal Index As Long, ByVal SensorValue As Long)
    ' We only care about port 4 and 5 which the joystick is on
    If (Index = 4) Then SensorX = (SensorValue * ConvertX) ' X Value on port 4
    If (Index = 5) Then SensorY = (SensorValue * ConvertY) ' Y Value on port 5
    Text1.Text = "X:" & " " & SensorX & "Y:" & " " & SensorY
    Call SetCursorPos(SensorX, SensorY) ' Set cursor to the actual joystick position
    End Sub

    Not doing carpc anymore

  • #2
    That mini joystick has a spring to autocenter it, right ? You'd better not use this like an absolute-positionning, it would be hard to maintain the position and click the same time.

    I did the same with an old PS2 minijoystick connected to a VM110 board. (sensors range from 0 to 255)


    PosXY.X:=PosXY.X + DeltaX;
    PosXY.Y:=PosXY.Y - DeltaY;

    Maths are there to alter linearity.

    And to emulate a left click (switch connected to input 1, (i and 1) checks if input #1 is 0/1)

    if (i and 1)>0 then
    Now Galileo is real. Muhahahahaha :p


    • #3
      Ya, i tried to use the button in the joystick today, and it is a bit tricky, so i might just put two buttons in my armrest on the side of the joystick i think, as for accuracy in positioning it seems fine for the big buttons in the skin i use for RoadRunner @ 800x600.
      Not doing carpc anymore


      • #4
        Separate buttons will help. My point is, to click a button on RR, you will need to keep the right position of the minijoy while you click (using others buttons, or the integrated switch). That will be tricky if you are driving.

        The way I coded mine, you can position the mouse over a button, do something vital - avoid a crash-, then click.

        Idealy a minijoy like this, coupled with a Frontend, should imho work like the arrow keys, a kind of "Jump to the nearest button in the direction you pushed".

        Just my 2 cents

        my joystick
        Now Galileo is real. Muhahahahaha :p


        • #5
          You might be right about that, i guess i won't find out if this is something that could work until it is installed in the car.
          Not doing carpc anymore