Test any joystick

Mac OSX specific forum
User avatar
Piero
Addict
Addict
Posts: 1044
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Test any joystick

Post by Piero »

I'm posting also because it shows how to manage "fast streaming" outputs…
Note: PB does not "fully see" some stuff, but this (SDL2) does!

Code: Select all

; Test any joystick/gamepad on PB!

; You will need joyosc:
; https://github.com/danomatika/joyosc
; and stdbuf:
; https://formulae.brew.sh/formula/coreutils#default

; To stop, better quit joyosc (or close the window)

Procedure Shell(ShellCommand$)
   Protected shell = RunProgram("/bin/zsh","-l","",
      #PB_Program_Open|#PB_Program_Write|#PB_Program_Read)
   If shell
      WriteProgramStringN(shell,ShellCommand$)
      WriteProgramData(shell,#PB_Program_Eof,0)
      While ProgramRunning(shell)
         If AvailableProgramOutput(shell)
            Debug ReadProgramString(shell)
         EndIf
      Wend
      CloseProgram(shell)
   EndIf
EndProcedure

Shell(~"stdbuf -oL joyosc -ew") ; full
; Normalized output:
; Shell(~"stdbuf -oL joyosc -ew -jn | stdbuf -oL awk -F'[/: ]' '{print $2\":\"$(NF-3)\":\"$(NF-1)\":\"$NF}'")
Edit: small fix to the normalized example (-ew -jn)