#!/usr/bin/python2
# -*- coding: utf-8 -*-
#
# http://www.forum-raspberrypi.de/Thread-reboot-shutdown-pi-reboot-windows-rechner?pid=265171#pid265171
#
# v0.1 by meigrafd
#
from __future__ import print_function
from time import sleep, time
from RPi import GPIO
from Queue import Queue
from functools import partial
def interrupt_Event(q, channel):
q.put( (channel, GPIO.input(channel)) )
def main(switchPi=11, switchWin=17, specialTime=3):
GPIO.setmode(GPIO.BCM)
GPIO.setup(switchPi, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(switchWin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
queue=Queue()
triggerTime=0
GPIO.add_event_detect(switchPi, GPIO.BOTH, callback=partial(interrupt_Event, queue), bouncetime=150)
GPIO.add_event_detect(switchWin, GPIO.BOTH, callback=partial(interrupt_Event, queue), bouncetime=150)
try:
while True:
job = queue.get()
pin = job[0]
state = job[1]
if pin == switchPi:
if state == GPIO.HIGH:
triggerTime = time()
elif state == GPIO.LOW:
triggerTime = time() - triggerTime
if triggerTime < specialTime:
print("reboot pi")
elif triggerTime > specialTime:
print("shutdown pi")
else:
print("time '%s' not valid" % triggerTime)
elif pin == switchWin:
if state == GPIO.HIGH:
triggerTime = time()
elif state == GPIO.LOW:
triggerTime = time() - triggerTime
if triggerTime > specialTime:
print("reboot win")
else:
print("time '%s' not valid" % triggerTime)
except (KeyboardInterrupt, SystemExit):
GPIO.cleanup()
print("\nQuit\n")
if __name__ == "__main__":
main()
#EOF