-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialParser.py
70 lines (53 loc) · 2.23 KB
/
serialParser.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
import serial
import time
#for RPi /dev/ttyACM0 for serial path
#for MacOS /dev/cu.usbmodem00001
ser = serial.Serial('/dev/cu.usbmodem00001',9600)
#this object manages serial communication between
#arduino and RPi
#format for serial communication
#signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma
#set size for heaps, note that this should be changed in later iterations
#for general implementations
#returns signal quality value
#a null object is returned when the signal quality drops
#a byte like object is returned if successful
#works as of May 4th !
def getSignalQuality(duration):
#print("entered method")
startTime = time.time()
while(time.time() < startTime + duration):
#print("entered while loop")
read_serial = ser.readline()
#print("read serial port ")
#myByteList[0] = read_serial.split(b",")
# print("made list")
myByteList = read_serial.split(b",")
#returns byte object for signal quality
#print("about to finish method and return")
return myByteList[0]
#returns attention value
#for a duration in seconds(int)
#works as of May 4th
def getAttention(duration, read_serial=None):
startTime = time.time()
#this is to ensure that we have a healthy signal
# 0 is full connection, 200 is no connection to headset
# recall that these are byte like objects as well
while (time.time() < startTime + duration and getSignalQuality(duration)== b'0') :
read_serial = ser.readline()
myByteList = read_serial.split(b",")
return myByteList[1]
#Returns the low gamma (31-40Hz) power value, associated with multi-sensory processing.
# I've found it more associated with physical movement
def getGamma(duration, read_serial=None):
startTime = time.time()
# this is to ensure that we have a healthy signal
# 0 is full connection, 200 is no connection to headset
# recall that these are byte like objects as well
#remember to check signal quality as in other methods, I removed
#this condition b/c I had to work around it
while (time.time() < startTime + duration ):
read_serial = ser.readline()
myByteList = read_serial.split(b",")
return myByteList[2]