Skip to content

Instantly share code, notes, and snippets.

@CookiePLMonster
Created January 2, 2019 10:54
Show Gist options
  • Save CookiePLMonster/4e7f8e14eb3ed178bdcb944e7aeafcc1 to your computer and use it in GitHub Desktop.
Save CookiePLMonster/4e7f8e14eb3ed178bdcb944e7aeafcc1 to your computer and use it in GitHub Desktop.
MegaPi modified Safe Shutdown
#!/usr/bin/env python3
from gpiozero import Button, LED
import os
from signal import pause
import subprocess
resetPin = 2
ledPin = 14
powerenPin = 4
hold = 2
led = LED(ledPin,initial_value=True)
power = LED(powerenPin,initial_value=True)
reboot_long_press = None
#functions that handle button events
def reboot_press():
global reboot_long_press
reboot_long_press = False
def reboot_hold():
led.blink(.25,.25)
global reboot_long_press
reboot_long_press = True
def reboot_release():
led.on()
output_es = int(subprocess.check_output(['/opt/RetroFlag/multi_switch.sh', '--es-pid']))
output_rc = int(subprocess.check_output(['/opt/RetroFlag/multi_switch.sh', '--rc-pid']))
if reboot_long_press:
if output_rc:
os.system("/opt/RetroFlag/multi_switch.sh --closeemu")
if output_es:
os.system("/opt/RetroFlag/multi_switch.sh --es-reboot")
else:
os.system("sudo reboot")
else:
if output_rc:
os.system("/opt/RetroFlag/multi_switch.sh --closeemu")
elif output_es:
os.system("/opt/RetroFlag/multi_switch.sh --es-restart")
rebootBtn = Button(resetPin,hold_time=hold)
rebootBtn.when_pressed = reboot_press
rebootBtn.when_held = reboot_hold
rebootBtn.when_released = reboot_release
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment