Thanks Ronan, your script was the code I needed for my Retro RPi2!
I adjusted it to fit my GPIO stuff with some LEDs added, and attached my version in case anyone is interested. (I use the retropi 2.6 image.)
My changes:
– made it a very basic python daemon, so I could add it to init-scripts
– use BCM GPIO 3 for shutdown, since it also can startup the rpi when pulled low
– for that reason, use FALLING interrupts
– use SIG TERM for emulator, to allow clean exit (save srm?), wait 5 seconds and then send SIG KILL to the process in case TERM did not help
– added LED when nespi.py daemon is running
– added LED when emulator is running, check every second
To simplify the emulator LED, I hacked runcommand.sh to write its own PID into a temp file on start, and remove it on script end.
I also wanted my own ACT LED for sd card activity, which, as turned out, is super easy using the device tree overlay in config.txt.
dtoverlay=act_led_gpio=22