forked from RetroFlag/retroflag-picase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SafeShutdown.py
32 lines (29 loc) · 700 Bytes
/
SafeShutdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
from gpiozero import Button, LED
import os
from signal import pause
powerPin = 3
resetPin = 2
ledPin = 14
powerenPin = 4
hold = 1
led = LED(ledPin)
led.on()
power = LED(powerenPin)
power.on()
#functions that handle button events
def when_pressed():
led.blink(.2,.2)
os.system("sudo killall emulationstation")
os.system("sleep 5s && sudo shutdown -h now")
def when_released():
led.on()
def reboot():
os.system("sudo killall emulationstation")
os.system("sleep 5s && 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()