Results 1 to 29 of 29

Thread: Test my joystick class please

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Smile Test my joystick class please

    I have written this simple wrapper for Joystick API's (attached). Just rename the file to a .vb extension and its ready for use.

    If you are writing a game in VB and want stick support then include this file in your project (or compile it into a dll) and use instances of it in your code.

    To create an instance:

    VB Code:
    1. Dim Stick as Joystick
    2.     If Joystick.SticksPresent() =1 Then
    3.         Stick = New Joystick(0) 'bind to first stick
    4.     End If

    The argument in the constructor tells the program which joystick you want to bind this instance to. You might have more than one stick plugged in so this number will vary depending which one(s) you are going to use.

    This class provides axis data in the normal format and also in a relative format...

    Calling XAxisRelative() will return values from -1 (left) to +1 (right) data type is single. Y and Z axis data is available in the same way.

    I only have 1 joystick myself and so I need people with more than one stick plugged in to try to access the stick data.

    Call the Refresh() sub to bring the data in the class up to date.

    Have a look through the code to get the hang of it, its pretty simple

    To test for 2 joystick compatibility, plug in both of your sticks, and use 2 instances of the class, bind one of them to 0 and the other to 1 using the constructor argument)

    Then use a timer to refresh() each joystick (timer interval of 50 is fine). Then take some info from each joystick and show it on the form (I use a label to display the XAxisRelative() values).

    Stick left should be approximately -1 (this can vary, and be as small as -0.5 on some sticks)

    Then move both sticks simultaneously in random directions, the data for both sticks should change on the labels.

    I probably haven't explained this well (sorry) so please let me know if you can't get it working.

    Thanks for reading
    I don't live here any more.

  2. #2

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Please?
    I don't live here any more.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Give me a joystick.

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Originally posted by wossname
    Please?
    Hi.

    I downloaded your class last night, but I haven't had time to test it yet.
    I will see if I can do it tonight.

    I'll Be Back...
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Isn't this the same sort of thing that DirectX offers with directInput? Or am I wrong?

  6. #6

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Its mainly for people that haven't got the need for the cumbersome Directx system.

    I haven't got a late edition of DX anyway so I wouldn't know

    Have a look, see what you think.
    I don't live here any more.

  7. #7
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    I have just tried it and it seems pretty solid and straight-forward. Good Job

    I few things missing though (sorry!).

    I have a wheel with 6 buttons, throttle, rudder and 2 POV's

    The X,Y,Z(throttle) and the buttons work just fine.
    But I don't see any way to access the rudder and POV's.

    And it would be very nice if it were event driven to inform the user that something has changed (perhaps with a dead-band to limit the number of events), so you didn't have to insert a timer and refresh. It would probably just be the timer being moved into the Joystick-class, but still, it would be nice if the user didn't have to think about such things.

    Just a suggestion. I still thinks it's great work...
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  8. #8

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Thanks for the input

    Did you mean all 6 buttons work? I wasn't sure if it would return data for more than 4 buttons. If it does then great

    Your stick has 2 POV's ? weird.

    My stick that I use has x, y and throttle and only 4 buttons, not the perfect test bed for this

    Things to add so far...

    - timer within joystick class (can be ignored by app)
    - variable autofire (might be difficult!)
    - variable dead zone for axes

    I don't think the API supports rudder or POV hat but I could be wrong, if it does then I'll try to add it.

    Keep the suggestions coming.

    Thanks
    I don't live here any more.

  9. #9
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Yeah, all 6 buttons work. it just returns 1,2,4,8,16,32 depending on which button is pressed.

    I've looked a little on the API's myself, and it appears there is a joyGetPosEx that should return up to 6 axis and at least 1 POV.

    And the documentation for JOYCAPS is different from the one you made. The one that's in the help also has info about the R U V axis and the POV. But I can't get it to work. But then again, I'm not to big on API, espacially from within .NET.

    Keep up the good work.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  10. #10

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Where did you find info on that joyGetPosEx API?

    Have you got a link? My copy of API Guide doesn't cover it.
    I don't live here any more.

  11. #11
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    It's in the VS help. There's not much info on how to use it in net though.


    I hope this link works:
    joyGetPosEx
    I hope you can get it to work.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  12. #12
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Attached Images Attached Images  
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  13. #13

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Right then, (I managed to find the API stuff in the VSIDE) I've expanded the class to encompass the new API call. Would you mind trying this version out for me? I won't be able to test POV and R,U,V axes. I'll have to look in the PC world preowned bin for an old stick with lots of features

    I haven't done the dead zone thing yet...

    Would it be best to set a blanket deadzone for all axes or set each axis DZ individually?
    It could be done easily either way but the latter adds more complication to the class. Its a compromise between simplicity and versatility.

    What do you think?

    Still working on autofire and internal timer ideas.

    I'm going to release this as a freeware DLL, I'll give you a credit in the documentation

    Cheers for the help.
    I don't live here any more.

  14. #14
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Sure I'll try it. Only problem is, that I have just now finished re-installing my OS. My girlfriend f***ked it up .

    And it's a quarter past midnight here right now, so it will problably not be until tomorrow evning.
    I hope you can bare the suspence until then

    I think it would be best to add individual deadbands even though it does add some complexity to it.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  15. #15
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    I have just tried it, and I'm sorry to say that nothing worked .
    It couldn't even see my joystick. There's no error, it just says that there are 0 sticks present.
    When I use the first version of your class it works, and it also works in Control Panel, so I guess the joystick is installed ok.

    I think it may have something to do with the EX api's.
    I'm using Win XP Pro SP1 and VS .NET 2003.
    What are you using?
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  16. #16
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Back again. It's working now.

    In the JOYINFOEX structure all variables were Long's. I changed those to Integer.

    In SticksPresent function I added a JI.Size=Len(JI) before the loop.
    VB Code:
    1. Public Shared Function SticksPresent() As Integer
    2.         Dim i As Integer
    3.         Dim j As Integer
    4.         Dim JI As JOYINFOEX
    5.  
    6.         i = joyGetNumDevs
    7.  
    8.         'Added this line
    9. JI.Size = Len(JI)
    10.  
    11.         j = 0
    12.         Do While i > 0
    13.             i -= 1             'Joysticks id's are 0 and 1
    14.             If joyGetPosEx(i, JI) = JOYERR_NOERROR Then
    15.                 j += 1
    16.             End If
    17.         Loop
    18.  
    19.         Return j
    20.  
    21.     End Function
    In sub New I also added a _INFO.Size=Len(_INFO)
    VB Code:
    1. Public Sub New(ByVal StickID As Integer)
    2.         If StickID >= SticksPresent() Then
    3.             Throw New JoystickBadIDException("That ID is greater than the number of joysticks attached to the system.")
    4.         End If
    5.  
    6.         _ID = StickID
    7.         If joyGetDevCaps(_ID, _Caps, Len(_Caps)) <> JOYERR_NOERROR Then
    8.             Throw New JoystickGenericException("Could not get the device caps for joystick ID: " & _ID)
    9.         End If
    10.  
    11.         'Added this line
    12. _INFO.Size = Len(_INFO)
    13.     End Sub

    And everythings peachy now.
    All axis and buttons work fine.
    It can only see one of my POV's though, but I think thats due to the API itself. I have several games that can only see one as well.

    Very cool job.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  17. #17
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Doh, forgot to attach the file I made corrections to...
    Attached Files Attached Files
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  18. #18
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    I just downloaded the code but haven't had time to look at it yet. Have either of you tried it with the Sidewinder? I'm curious how it worked.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  19. #19

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Damn, completely forgot about vb6 long = vb.net integer.

    Nice catch

    Good new it works, its a bit frustrating not being able to test it myself.

    I trust the POVAngleDegrees() and POVAngleRadians() functions are working properly. I have added a POVAngleRaw() function for backwards compatibility with some old routines.

    I have thought long and hard about this timer problem and I have concluded that its better to leave it out of the joystick class. I'd rather let the client app demand info as and when required, than make the class generate this information which will probably fall out of synch with the client app anway.

    By letting the client app ask for the refresh() it is guaranteed to get brand new data from the stick, rather than get data that is 100ms our of date. (That is a LONG time in gaming)

    The same goes for the autofire feature.

    But, I'll implement the deadzones today and get the new version posted here today.

    Something like

    public sub DeadZone(x as single, y as single)
    ...

    with several overloads to represent the different axes.

    Watch this space.
    I don't live here any more.

  20. #20
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Originally posted by wossname
    By letting the client app ask for the refresh() it is guaranteed to get brand new data from the stick, rather than get data that is 100ms our of date. (That is a LONG time in gaming)

    The same goes for the autofire feature.
    Agreed. Good point. There would/could be many situations in a game, like cutscenes, where you don't need to use resources on timers.

    RealisticGraphics:
    I don't have a sidewinder, but it uses the standard windows api, so I can't see why it shouldn't work.
    I'm using a CH Products Virtual Pilot Pro with rudderpedals.
    I'm just using the standard driver "Joystick with 6 buttons, 2 POV and throttle" with pedals activated.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  21. #21

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Nearly there!

    I have almost got the deadzone (DZ) thing right.

    I am planning this:

    The DZ value that you supply to the class will be from 0 to 1 typically 0.1 for example.

    Using the X axis as an example, moving the stick very slowly to the right will cause the class to return zero as the X value until the stick physically passes through 0.1 of its full travel. At that exact point it will return something like 0.001. When it gets to extreme right, it will be returning something like 0.999.

    This is cool because you still get the same range of output from the stick even though there is a deadzone where no noise is transmitted to the game.

    This applies to all 6 axes. I am currently trying to fix a bug with it, which means that it is chopping off the top few degrees of motion. Annoying

    I'll impost a limit of 0.25 on the deadzone as this is quite a huge range of stick travel and its unlikely that you'll need more than that (basically a quarter of the sticks range!). As long as you are not having a seizure at the helm of your starship you'll be OK with that number

    ALSO
    A sexy additional feature, is the ToString() function that I have written for he joystick class. It basically churns out a little report on the stick's current status (all axes data, buttons pressed status etc.)

    Makes testing infinitely easier, sweet.

    I'll need your help tomorrow if thats ok?
    I don't live here any more.

  22. #22
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Cool. I'll help all that I can.
    The DZ sounds sweet.
    An addition to that could be to be able to define max and min for each axis. When turning an axis completely to one side rarely produces 0 or 1. This will be even more visible when the DZ comes into play.

    But being able to set the Max and Min for each axis would remove this problem, while still having the DZ remove the noise.

    I was thinking something like:
    VB Code:
    1. Public Function XAxisRelative() As Single
    2.     'returns values between -1 and +1
    3.     Select Case _INFO.X
    4.         Case <X_MIN
    5.             Return 0
    6.         Case >X_MAX
    7.             Return 1
    8.         Case Else
    9.             Return (_INFO.X / HALF_AXIS_TRAVEL) - 1
    10.             'Including your DZ formula here
    11.     End Select
    12. End Function

    This is going to be one cool DLL.
    I was actually thinking about making one myself a while ago, but I couldn't make the API's work so I gave it up.
    When I look at your code, I can't understand why I couldn't make it work, cuz it seems so simple when someone else is doing it.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  23. #23

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Hey Pax, how about we stop posting the code here and do it by email instead?

    PM me and we could swap email addresses (that's if you want to ).
    I don't live here any more.

  24. #24
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    email exhange? You guys are no fun!!! I enjoyed reading this thread even though I have no clue what you guys are talking about!!!

  25. #25

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Don't worry, we'll be releasing the DLL lib soon.

    Then you can taste the fruit of our toil.
    I don't live here any more.

  26. #26
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    You'll be including the source code, right?
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  27. #27

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Depends if there's any demand for it.
    I don't live here any more.

  28. #28

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Nearly there now. I'll start taking orders now
    I don't live here any more.

  29. #29
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Damn' Wossname, you change you sig and location more than I change my underwear...Which happens almost every christmas
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

Posting Permissions

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



Click Here to Expand Forum to Full Width