HELP! I find an issue using _DEVICES!
#1
Hi QB64 coders

I was attempting to accomplish this task
detecting a joystick and its settings of  buttons/axis

using the original code I thought that I made an error in typing code. So with the goal to solve this issue of detecting a Joystick before to change its settings of _BUTTONS, I fall in this issue that you can live running this code and following these instructions:
1.  copy and paste this code into QB64 IDE
2.  take near you an USB joystick
3.  press F5 after QB64 IDE with this demo code has got the focus
4. you should get message "NO Joystick! 2   0   0    0"
5. pressing ENTER key you should get the same message on the screen
6. Plug in the USB joystick to the PC/Notebook and wait for the sound of controller connected by Windows 11
7. press 3 times ENTER Key, you should get a message "Joystick detected  3 .........." three times
8. disconnect the USB joystick and wait for the sound of controller disconnected by Windows 11
9. press ENTER key and WHAT message do you get back?

Here the code that I used

Code: (Select All)
 
ReDim Shared Ax(1 To 1) As Integer, Bx(1 To 1) As Integer, Wx(1 To 1) As Integer
ReDim Shared Axm As Integer, Bxm As Integer, Wxm As Integer
Dim Kh As Integer

Cls
Print " Press ESC to quit and Enter to detect joystick"
Print " JoyStick  Axis        Buttons      Wheels"
Print IsJoystick%, Axm, Bxm, Wxm
View Print 4 To 24
Kh = 0
While Kh <> 27
    Kh = _KeyHit
    If (Kh) = 13 Then Print IsJoystick%, Axm, Bxm, Wxm
    Locate 24, 1: Print Kh;
    _Limit 30
Wend
End

'*****************************************************************
'            JOYSTICK DETECTION
'*****************************************************************
Function IsJoystick% ()
    Dim HMD%: HMD% = HowManyDevice%

    If HMD% = 0 Then
        Print " No input devices!": End
    Else
        Locate , 1: Print HMD%
    End If

    If HMD% = 3 Then
        Locate , 4: Print "Joystick detected";
        IsJoystick% = -1
        Axm = _LastAxis(3)
        Bxm = _LastButton(3)
        Wxm = _LastWheel(3)
    Else
        ' all cases in which HMD% <>3
        Locate , 10: Print " NO Joystick!";
        IsJoystick% = 0
        Axm = 0
        Bxm = 0
        Wxm = 0
    End If
    Print HMD%, Axm, Bxm, Wxm
End Function

Function HowManyDevice%
    HowManyDevice% = 0 ' error value
    HowManyDevice% = _Devices ' value detected
End Function
'*****************************************************************
'        END Subs and Functions for JOYSTICK DETECTION
'*****************************************************************

Here my weird output


[Image: immagine-2023-05-02-004435348.png]

detection is stuck!

So please make bigger my knowledge with your feedbacks!
Where is the mistake in the code?
Thank you for your apport!
Reply
#2
I just finished a complete lesson on controller devices in my tutorial.

https://www.qb64tutorial.com/lesson21

I believe the issue you are having is that you are not using _DEVICEINPUT first before polling the controllers for information. The lesson goes through step by step on how to properly poll controller devices for information.

_DEVICES and related statements are a bit tricky to use and set up properly. I'm sure this tutorial lesson will help you.
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#3
Hi Terry Smile 
I just read your mini biography, very interesting.
Reply
#4
If you guys are going to be using _Devices, you might want to test it with our latest repo version.

QB64PE v3.7 should be releasing soon(tm), and it's got several fixes and enhancements on _Devices.
Reply
#5
Hi Terry
thanks for the link!
I have already followed the birth of your Controller Library on this forum.
I must see the latest adjournments that you have published.

In the while I read your Lesson 21 with calm, (your Controller Library can be the solution of the issue) ,
here the root of my code

Quote:Another thing to fix I realized is the test for the presence of a joystick needs to come inside the menu loop, at the top. That way you can plug a controller in without having to restart the program.


from this post #30 of old QB Defender thread... the far away goal is to let plug in/out a controller without restart the program.
The code in #1 of this thread attempts to scan devices activated on the pc after a command input (ENTER key).
The strange behaviour that I got is that after a first good run  the following testings are stucked!

I'll search in your lesson 21 the solution to my issue.
Thank you
Reply
#6
(05-01-2023, 11:42 PM)SMcNeill Wrote: If you guys are going to be using _Devices, you might want to test it with our latest repo version.

QB64PE v3.7 should be releasing soon(tm), and it's got several fixes and enhancements on _Devices.

I just now tried using v 3.6.0 but the story seems to be the same.
here screenshot


[Image: immagine-2023-05-02-021006379.png]
at start (first row of results) there was no joystick plugged in.
Then I plugged in a joystick 2 axis and 10 buttons (second row of results)
After this I plugged out the same joystick and I got the other three row of results.

NB: the first number is the name of devices in the pc (under the Joystick column)
and in the bottom on the left is the keycode got by _Keyhit.
Reply
#7
(05-01-2023, 11:33 PM)Jack Wrote: Hi Terry Smile 
I just read your mini biography, very interesting.

Yeah, I didn't take the usual path through life. Smile
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#8
(05-01-2023, 11:42 PM)SMcNeill Wrote: If you guys are going to be using _Devices, you might want to test it with our latest repo version.

QB64PE v3.7 should be releasing soon(tm), and it's got several fixes and enhancements on _Devices.

Looking forward to 3.7 with regards to _devices so I can finish the _wheel portion of the controller library.

Also, I believe you mentioned in an earlier post that _PRINTSTRING would be much faster as well, is this correct?
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#9
   
Reply
#10
Definitely looking forward to the print improvements!
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply




Users browsing this thread: 3 Guest(s)