mrchrisster / MiSTer_SAM

154 stars 23 forks source link

Joystick detection handling and improvement #131

Closed mrchrisster closed 2 years ago

mrchrisster commented 2 years ago

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)

5. Launch `./joytest.py /dev/input/js0` and see if buttons are detected. Repeat with all other js devices
Paradox commented 2 years ago

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.

mrchrisster commented 2 years ago

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

mrchrisster commented 2 years ago

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

Paradox commented 2 years ago

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

Paradox commented 2 years ago

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.

mrchrisster commented 2 years ago

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...

Paradox commented 2 years ago

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?

Paradox commented 2 years ago

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.

Paradox commented 2 years ago

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

mrchrisster commented 2 years ago

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...

Paradox commented 2 years ago

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?

https://github.com/mrchrisster/MiSTer_SAM/commit/07a3bdc98688139942b93e0b7789c12e25a8cfb0#commitcomment-73621091

Paradox commented 2 years ago

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

mrchrisster commented 2 years ago

Joystick handling and keyboard change detection have been implemented