/
encode.py
executable file
·66 lines (49 loc) · 1.27 KB
/
encode.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
import pygame
from pygame.locals import *
from constants import *
import time
from csv_collector import CSVCollector
from extract_words import get_words
import pandas as pd
pygame.init()
pygame.mouse.set_visible(False)
from screen import screen
from drawstuff import *
study_time = int(time.time())
print(study_time)
eeg_fname='../data/eeg_{}.csv'.format(study_time)
word_fname = '../data/words_{}.csv'.format(study_time)
words = get_words()
words.to_csv(word_fname)
collector = CSVCollector(port='/dev/ttyUSB0', fname=eeg_fname)
collector.start()
collector.tag(0)
time.sleep(4)
def check_for_escape():
while True:
event = pygame.event.poll()
if event.type == 0:
return False
elif event.dict.get('key', -1) == K_ESCAPE:
return True
def finish_stuff(early=False):
return
for i in xrange(words.shape[0]):
d = dict(words.ix[i])
if d['is_shown'] != 1:
continue
word = d['word']
simple_slide(word)
collector.tag(word)
time.sleep(2.0)
if check_for_escape():
finish_stuff(early=True)
collector.stop()
exit()
focus_slide()
collector.tag('focus')
time.sleep(0.5)
if check_for_escape():
finish_stuff(early=True)
collector.stop()
exit()