Open the space when the switch is toggled while we are closed
[saartuer.git] / tuerd
1 #!/usr/bin/python3
2 import RPi.GPIO as GPIO
3 import statemachine, actor, pins, tysock, waker
4 from libtuer import logger
5 import argparse
6
7 # Parse arguments
8 parser = argparse.ArgumentParser(description='Run a door')
9 parser.add_argument("-d", "--debug",
10                                         action="store_true", dest="debug",
11                                         help="Don't send emails")
12 args = parser.parse_args()
13 if args.debug:
14         import libtuer
15         libtuer.mailAddress = []
16
17 # initialize GPIO stuff
18 GPIO.setmode(GPIO.BOARD)
19
20 # bring 'em all up
21 the_actor = actor.Actor()
22 the_machine = statemachine.StateMachine(the_actor)
23 the_socket = tysock.TySocket(the_machine)
24 the_pins = pins.PinsWatcher(the_machine)
25 the_waker = waker.Waker(the_machine)
26
27 # we do the socket accept thing in the main thread
28 try:
29         the_socket.accept()
30 except KeyboardInterrupt:
31         # this is what we waited for!
32         logger.info("Got SIGINT, terminating...")
33         pass
34
35 # bring 'em all down
36 the_waker.stop()
37 the_pins.stop()
38 the_machine.stop()
39 the_actor.stop()
40
41 # shutdown GPIO stuff
42 GPIO.cleanup()