Last active
March 29, 2018 17:50
-
-
Save sourceperl/09d8bed98e0ae6ba6b2fa0b9ad486b29 to your computer and use it in GitHub Desktop.
Pi Desktop manager
This file contains hidden or 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/env python | |
import RPi.GPIO as GPIO | |
import time | |
import os, sys | |
import signal | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(31, GPIO.OUT) | |
GPIO.setup(33, GPIO.IN) | |
GPIO.output(31, GPIO.LOW) | |
def shutdown_system(channels): | |
os.system("sync") | |
time.sleep(1) | |
os.system("shutdown -h now") | |
sys.exit() | |
GPIO.add_event_detect(33, GPIO.RISING, callback=shutdown_system) | |
while True: | |
time.sleep(1) |
This file contains hidden or 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
[Unit] | |
Description=Pi-Desktop power on/off manager | |
After=local-fs.target | |
[Service] | |
Type=simple | |
ExecStart=/usr/local/bin/pi-desktop-manager | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment