mrchrisster/MiSTer_SAM

Joystick detection handling and improvement

Closed this issue · 13 comments

Some modern Bluetooth controllers create additional input devices which break functionality with SAM since they appear to SAM as devices that constantly push buttons. This thread is trying to improve on the input button detection.

SAM recognizes button pushes through monitoring the binary stream of js input devices.
Here is a script to test your input devices.

  1. SSH into the mister and type ls /dev/input
  2. Make a note of all js devices
  3. Create a file with nano joytest.py
  4. Paste the following content:
#!/usr/bin/env python

import struct
import time
import glob
import sys

packstring = "iiiiiiiiiiiiiiiiiiii"

infile_path = sys.argv[1]
EVENT_SIZE = struct.calcsize(packstring)
while True:
    try:
        file = open(infile_path, "rb")
        event = file.read(EVENT_SIZE)
        (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) = struct.unpack(packstring, event)

        if b != 8454144 or d != 25231360 or f != 42008576 or h != 58785792 or n != 109117440 or p != 125894656 or r != 142671872 or t != 159449088:
           print("Button pushed")
        time.sleep(0.2)
    except FileNotFoundError:
        print("Joystick disconnected")
        sys.exit(1)
  1. Launch ./joytest.py /dev/input/js0 and see if buttons are detected. Repeat with all other js devices

check out evdev-joystick --l
and cat /proc/bus/input/devices
Should be able to grep the name of the controller, and then dig down to figure out which js* devices it is using, etc.

Nice, that's a good idea! I'll be back at my Mister setup on Friday and can take a look then

Just updated joystick detection. @Paradox, do you have time to test?
I followed your suggestion and filter js devices through /proc/bus/input/devices to exclude motion sensor js devices

I'll check, now, but, I don't have a ps5 controller, so, someone else will need to confirm that part.

At first, it wasn't working, but, I killed all the processes related to SAM and started it again, and, now, all of my controllers work.

I'm not sure if there is an issue with stop not killing all related processes, or, just an issue with my setup, since I have been doing a lot of testing, I have to run pick up my girls from school, so, I'll look into it more, later.

It might have just needed a reboot. Great to hear your controllers are all detected now. Does button detection work on all of them?
PS5 works reliably for my 2 controllers.

Stop should have killed all joystick processes since it kills MCP. It worked for my setup just now...

The start or select button doesn't seem to work on some controllers, and the dpad doesn't trigger on any that I have noticed, but, that may be correct behavior, I think you mentioned that to me, once before.

Edit: I notice some buttons just don't trigger it, maybe a controller mapping issue?

Also, anytime I use stop, I get this message:
./media/fat/Scripts/MiSTer_SAM_on.sh: line 1686: kill: (1083) - No such process

Edit: I'm guessing inotifywait gets killed by killing one of the other processes, and that line is just in case it doesn't for some reason.

but, it does stop all SAM processes, might have just needed a reboot, like you said.

The start or select button doesn't seem to work on some controllers, and the dpad doesn't trigger on any that I have noticed, but, that may be correct behavior, I think you mentioned that to me, once before.

Edit: I notice some buttons just don't trigger it, maybe a controller mapping issue?

Yeah, the problem is that we receive raw input and when buttons are unmapped, it's kind of unpredictable how the joystick will operate. Through extensive testing we determined that for all gamepads we checked, the four main buttons seem to respond to the same binary codes. While Start/Select worked on my controller, it gave other users trouble with SAM. I never figured out how to read the dpad unfortunately...

Somewhere, in these last commits, you broke stop, it doesn't stop the currently playing game, when using playcurrentgame="No"

Edit: I'll have a fix up, soon, it was simple. Also, searching for default paths takes a second for me, why would it take you so long?

07a3bdc#commitcomment-73621091

I'll clean it up, and add a disable/enable variable, and you can test it, too.

Joystick handling and keyboard change detection have been implemented