-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.py
More file actions
37 lines (25 loc) · 925 Bytes
/
Copy pathbutton.py
File metadata and controls
37 lines (25 loc) · 925 Bytes
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
33
34
35
36
37
import subprocess
import socket
from gpiozero import Button, LED
from signal import pause
#############################################################################################
# Sends 'message' to port 55355 for RetroArch's network commands
def retroarch_command():
print "reset...\n"
sock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
sock.sendto("RESET", ("127.0.0.1", 55355))
#############################################################################################
# Safely shuts-down the Raspberry Pi
def shutdown():
print "shutdown...\n"
subprocess.call("sudo shutdown -h now", shell=True)
#############################################################################################
led = LED(14)
resetbtn = Button(2)
offbtn = Button(15)
while True:
led.on()
offbtn.when_pressed = shutdown
resetbtn.when_pressed = retroarch_command
pause()