Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gamepad tester
#2
Hi,

New version that looks like this; it has been tested with a Sony DualSense controller; I welcome any feedback from tests with other controllers.
[Image: gamepad-Tester.png]

Code: (Select All)

type axis_amplitude_type
    min as integer
    max as integer
    amplitude as integer
end type

$console
_dest _console
? "gamepad tester"

screenWidth% = 640
screenHeight% = 480
page0& = _newimage (screenWidth%,screenHeight%,32)
display& = _newimage (screenWidth%,screenHeight%,32)
screen display&

displayTextCenter _
    display&, _
    screenWidth%/2, screenHeight%/2 - _fontheight, _
    _rgb(160,160,160), _
    "GAMEPAD TESTER"

_delay 1

displayTextCenter _
    display&, _
    screenWidth%/2, screenHeight%/2 + _fontheight * 3, _
    _rgb(160,160,160), _
    "Ready !"

_delay 1

displayTextCenter _
    display&, _
    screenWidth%/2, screenHeight%/2 + _fontheight * 5, _
    _rgb(160,160,160), _
    "Plug your gamepad..."

_delay 1

displayTextCenter _
    display&, _
    screenWidth%/2, screenHeight%/2 + _fontheight * 7, _
    _rgb(160,160,160), _
    "Then press your keyboard to launch Wink"

do until inkey$ > chr$(0) : _limit 60 : loop

_dest _console
for i% = 1 to _devices
    dv$ = _device$(i%)
    ? dv$
    ? "buttons = ";_lastbutton(i%), "axis = ";_lastaxis(i%), "wheels = ";_lastwheel(i%)
    if left$(dv$,12) = "[CONTROLLER]" then
            controller% = i%
            buttons% = _lastbutton(i%)
            axis% = _lastaxis(i%)
    end if
next i%
_dest 0

if controller% = 0 and buttons% = 0 and axis% = 0 then
    cls
    displayTextCenter _
        display&, _
        screenWidth%/2, screenHeight%/2 - 2 * _fontheight, _
        _rgb(255,63,63), _
        "No gamepad device found !"
    displayTextCenter _
        display&, _
        screenWidth%/2, screenHeight%/2 + _fontheight, _
        _rgb(255,63,63), _
        "Connect a joystick then relaunch this program."
    color _rgb(127,127,127)
    end
end if

lastPressedButton% = -1
lastUsedAxis% = -1

fps% = 60
clstep% = 255 \ fps%
bfm% = 4 * buttons% - 1
axm% = axis% \ 2
xl% = (screenWidth% - 30 * (bfm% \ 4 + 1)) \ 2

redim bf%(0 to bfm%)
redim ax(1 to axis%) as axis_amplitude_type
resetAxisAmplitude ax()

do
    _limit fps%

    _dest page0&
    color _rgb(0,0,0),_rgb(0,0,0)
    cls

    if lastUsedAxis% > -1 then
        msg$ = "last pressed button : " + _tostr$(lastPressedButton%)

    else
        msg$ = "last pressed button : none"
    end if

    displayTextAlignLeft _
        page0&, _
        10, 30, _
        _rgb(160,160,160), _
        "last pressed button : " + _tostr$(lastPressedButton%)

    if lastUsedAxis% > 0 then
        msg$ = "max amplitude used axis : " + _tostr$(lastUsedAxis%) + " (press keyboard to reset)"
    else
        msg$ = "max amplitude used axis : move axis needed"
    end if

    displayTextAlignLeft _
        page0&, _
        10, 50, _
        _rgb(160,160,160), _
        msg$

    displayTextAlignLeft _
        page0&, _
        10, screenHeight% - _fontheight, _
        _rgb(160,160,160), _
        "Quit: press Escape"

    displayTextAlignLeft _
        page0&, _
        10, 10, _
        _rgb(160,160,160), _
        "device #"+_tostr$(controller%)+" : "+_tostr$(buttons%)+" buttons, "+_tostr$(axis%)+" axis."

    displayTextAlignLeft page0&, 10, 130, _rgb(127,127,127), "strig(??,1)"

    for i%=0 to bfm%

        p% = strig(i%,1)
        if p% then
            bf%(i%) = fps%
            c& = _rgb(255,0,0)
            lastPressedButton% = i% \ 4 + 1
        else
            if bf%(i%) = 0 then
                c& = _rgb(63,63,63)
            elseif bf%(i%) > 0 then
                bf%(i%) = bf%(i%) - 1
                c& = _rgb(clstep% * bf%(i%),clstep% * bf%(i%),0)
            end if
        end if
        t$ = str$(i%)

        displayTextAlignRight _
            page0&, _
            xl% + 50 + 30 * (i% \ 4), 100 + 30 * (i% mod 4), _
            c&, _
            t$
    next i%

    for i% = 1 to axm%
        for d% = 0 to 1
            px% = stick(d%,i%)
            y% = 200 + 2.5 * _fontheight * i%
            axi%  = 2*(i% -1) + d% + 1
            if px% < ax(axi%).min then ax(axi%).min = px%
            if px% > ax(axi%).max then ax(axi%).max = px%

            displayTextAlignLeft _
                page0&, _
                10, y% + d% * 1.25 * _fontheight, _
                _rgb(127,127,127), _
                "stick("+_tostr$(d%)+","+_tostr$(i%)+")"

            displayTextCenter _
                page0&, _
                110 + 2 * px%, y% + d% * 1.25 * _fontheight, _
                _rgb(63,255,63), _
                right$("00"+_tostr$(px%),3) '+"("+_tostr$(ax(axi%).amplitude)+"):"+_tostr$(axi%)

            displayTextAlignLeft _
                page0&, _
                110 + 2 * ax(axi%).min - 2.5 * _fontwidth, y% + d% * 1.25 * _fontheight, _
                _rgba(0,255,0,128), _
                "["
            displayTextAlignRight _
                page0&, _
                110 + 2 * ax(axi%).max + 2.5 * _fontwidth, y% + d% * 1.25 * _fontheight, _
                _rgba(0,255,0,128), _
                "]"

        next d%
    next i%

    max% = 20
    for i% = lbound(ax) to ubound(ax)
        ax(i%).amplitude = ax(i%).max - ax(i%).min
        if ax(i%).amplitude > max% then
            lastUsedAxis% = i%
            max% = ax(i%).amplitude
        end if
    next i%

    _dest 0
    _putimage , page0&, 0

    if inkey$ = chr$(27) then system
    if _keyhit then
        resetAxisAmplitude ax()
        lastUsedAxis% = -1
    end if

loop

sub resetAxisAmplitude(aa() as axis_amplitude_type)
    for i% = lbound(aa) to ubound(aa)
        aa(i%).min = 255
        aa(i%).max = 0
    next i%
end sub

sub displayTextCenter(d&,x%,y%,c&,t$)
    _dest d&
    color c&, _rgba(0,0,0,0)
    _printstring(x% - _printwidth(t$,d&)/ 2,y%),t$
end sub

sub displayTextAlignLeft(d&,x%,y%,c&,t$)
    _dest d&
    color c&, _rgba(0,0,0,0)
    _printstring(x%,y%),t$
end sub

sub displayTextAlignRight(d&,x%,y%,c&,t$)
    _dest d&
    color c&, _rgba(0,0,0,0)
    _printstring(x% - _printwidth(t$,d&),y%),t$
end sub
Reply


Messages In This Thread
gamepad tester - by Herve - 09-07-2025, 09:12 PM
RE: gamepad tester - by Herve - 09-09-2025, 07:10 PM
RE: gamepad tester - by Unseen Machine - 09-09-2025, 10:28 PM
RE: gamepad tester - by SMcNeill - 09-10-2025, 12:21 AM
RE: gamepad tester - by Herve - 09-10-2025, 06:53 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)