-
Notifications
You must be signed in to change notification settings - Fork 0
/
main
72 lines (60 loc) · 2.85 KB
/
main
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
__author__ = "Jian Wu"
__email__ = "jian.wu@tamu.edu"
from MotionNet import MotionNet
from SlideControl import PPTControler
from watch import watchData
import numpy
import heapq
import thread
WATCH_NUM = 5
DEF_MACADDR = ['2VTX', '2VR7', '2ZX7', '2VN8', '2KMX']
if __name__ == '__main__':
# Start smart watch server and start to receive data from all clients.
slides_number = {}
file_dir = "C:/Users/jxw117830/Desktop/pptfiles/"
ppt_name = 'TerraSwarm_new.pptx'
slides_map = {"Ali A": 2, "Jian": 3, "Peiming": 4, "William": 5, "Viswam": 6, "Bassem": 7}
UDP_IP_local = '192.168.0.109' # ip address of local machine
UDP_IP_remote = '192.168.0.120' # ip address of registration server
UDP_PORT_to_watch = 4570 # Port to send welcome message from local machine to watch.
UDP_PORT_from_watch = 4566 # Port to listen to for all watch raw data.
UDP_PORT_from_reg = 4564 # port to recv information from registration server.
UDP_PORT_to_reg = 4565 # Port to sent all watch raw data to registration server.
smart_watch = watchData(UDP_IP_local, UDP_PORT_from_watch, UDP_PORT_to_watch, UDP_IP_remote, UDP_PORT_from_reg, UDP_PORT_to_reg, WATCH_NUM)
thread.start_new_thread(smart_watch.read_from_watch, ())
# Start to receive data from MotionNet.
motion_sensor = MotionNet(6, 115200)
thread.start_new_thread(motion_sensor.read, ())
# Start to control slideshow
ppt = PPTControler()
file_name = file_dir + ppt_name
ppt.openSlides(file_name)
ppt.fullScreen()
cov_array = [0 for x in range(WATCH_NUM)]
# Start data processing
while True:
watch_gyro = smart_watch.get_gyro_data()
MotionNet_gyro = motion_sensor.get_data()
register_table = smart_watch.get_registration_data()
register_map = {}
for key, value in register_table.items():
if not (value == " "):
register_map[key] = value
# print register_map
if (len(register_map) > 0):
for i in range(len(register_map)):
device_name = register_map.keys()[i]
watch_index = DEF_MACADDR.index(device_name)
if (len(watch_gyro[watch_index]) == 100 and len(MotionNet_gyro)== 100):
watch_data = list(watch_gyro[watch_index])
motion_data = list(MotionNet_gyro)
cov_array[watch_index] = numpy.corrcoef(watch_data, motion_data)[0][1]
max_value = max(cov_array)
# print max_value
twolargest = heapq.nlargest(2, cov_array)
if ((max_value > 0.9) and (abs(twolargest[0] - twolargest[1]) > 0.4)):
index = cov_array.index(max_value)
watch_name = DEF_MACADDR[index]
presenter = register_map[watch_name]
slides_num = slides_map[presenter]
ppt.gotoSlide(slides_num)