1 Attachment(s)
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
1 Attachment(s)
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.
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.
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
Re: TBDI - DirectInput Joystick module
:o
Mike,
this is perfect !
Logitech Wingman Precision works absolutely good with your module !
Great great great work !
Thanks,
Petr
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?
Re: TBDI - DirectInput Joystick module
Forum syntax highlight will now recognize new TBDI keywords.
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]
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.
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.