|
Post by alwichita on May 15, 2023 10:55:43 GMT -5
Hi,
I have a couple of generic joysticks that I can't read using the following code:
Note: Windows 10 joystick tester works just fine. Also, the joystick is held in different positions for several seconds.
Thanks ! Al '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CODE:
for lp=1 to 100
print lp
readjoystick 1
print Joy1x, Joy1y, Joy1z, Joy1button1, Joy1button2
readjoystick 2
print Joy2x, Joy2y, Joy2z, Joy2button1, Joy2button2
print
calldll #kernel32,"Sleep",500 as ulong,r as void
next
end
''''''''''''''''''''''''''''''''''''''' OUTPUT / RESULTS: (all reading 1-100 are the same)
99 32511 32511 32511 0 0 0 0 0 0 0
100 32511 32511 32511 0 0 0 0 0 0 0
|
|
|
Post by Rod on May 15, 2023 11:17:56 GMT -5
Since it is returning values I just wonder if the joysticks have installed as 1 & 2 What does windows device manager tell you about the joysticks?
USB based joysticks can install as 3 4 5 etc You can read those with api but Liberty natively reads only 1and2
Last time I tried on win11 it just worked.
|
|
|
Post by alwichita on May 15, 2023 12:46:46 GMT -5
windows device manager recognizes both joysticks and the windows joystick test works fine. Can you please share or point me to the api? Thanks Al
|
|
|
Post by Rod on May 15, 2023 13:28:13 GMT -5
Yes but does windows assign 1 and 2 as the joystick handles? There is api code on the LBPE but we should try and get native working first.
|
|
|
Post by Rod on May 15, 2023 13:52:40 GMT -5
|
|
|
Post by Rod on May 15, 2023 14:02:50 GMT -5
Also try this code from Rosetta Code just in case the sleep command is causing the code to loop really quickly and miss the joystick movement.
'disable text window nomainwin
'set window size WindowWidth = 308 WindowHeight = 331
'center window on screen UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2)
'open graphics window open "Joystick Position" for graphics_nf_nsb as #m
'trap window closing #m "trapclose [quit]"
'put pen down #m "down"
'get center of graphics window #m "home" #m "posxy CenterX CenterY"
'draw sprite for crosshair #m "backcolor black; color black" #m "place 0 20;boxfilled 20 40" #m "line 0 10 20 10" #m "line 10 0 10 20" #m "place 10 10; circle 10" #m "backcolor white; color red" #m "line 0 30 20 30" #m "line 10 20 10 40" #m "place 10 30; circle 10" #m "flush"
'get sprite image #m "getbmp plus 0 0 20 40" #m "cls"
'create sprite from image #m "addsprite crosshair plus" #m "centersprite crosshair" #m "spritexy crosshair "; CenterX; " "; CenterY #m "drawsprites"
'check joystick every 100 milliseconds timer 100, [CheckJoystick] wait
[CheckJoystick] readjoystick 1
'calculate crosshair position PosX = int(CenterX*Joy1x/32767) PosY = int(CenterY*Joy1y/32767)
'update crosshair position #m "spritexy crosshair "; PosX; " "; PosY #m "drawsprites"
'display button information if Joy1button1 > 0 then #m "place 0 0;\\Button 1 pressed" if Joy1button2 > 0 then #m "place 0 0;\\\Button 2 pressed"
wait
[quit] timer 0 close #m unloadbmp "plus" end
|
|
|
Post by alwichita on May 15, 2023 16:01:58 GMT -5
Thank You Rod ! Upon further investigation, Using my code, I am able to read the buttons only - Joy1Button1 reads a '1', Button 2 read a '2', and Joy2Button1 reads a '1', Button 2 read a '2' - all return to '0' when not pressed. Using your code it also reads the buttons but not the X/Y/Z inputs (same as mine). It appears to be a generic driver issue - although Windows 10 reads all joystick functions properly and tests everything fine. When using Liberty Basic (both software versions) Only the buttons work and not XYZ. I'm gonna go buy a different Joystick and see if that works.
|
|
|
Post by alwichita on May 15, 2023 18:21:23 GMT -5
New Joysticks work great !
Thanks Rod !!!
|
|