-
Notifications
You must be signed in to change notification settings - Fork 0
/
race_controller_mock_GPIO.py
61 lines (47 loc) · 1.14 KB
/
race_controller_mock_GPIO.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
START = 25
LANE1 = 18
LANE2 = 17
LANE3 = 27
LANE4 = 22
LANE5 = 23
LANE6 = 24
LANE_GPIO_PORTS = [LANE1,LANE2,LANE3,LANE4,LANE5,LANE6]
BCM = None
IN = None
PUD_DOWN = None
RISING = None
FALLING = None
# interupt like behaviour mocked from
# http://code.activestate.com/recipes/203830-checking-for-a-keypress-without-stop-the-execution/
import threading
import time
from random import randint
class Monitor(threading.Thread):
def __init__(self, lane, callback):
threading.Thread.__init__(self)
self.lane = lane
self.callback = callback
def run(self):
while 1:
time.sleep(randint(10,20))
self.callback(self.lane)
key_thread = None
def setmode(x):
pass
def setup(*args, **kwargs):
pass
def input(*args, **kwargs):
if args[0] == START:
second = int(time.time() % 10)
return second not in [3,7]
else:
return True
def add_event_detect(*args, **kwargs):
x = Monitor(args[0], kwargs['callback'])
# dies when parent dies
x.daemon = True
x.start()
def wait_for_edge(*args, **kwargs):
time.sleep(randint(1,5))
def cleanup():
pass