-
Notifications
You must be signed in to change notification settings - Fork 1
/
salvo.py
72 lines (57 loc) · 1.76 KB
/
salvo.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from actions.speak import Speak
from actions.move import Head
from triggers.distance import DistanceTrigger
from triggers.nfc import NfcTrigger
import sys
import RPi.GPIO as GPIO
class Salvo():
'''
Salvo il salutatore
'''
head = Head()
speak = Speak()
callbacks = {}
threadList = []
behaviour_instances = []
__is_busy = False
def init(self):
print "init init"
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
self.head.init()
print "end init"
def behave(self, bclass, event):
''' register a behaviour '''
self.behaviour_instances.append(bclass(self))
self.callbacks[event] = self.behaviour_instances[-1].callback
def run(self):
''' launch threads for all the triggers: new twitter message, new distance etc
'''
print "Salvo is alive!"
print "press q + ENTER to quit"
if 'distance' in self.callbacks:
distanceThread = DistanceTrigger(self.callbacks['distance'])
self.threadList.append(distanceThread)
if 'nfc' in self.callbacks:
nfcThread = NfcTrigger(self.callbacks['nfc'])
self.threadList.append(nfcThread)
# launch threads
for t in self.threadList:
t.start()
# no return from here
c = sys.stdin.read(1)
if c == 'q':
print "you say quit, I quit"
self.stop()
def stop(self):
print "Salvo is going to sleep..."
self.head.cleanup()
for t in self.threadList:
if t.isAlive():
t.stop()
t.join()
def is_busy(self):
return self.__is_busy
def busy(self, status):
# todo put a mutex
self.__is_busy = status