Ligne 72 : |
Ligne 72 : |
| | | |
| {{asm-begin}} | | {{asm-begin}} |
| + | {{asm-row|img=Rasp-Retro-Games-Arcade-Control-30.jpg}} |
| + | {{asm-text}} This is an example of a case I made from acrylic, but any workable material will do. '''A cigar box makes a great fit'''! |
| + | |
| + | The case should be at least 50mm (2 in.) deep to accommodate the buttons and solderless connectors. |
| + | |
| + | {{asm-row|img=Rasp-Retro-Games-Arcade-Control-31.jpg}} |
| + | {{asm-text}} The shelf at the top of the case holds a small USB keyboard. This is a catch-all for seldom-used functions (e.g. game start). Only the essential controls were assigned to arcade buttons. Add others if you like! |
| + | |
| + | {{asm-row|img=Rasp-Retro-Games-Arcade-Control-32.jpg}} |
| + | {{asm-text}} Here’s the joystick and two buttons plugged directly into the Raspberry Pi GPIO header as previously described. |
| | | |
| {{asm-end}} | | {{asm-end}} |
| | | |
| + | == Un dernier élément == |
| + | Our “retrogame” utility is the software glue that joins these keyboard-driven games to our GPIO-connected controls. |
| + | |
| + | [https://github.com/adafruit/Adafruit-Retrogame Download retrogame from GitHub]. Select the “download ZIP” button and uncompress this file on your Raspberry Pi. |
| + | |
| + | '''A pre-built version of retrogame is included in the ZIP file. If using the joystick and button layout described above, this program can be used as-is'''. Otherwise, the C source code needs some editing, and you’ll need to compile it (a Makefile is provided) after making changes. The GPIO pin to keyboard remapping is currently handled with a table in the source…this should be edited to match your unique wiring setup. |
| + | |
| + | <nowiki>cd Adafruit-Retrogame |
| + | nano retrogame.c</nowiki> |
| + | |
| + | (Of course you can substitute your editor of preference there — “nano” is easier for beginners.) |
| + | |
| + | Starting around line 77 you’ll see a table resembling this: |
| + | |
| + | <nowiki>struct { |
| + | int pin; |
| + | int key; |
| + | } io[] = { |
| + | // Input Output (from /usr/include/linux/input.h) |
| + | { 25, KEY_LEFT }, |
| + | { 9, KEY_RIGHT }, |
| + | { 10, KEY_UP }, |
| + | { 17, KEY_DOWN }, |
| + | { 23, KEY_LEFTCTRL }, |
| + | { 7, KEY_LEFTALT } |
| + | };</nowiki> |
| + | |
| + | Each line in this table contains two elements. The first is a GPIO pin number (where a button or one direction from a joystick is attached), the second is the corresponding key code to be generated by this control. A list of valid key code names can be found in the file /usr/include/linux/input.h starting around line 178. Remember to enclose each pin/key pair in {curly braces} with a comma between them. |
| + | |
| + | '''By default, the code is set up to match our example “no solder” controller wiring. This also works directly with the standard MAME controls. So you might not need to change anything; the pre-built version may have you covered.''' |
| + | |
| + | If you need an extra ground pin (and have extra GPIO pins available that you’re not using for controls), set the key code to GND instead. |
| + | |
| + | Write your changes to the file and exit the editor, then type: |
| + | |
| + | <nowiki>make</nowiki> |
| + | |
| + | This should build the executable '''retrogame''' utility. If you instead get an error message, there’s a problem in the edited table — most likely a missing curly brace, comma or semicolon. |
| + | |
| + | '''But wait'''...we’re not ready to run yet! Retrogame requires the uinput kernel module. This is already present on the system but isn’t enabled by default. For testing, you can type: |
| + | |
| + | <nowiki>sudo modprobe uinput</nowiki> |
| + | |
| + | To make this '''persistent between reboots''', append a line to /etc/modules: |
| + | |
| + | <nowiki>sudo sh -c 'echo uinput >> /etc/modules'</nowiki> |
| + | |
| + | '''Now''' we’re in good shape to test it! |
| + | |
| + | Retrogame needs to be run as root, i.e.: |
| + | |
| + | <nowiki>sudo ./retrogame</nowiki> |
| + | |
| + | Give it a try. If it seems to be working, press control+C to stop the program and we’ll then set up the system to launch this automatically in the background at startup. |
| + | |
| + | <nowiki>sudo nano /etc/rc.local</nowiki> |
| + | |
| + | Before the final “exit 0” line, insert this line: |
| + | |
| + | <nowiki>/home/pi/Adafruit-Retrogame/retrogame &</nowiki> |
| + | |
| + | If you placed the software in a different location, this line should be changed accordingly. “sudo” isn’t necessary here because the rc.local script is already run as root. |
| + | |
| + | Reboot the system to test the startup function: |
| | | |
| + | <nowiki>sudo reboot</nowiki> |
| | | |
| + | The software will now be patiently waiting in the background, ready for use with any emulators. |
| | | |
| + | Each emulator will have its own method for configuring keyboard input. Set them up so the keys match your controller outputs. Up/down/left/right from the arrow keys is a pretty common default among these programs, but the rest will usually require some tweaking. |
| | | |
| {{Rasp-Retro-Games-TRAILER}} | | {{Rasp-Retro-Games-TRAILER}} |