Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: TBDI - DirectInput Joystick module

  1. #1
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    TBDI - DirectInput Joystick module

    Hi folks,

    I didn't know where to post it so feel free to move it. Here is the first directinput module for joystick support and a text file with the syntax of the 5 commands in it. Just 5, some will ask? Don't worry, I just got PowerBasic to do what I want.

    I thought I needed a conversion of a C macro but no, I had false examples. After a look inside the MS SDK docu I found the bug and voila, now joystick behaves like a good boy. I would like you to test it temporary inside TopDown and let me know if it works or crashes. Before someone asks, copy the DLL inside the thinBasic lib folder.

    After more tests are done and I added more stuff to it, I will ask Eros to include this module into the official distribution and hand it over to him.

    Here is some code that has to be added to TopDown:

    [code=thinbasic] USES "TBDI"
    '...
    DIM But1 as integer
    dim direturn as long
    dim joyX as integer
    dim joyY as integer
    ...
    'Initialize DirectInput Joystick support
    direturn = tbdi_init(0)
    '...
    'Check the state of both axxis and the button no.1
    joyX = tbdi_joyX
    joyY = tbdi_joyy
    but1 = tbdi_joybutton(1)
    '...

    if GetAsyncKeyState(%VK_SPACE) or but1 then
    '...
    if GetAsyncKeyState(%VK_UP) or joyY < 0 then
    '...
    if GetAsyncKeyState(%VK_DOWN) or joyY> 0 then
    '...
    'Don't forget to release the joystick
    tbdi_close
    [/code]

    I think it is easy to use, or? I hope it works on your machines.

    Cheers
    Michael Hartlef
    Attached Files Attached Files

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Re: TBDI - DirectInput Joystick module

    Mike,

    I'm testing module. FIRST OF ALL: THANKSSSS!!

    Now, I'm using a XBox 360 USB Controller. I've amended TopDown3D (see attached) and seems working fine.
    I do not know if it is normal but when I move cursor left or right or top or bottom, it continue moving till the edge of limits even if I stop moving gamepad.

    Maybe I'm making something wrong.
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: TBDI - DirectInput Joystick module

    Mmh, your code works fine here, I'm using a regular PC gamepad P880 from Saitek.
    I will test it tommorow with my MS Sidewinder.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Re: TBDI - DirectInput Joystick module

    Mike, what is the meaning of parameter in TBDI_INIT(0) function?

    Also consider you can add initialization and / or de-initialization in LoadLocalSymbols and UnLoadLocalSymbols function inside module.
    When thinCore search for a requested script module, if found, LoadLocalSymbols is searched and executed.
    When script ends, thinCore will take care to call UnLoadLocalSymbols from all currently open modules.

    So maybe you can add code in UnLoadLocalSymbols to avoid users to call TBDI_CLOSE.
    Just guessing.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Re: TBDI - DirectInput Joystick module



    Mike,

    this is perfect !
    Logitech Wingman Precision works absolutely good with your module !
    Great great great work !

    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Re: TBDI - DirectInput Joystick module

    So, maybe its my config. I will check.
    Just a question. When I stop moving on gamepad tbdi_joyX or tbdi_joyY should return zero?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Re: TBDI - DirectInput Joystick module

    Forum syntax highlight will now recognize new TBDI keywords.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Re: TBDI - DirectInput Joystick module

    I found that X and Y returned by my gamepad is not zero but something different: sometimes positive, sometimes negative.

    I've done a little test script and found it. Maybe only a calibration problem.
    [code=thinbasic]USES "TBDI"
    uses "console"

    DIM But1 as integer
    dim direturn as long
    dim joyX as integer
    dim joyY as integer

    'Initialize DirectInput Joystick support
    direturn = tbdi_init(0)

    while %TRUE
    'Check the state of both axxis and the button no.1
    joyX = tbdi_joyX
    joyY = tbdi_joyy
    but1 = tbdi_joybutton(1)


    console_write "BUT1: " & But1
    console_write " Y:" & joyY
    console_write " X:" & joyX
    console_writeline ""
    wend
    tbdi_close[/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: TBDI - DirectInput Joystick module

    Quote Originally Posted by ErosOlmi
    So, maybe its my config. I will check.
    Just a question. When I stop moving on gamepad tbdi_joyX or tbdi_joyY should return zero?
    Eros, Yes, it should. Maybe you can output the joyx and joyy values next to the score. It could be that your joystick needs a higher dead_zone. I will make it variable. IT could be that the default value is not high enough for you.

    Btw. great suggestions about Init and close. I will do that. Init had the instance value as a parameter. When it was given 0, it is taken the DLL instance. But your solution is perfect.

    Petr, thanks man. It caused me some gray hairs, but now it is working and is a good base for more stuff like force feedback.

  10. #10
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: TBDI - DirectInput Joystick module

    Quote Originally Posted by ErosOlmi
    I found that X and Y returned by my gamepad is not zero but something different: sometimes positive, sometimes negative.
    Yeah, that could be. Some joystick are not that good when it comes to hold constant values. Like I said, you would need a bigger dead_zone where it reports 0. Or the checks inside the gamelogic should be different. Not checking against 0.

Page 1 of 3 123 LastLast

Similar Threads

  1. So how do you get along with the TBDI module?
    By Michael Hartlef in forum TBDI module. thinBasic Direct Input integration by MikeHart
    Replies: 36
    Last Post: 30-08-2007, 09:07

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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