Getting the Reset Button Working and Completing the RetroPie
In a previous post I talked about adding a status light and a power switch to my mini arcade game box. My case is made to look like a miniature Nintendo entertainment System. If you recall, the original had two buttons: the one on the left was the power button, and the one on the right was a game reset button. I created a lego brick with a microswitch attached to hook up the power button. But I hadn't yet enabled the second button.
Making another one of these was a piece of cake! |
Making another microswitch lego brick is pretty simple, but I didn't know how I was going to translate its click to instruct the game emulator to reset the currently running game.
Most of the games on my box run on LibRetro enabled emulators. LibRetro standardizes the behaviour of the emulators and provides extra stuff like real-time rewind, screenshot capabilities, game saving, cheats, and common control settings. It also adds keyboard shortcut commands - by default you can press the letter "H" to send the "RESET" command.
Bingo! I just needed to find a way to have the button emulate the keyboard press of the letter "H". I did some digging and I came across a library called uinput that is designed to do just what I needed. With the button wired to GPIO 13, I made a simple python script to listen for the button press. Using the uinput library, I was able to get the letter "H" output to the command line when I pressed the reset button.
Time to celebrate? Not so fast... it turns out that LibRetro needs to initialize an attached keyboard as an input device. Since there is no actual keyboard attached, output from uinput was not recognized by the emulators. To get this to work, I'd need to write a driver for uinput that would fool the system into thinking there was an attached USB keyboard. Yeah... cuz that's something I can do...
Back to the drawing board.
More Google Fu turned up another way to interface with LibRetro. There is a configuration that enables network socket commands to be sent to the emulator, including the 'RESET' instruction. I had to dig a little further to find a working example, but eventually I found this discussion which gave me everything I needed to write my own python script.
Did it work? Watch the video to see!
With this done, I'm pretty much finished with my retro gaming box. Having both buttons function faithfully like the original NES is about as authentic of an experience that I can make!
Comments
Post a Comment