From dcdefc469809857d581bfddf1d06f1864d3a35b5 Mon Sep 17 00:00:00 2001 From: Travis Evashkevich Date: Wed, 26 Dec 2018 12:17:18 +0000 Subject: [PATCH] Small tweak to make it so if emulationstation has crashed you can still use the buttons (or are more likely to be able to) --- SafeShutdown.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/SafeShutdown.py b/SafeShutdown.py index 7d6393b..f61a2c2 100644 --- a/SafeShutdown.py +++ b/SafeShutdown.py @@ -2,6 +2,7 @@ from gpiozero import Button, LED import os from signal import pause +import subprocess powerPin = 3 resetPin = 2 @@ -15,16 +16,26 @@ #functions that handle button events def when_pressed(): - led.blink(.2,.2) - os.system("sudo killall emulationstation && sleep 5s && sudo shutdown -h now") + try: + led.blink(.2,.2) + subprocess.call("sudo killall emulationstation && sleep 5s && sudo shutdown -h now") + except: + #assume that emulationstation is dead already (crashed?) + led.blink(.2,.2) + os.system("sudo shutdown -h now") + def when_released(): - led.on() -def reboot(): - os.system("sudo killall emulationstation && sleep 5s && sudo reboot") + led.on() +def reboot(): + try: + subprocess.call("sudo killall emulationstation && sleep 5s && sudo reboot") + except: + os.system("sudo reboot") + btn = Button(powerPin, hold_time=hold) rebootBtn = Button(resetPin) rebootBtn.when_pressed = reboot btn.when_pressed = when_pressed btn.when_released = when_released -pause() +pause() \ No newline at end of file