-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscriptmanager.py
More file actions
53 lines (36 loc) · 1.06 KB
/
scriptmanager.py
File metadata and controls
53 lines (36 loc) · 1.06 KB
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
import time
import threading
from networktables import NetworkTables as nt
import tape3
import ball
import thread_example
ip = "10.15.12.2"
nt.initialize(server=ip)
table = nt.getTable("chooser_data")
stop_message = [0]
def start_tape():
tape3.main(stop_message)
def start_ball():
ball.main(stop_message)
def start_example():
thread_example.main(stop_message)
def valueChanged(table, key, value, isNew):
print("Value changed:", table, key, value)
# 0 stops everything
# 1 stops everything but tape detector
# 2 stops everything but ball detector
stop_message[0] = 0
value = int(value)
stop_message[0] = value
if value != 0:
time.sleep(1)
print("[*]Starting thread: {}".format(value))
t = threading.Thread(target=target_list[value])
t.start()
def connectionListener(info, connected):
print(info, "Connected:", connected)
target_list=[0, start_tape, start_ball, start_example]
nt.addConnectionListener(connectionListener)
table.addEntryListener(valueChanged)
while True:
time.sleep(5)