I'm just trying to get PiMAME running without a keyboard. I'm hoping to use this as a MAME machine, where it's possible to scroll through menus with the joystick, select from menus with a joystick button, etc.
I have no idea where to begin - I basically just want to map keys to joystick functions.
I tried to install xev to do something like this, but I couldn't get it working. I even tried copying it off my Mint box, no luck. If there's a console where I can get that data, that's awesome - just let me know how to access it! :)
And actually, I reinstalled PiMAME because I wanted a clean install after I did so much mucking about working on the roms and joystick, and now the joystick doesn't work in the emulators anymore.
I have not installed a driver for it, but it shows up in /dev/input/ as js0.
I have a PS3 dual shock usb connected to the pi with the following results which may help:
jstest shows all buttons & axis working great :)
advmenu - works but control mapping seems fixed - i.e. I have to use the joystick rather than the d-pad etc (I could be missing something here)
advmame - works up to button 12 (or it may have been 11 or 13) - anything after that does not work which is problem as the main X & O buttons are numbered higher than this so cannot be used :(
pi-snes - doesn't work - googling around I think someone had found this was due to it expecting a max of 5 axes but the dualshock has many more. Someone got it to work by changing unix.cpp (i think) and removing the check on 5 axes limit.
Let me know if you are interested in more details and I'll do some research for you with more exact results!
Rather than use a USB joystick, I rewired some arcade parts to GPIO (used a breakout cobbler board from adafruit) and then went and compiled their retrogame code to map the GPIO pins to keyboard presses. It was fairly trivial to get the buttons I wanted mapped to the default mame keys (including ESC, so I can go completely keyboard free!)
I also needed to enable the uinput module at boot time.
I don't know if there is a module that needs to be loaded before USB joypads can be used in linux, but I suspect there is.
What I did was to get a cobbler breakout board from adafruit and solder all my connections to that. It's nicely laid out with solder holes, and has a ribbon cable so that you can connect it to the pi. That way avoids soldering pins directly to the pi, and I can easily unhook the pi from all the buttons if/when I need to pull the pi out and do work on it.
I simply edited the retrogame code and added what keys I wanted for each pin, compiled it, dropped it in /home/pi. Then I set up uinput to load at boot time and got rc.local to start it -- as per the instructions.
All the buttons and joystick directions need to have a common "ground" connection (so one side of each button and joystick switch are all wired together in a ground circuit), and that in turn is wired to the ground pin on the board. Then you wire each direction/button to it's respective GPIO pin. I managed to cram 4 joystick directions, 5 game buttons, player 1&2 buttons, as well as coin insert, ESC, and I have one spare (which I may wire to F3 for reset, or TAB for menu -- not sure yet -- but this could have been a sixth button if I had room for one on my case.)
To go completely keyboard free with the PI, I created a short script to act as a "maintenance window" before automatically starting up any emulator. This gives you a 3 second window to break out of the script with Ctrl-C and get a bash shell. Unless you've been silly and configured both CTRL and C to seperate output buttons, you won't be able to break out of the script without a keyboard attached - which is the goal. Without this script, and since the emulator is going to be autostarting, we'd have no opportunity to stop the pi and we'd likely lose control of it!
#!/bin/bash echo "Loading MAME! Ctrl-C for maintenance" sleep 3
I edited /home/pi/.profile. First task was to comment out the line that starts the pimame menu.
After that, I added three lines: First I called the maintenance window script. Next I called mame4all Lastly I called shutdown -h now
So the way it works is that the pi starts up, triggers the maintenance window script, which if left alone, automatically finishes and then starts up MAME. Since I have ESC wired to one of my buttons, when I am done playing, hitting it closes MAME and then .profile triggers off the shutdown command.
Now I am keyboard free! I'll post some photos later in another thread.
the PiMAME menu is made in Python, and looks for a keypress, I wonder if I could use something to read in the usb joystick info. I don't know yet, but its a possibility.
I managed to hack the menu.py script to read the joystick controls using the pygame add-on but there's a known bug in the pygame binary for the raspberry pi where it constantly sends debug info to the screen. There's an updated version of the source code with the bug fixed but I haven't got a clue how to go about compiling it for the pi. If someone can point me in the right direction, it would be much appreciated.
I've managed to get around the pygame joystick bug by writing the joystick event handler slightly differently and it now works fine with the joystick! Woohoo!! However, in doing so, I've had to disable the keyboard input as it uses Curses commands which doesn't really work with the way the pygame joystick code needs to be written. I'm trying to use the pygame keyboard events instead which should be fairly straight-forward as it's similar to the joystick code, but I can't get it to work. Anyone got any experience of this?
I've discovered why I can't read keyboard presses in Pygame in a console window. Without rewriting the entire interface, I'll have to do it another way, which can wait for the time being. It works from the joystick which is what I wanted it to do. Let me know if you want the program.