-
Notifications
You must be signed in to change notification settings - Fork 0
/
hack1.py
44 lines (38 loc) · 1.06 KB
/
hack1.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
import emokit
from emokit import emotiv
import platform
if platform.system() == "Windows":
import socket
import gevent
import numpy as np
import serial
if __name__ == "__main__":
headset = emotiv.Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
try:
arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ser = serial.Serial('COM3', 9600)
while True:
packet = headset.dequeue()
#packet.gyro_x, packet.gyro_y
arr.append(packet.P8[0])
del arr[0]
variance = np.var(arr)
if (variance > 900):
ser.write('1')
print "ACTIVE"
else:
ser.write('0')
print "INACTIVE"
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
ser.close()
finally:
headset.close()
ser.close()