Created
March 26, 2019 19:24
-
-
Save werpu/99ac729a9a66ff3c710bf1d34c7b3db2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
## | |
## General universal kill switch service | |
## | |
## The idea is to iterate over a list of possible | |
## emulators if the correct button combo is pressed | |
## and then kill the appropriate processes | |
## | |
set timeout -1 | |
## emulators | |
## array holding our emus | |
## the key is the emulation executable the value is a descriptor string | |
array set emulators { | |
retroarch "retroarch emulation engine" | |
scummvm "scummvm adventure emulator" | |
mupen64plus "mupen64plus c64 emulator" | |
minivmac "minivmac emulator" | |
ppsspp "ppsspp psp emulator" | |
quasi88 "quasi88 ti88 emulator" | |
reicast "reicast dreamcast emulator" | |
stella "stella atari vcs emulator" | |
vice "vice c64 emulator" | |
ti99sim "ti99sim ti99 emulator" | |
yabause "yabause sega saturn emulator" | |
xm7 "xm7 FM7 emulator" | |
advmame "advmame advanced mame" | |
atari800 "atari800 emulator" | |
basilisk "basilisk mac emulator" | |
dosbox "dosbox dos vm" | |
drastic "drastic NDS emulator" | |
frotz "frotz infocom emulator" | |
hatari "hatari atari st emulator" | |
jzintv "jzintv intellivision emulator" | |
linapple "linapple apple II emulator" | |
simcoupe "simcoupe SAM Coupe emulator" | |
amiberry "amiberry Amiga emulator" | |
} | |
#button code which should trigger our kill chain | |
set BTN_CODE "number 13, value 1\r" | |
#joystick marker | |
set JOYSTICK "usb-Ultimarc_I-PAC_Ultimate_7-if02-joystick"; | |
spawn ls -la /dev/input/by-id/ | |
expect "$JOYSTICK" { | |
sleep 1 | |
} | |
## lets delay a little bit | |
## just in case something needs to catch up | |
sleep 5 | |
## span jstest on the joystick you want to watch | |
## you can use the mapped id instead of a raw js or event number | |
spawn jstest --nonblock "/dev/input/by-id/$JOYSTICK" | |
while { 1 } { | |
## ymmv this is the key combo I use, you can use whatever jstest reports for your kill button | |
## you also can use a sequence of buttons by using two expects in a sequence with a maximum timeframe | |
expect "$BTN_CODE" { | |
##the trick is to kill all running emulators one of them might be running | |
##and if not it is ignored by an empty catch | |
foreach {emu desc} [array get emulators] { | |
catch { | |
exec -ignorestderr -- killall -9 $emu | |
# if the kill was successful we do not bomb out and can give | |
# feedbackl | |
puts "stopped $desc" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment