silence sphinx a bit
[saartuer.git] / tuerd
1 #!/usr/bin/python3
2 import RPi.GPIO as GPIO
3 import statemachine, actor, pins, tysock, waker, spaceapi
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 parser.add_argument("-f", "--fallback",
13                                         action="store_true", dest="fallback",
14                                         help="Fallback mode for unfunctional hardware: Depend on less sensor input")
15 args = parser.parse_args()
16 if args.debug:
17         import libtuer
18         libtuer.mailAddress = []
19 if args.fallback:
20         logger.info("Starting in fallback mode")
21 else:
22         # to avoid exceptions or getting None
23         args.fallback = False
24
25 # Not let's go!
26 logger.info("Starting up...")
27
28 # initialize GPIO stuff
29 GPIO.setmode(GPIO.BOARD)
30
31 # bring 'em all up
32 the_actor = actor.Actor()
33 the_waker = waker.Waker()
34 the_api   = spaceapi.SpaceApi(the_waker)
35 the_machine = statemachine.StateMachine(the_actor, the_waker, the_api, args.fallback)
36 the_socket = tysock.TySocket(the_machine)
37 the_pins = pins.PinsWatcher(the_machine)
38
39 # we do the socket accept thing in the main thread
40 try:
41         the_socket.accept()
42 except KeyboardInterrupt:
43         # this is what we waited for!
44         pass
45
46 logger.info("Terminating...") # somehow this does not arrive in the syslog
47
48 # bring 'em all down
49 the_waker.stop() # this one first, it "randomly" calls other threads
50 the_pins.stop() # as does this
51 the_machine.stop()
52 the_api.stop()
53 the_actor.stop()
54
55 # shutdown GPIO stuff
56 GPIO.cleanup()