Results 1 to 5 of 5

Thread: Phidgets 8/8/8 and the Joystick sensor

  1. #1
    Maximum Bitrate
    Join Date
    Oct 2003
    Location
    Copenhagen, Denmark
    Posts
    747

    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 http://www.phidgets.com/index.php?mo...iew&CID=6&KID= 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

    <code>
    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
    </code>

    Jan
    Transflective Lilliput 8", LV-677DC Core Duo 1,83Ghz, , Mpegbox uSDC20D, Shuttle Express, HQCT, PG XS6600 http://carpc.boyakasha.dk

  2. #2
    Maximum Bitrate DeltaFX's Avatar
    Join Date
    Sep 2004
    Location
    France
    Posts
    499
    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)

    GetCursorPos(PosXY);
    DeltaX:=Trunc((((-25/3072)*(127-Data1)+1075/96)*(127-Data1)/1000)*Abs(127-Data1));
    DeltaY:=Trunc((((-25/3072)*(127-Data2)+1075/96)*(127-Data2)/1000)*Abs(127-Data2));

    PosXY.X:=PosXY.X + DeltaX;
    PosXY.Y:=PosXY.Y - DeltaY;
    SetCursorPos(PosXY.X,PosXY.Y);

    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
    begin
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    sleep(20);
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
    end;

  3. #3
    Maximum Bitrate
    Join Date
    Oct 2003
    Location
    Copenhagen, Denmark
    Posts
    747
    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.
    Transflective Lilliput 8", LV-677DC Core Duo 1,83Ghz, , Mpegbox uSDC20D, Shuttle Express, HQCT, PG XS6600 http://carpc.boyakasha.dk

  4. #4
    Maximum Bitrate DeltaFX's Avatar
    Join Date
    Sep 2004
    Location
    France
    Posts
    499
    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

  5. #5
    Maximum Bitrate
    Join Date
    Oct 2003
    Location
    Copenhagen, Denmark
    Posts
    747
    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.
    Transflective Lilliput 8", LV-677DC Core Duo 1,83Ghz, , Mpegbox uSDC20D, Shuttle Express, HQCT, PG XS6600 http://carpc.boyakasha.dk

Similar Threads

  1. What is the worst job you ever had?
    By fluffy2097 in forum Off Topic
    Replies: 16
    Last Post: 04-22-2008, 02:55 PM
  2. 93 accord SE: The Lost Cause
    By fluffy2097 in forum Show off your project
    Replies: 20
    Last Post: 10-15-2003, 04:47 AM
  3. What do you think of my playlist??
    By SkinnyBoy in forum Software & Software Development
    Replies: 19
    Last Post: 07-19-2001, 01:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •