-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgatherGestures.py
executable file
·143 lines (119 loc) · 3.97 KB
/
gatherGestures.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
#Serial connection
import serial
#COM_LIST = ['COM3', 'COM4', 'COM5']
# configure the serial connections (the parameters differs on the device you are connecting to)
ser = 0
which_com = 0
for i in range(0, 16):
try:
com = 'COM' + str(i)
ser = serial.Serial(com)
except:
pass
else:
which_com = com
print "COM PORT:", which_com, " Found!"
break;
if which_com == 0:
print "No COM ports found!"
import win32api, win32con, win32gui
from time import sleep
# def click(x,y):
# win32api.SetCursorPos((x,y))
# win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
# win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
import webbrowser
new = 2 # open in a new tab, if possible
# open a public URL, in this case, the webbrowser docs
url = "http://google.com"
import speech
def move(x,y):
win32api.SetCursorPos((x,y))
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
#double click
#win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
#win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def get_pos():
flags, hcursor, (x,y) = win32gui.GetCursorInfo()
return x, y
movement = 12
# import win32com
# shell = win32com.client.Dispatch("WScript.Shell")
# shell.Run("notepad");
# win32api.Sleep(100)
# shell.AppActivate("myApp")
# win32api.Sleep(100)
# shell.SendKeys("%")
# win32api.Sleep(500)
# shell.SendKeys("t")
# win32api.Sleep(500)
# shell.SendKeys("r")
# win32api.Sleep(500)
# shell.SendKeys("name")
# win32api.Sleep(500)
# shell.SendKeys("{ENTER}")
# win32api.Sleep(2500)
def main(name):
filename = name + ".txt"
f = open("data\\" + filename, "a")
track_data = 0;
sensor_data = [];
sensor_state = 0;
sensor0 = 0;
sensor1 = 0;
sensor2 = 0;
count = 0
while(True):
#print current_x, current_y
try:
message = ser.read()
current_x, current_y = get_pos()
if message == 'd':
#speech.say("Processing!")
print "Saving! " + str(count)
count += 1
write_data(sensor_data, f, name);
sensor_data = []
else:
#print "Track data: " + str(track_data)
message = ord(message)
if track_data == 0:
sensor_state = message;
track_data += 1;
elif track_data == 1:
sensor0_data = message;
track_data += 1;
elif track_data == 2:
sensor1_data = message;
track_data += 1;
elif track_data == 3:
sensor2_data = message;
new_array = [sensor_state, sensor0_data, sensor1_data, sensor2_data]
sensor_data.append(new_array)
track_data = 0;
except (KeyboardInterrupt, SystemExit):
f.close()
raise
except:
raise;
#Brainstorm features for classifying features (worth to implement?)
#Numbers for each sensor: is it increasing, decreasing, staying the same? (discusses up vs down)
#The average of all three sensors (if all of them are the same height and all active, most likely a line)
#Circle: did it go back to where it was
# What's being given? All three numbers at the same time
# What can I do? Plot numbers, calculate all the features
def write_data(array, file, name):
print array
string = str(array)[1:-1]
string += ", " + name
file.write(string)
file.write("\n")
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: gatherGestures.py filename"
sys.exit(1)
main(sys.argv[1]);