Skip to content

Commit

Permalink
Second integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelvianna committed Jan 24, 2016
1 parent f9d8d4b commit 413a026
Show file tree
Hide file tree
Showing 60 changed files with 43 additions and 15 deletions.
3 changes: 3 additions & 0 deletions eye_keyboard/components/phrase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf8

import pygame as pg

from hashlib import md5
Expand Down Expand Up @@ -32,6 +34,7 @@ def read(self):
file_path = join('/', 'tmp', file_name)
with open(file_path, 'w') as f:
params = st.VOCALWARE_PARAMS
self.text = 'espaço'
params[st.VOCALWARE_TXT] = self.text
checksum = md5(st.VOCALWARE_MD5_KEY.format(**params)).hexdigest()
params[st.VOCALWARE_CHECKSUM] = checksum
Expand Down
6 changes: 4 additions & 2 deletions eye_keyboard/components/table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf8

import pygame as pg

from collections import defaultdict
Expand Down Expand Up @@ -62,11 +64,11 @@ class Table(object):
SPACE = 'ESPACO'

LABELS = [
['A', 'B', 'C', 'D', 'E', 'F', ''],
['A', 'B', 'C', 'D', 'E', 'F', SPACE],
['G', 'H', 'I', 'J', 'K', 'L', 'M'],
['N', 'O', 'P', 'Q', 'R', 'S', ''],
['T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
[SPACE, ERASE, CLEAN, READ, ALERT, QUIT, '']
[ERASE, CLEAN, READ, ALERT, QUIT, '', '']
]

def __init__(self):
Expand Down
49 changes: 36 additions & 13 deletions eye_keyboard/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

class Control(object):

THINK_TIME = 3.0
CAPTURE_TIME = 2.5
THINK_TIME = 2.5

def __init__(self, tracker):
self.row_num = 0
Expand All @@ -26,7 +25,7 @@ def __init__(self, tracker):
self.num_frames = 0
self.press_enter = False
self.done = False
self.wait_time = self.CAPTURE_TIME
self.wait_time = self.THINK_TIME
self.tracker = tracker
self.eye_threshold = tracker.settings[st.PUPIL_POSITION][1]
self.screen = self._init_screen()
Expand All @@ -45,6 +44,7 @@ def start(self):
self._wait_loop()
if self.press_enter or self._move_eyes_upwards():
self._execute_choice()
self._wait_loop(capture=False)
else:
self._move_table_forward()

Expand All @@ -54,19 +54,40 @@ def _play_step_sound(self):
file_name = '{}.wav'.format(self.row_num + 1)
file_path = join(sound_dir, 'numbers', file_name)
else:
letter = self.table.cells[self.row_num][self.col_num].label.lower()
if not letter or letter not in lowercase:
label = self.table.cells[self.row_num][self.col_num].label.lower()
if not label:
return
if label == 'voltar':
file_name = 'voltar.mp3'
file_path = join(sound_dir, file_name)
elif label == 'som':
file_name = 'som.mp3'
file_path = join(sound_dir, file_name)
elif label == 'sair':
file_name = 'sair.mp3'
file_path = join(sound_dir, file_name)
elif label == 'limpar':
file_name = 'limpar.mp3'
file_path = join(sound_dir, file_name)
elif label == 'ler':
file_name = 'ler.mp3'
file_path = join(sound_dir, file_name)
elif label == 'espaco':
file_name = 'espaco.mp3'
file_path = join(sound_dir, file_name)
elif label in lowercase:
file_name = '{}.mp3'.format(label)
file_path = join(sound_dir, 'letters', file_name)
else:
return
file_name = '{}.wav'.format(letter)
file_path = join(sound_dir, 'letters', file_name)
pg.mixer.music.load(file_path)
pg.mixer.music.play()

def _wait_loop(self):
def _wait_loop(self, capture=True):
last_time = time()
while (time() - last_time) < self.wait_time:
self._update_table()
self._update_eye_preview()
self._update_eye_preview(capture)
self._redraw_screen()
self._event_loop()

Expand All @@ -78,10 +99,11 @@ def _update_table(self):
if self.col_num == -1 or col_num == self.col_num:
item.active = True

def _update_eye_preview(self):
def _update_eye_preview(self, capture):
result = self.tracker.give_me_all(pupilrect=True)
self.sum_pupil_y += self.tracker.settings[st.PUPIL_POSITION][1]
self.num_frames += 1
if capture:
self.sum_pupil_y += self.tracker.settings[st.PUPIL_POSITION][1]
self.num_frames += 1
self.eye_preview.update(
snapshot=result[0],
pupil_pos=self.tracker.settings[st.PUPIL_POSITION],
Expand All @@ -100,13 +122,15 @@ def _event_loop(self):
if event.type == pg.KEYDOWN:
if pg.key.name(event.key) == 'return':
self.press_enter = True
print 'ENTER'
if pg.key.name(event.key) == 'escape':
self.done = True

def _move_eyes_upwards(self):
avg_pupil_y = self.sum_pupil_y / self.num_frames
self.sum_pupil_y = 0.0
self.num_frames = 0
print avg_pupil_y, self.eye_threshold
return avg_pupil_y <= self.eye_threshold

def _move_table_forward(self):
Expand All @@ -117,7 +141,6 @@ def _move_table_forward(self):
if self.col_num == self.table.num_cols:
self.row_num = 0
self.col_num = -1
print self.row_num, self.col_num

def _execute_choice(self):
if self.col_num == -1:
Expand Down
Binary file added resources/sounds/espaco.mp3
Binary file not shown.
Binary file added resources/sounds/ler.mp3
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added resources/sounds/letters/a.mp3
Binary file not shown.
Binary file added resources/sounds/letters/b.mp3
Binary file not shown.
Binary file added resources/sounds/letters/c.mp3
Binary file not shown.
Binary file added resources/sounds/letters/d.mp3
Binary file not shown.
Binary file added resources/sounds/letters/e.mp3
Binary file not shown.
Binary file added resources/sounds/letters/f.mp3
Binary file not shown.
Binary file added resources/sounds/letters/g.mp3
Binary file not shown.
Binary file added resources/sounds/letters/h.mp3
Binary file not shown.
Binary file added resources/sounds/letters/i.mp3
Binary file not shown.
Binary file added resources/sounds/letters/j.mp3
Binary file not shown.
Binary file added resources/sounds/letters/k.mp3
Binary file not shown.
Binary file added resources/sounds/letters/l.mp3
Binary file not shown.
Binary file added resources/sounds/letters/m.mp3
Binary file not shown.
Binary file added resources/sounds/letters/n.mp3
Binary file not shown.
Binary file added resources/sounds/letters/o.mp3
Binary file not shown.
Binary file added resources/sounds/letters/p.mp3
Binary file not shown.
Binary file added resources/sounds/letters/q.mp3
Binary file not shown.
Binary file added resources/sounds/letters/r.mp3
Binary file not shown.
Binary file added resources/sounds/letters/s.mp3
Binary file not shown.
Binary file added resources/sounds/letters/t.mp3
Binary file not shown.
Binary file added resources/sounds/letters/u.mp3
Binary file not shown.
Binary file added resources/sounds/letters/v.mp3
Binary file not shown.
Binary file added resources/sounds/letters/w.mp3
Binary file not shown.
Binary file added resources/sounds/letters/x.mp3
Binary file not shown.
Binary file added resources/sounds/letters/y.mp3
Binary file not shown.
Binary file added resources/sounds/letters/z.mp3
Binary file not shown.
Binary file added resources/sounds/limpar.mp3
Binary file not shown.
Binary file added resources/sounds/sair.mp3
Binary file not shown.
Binary file added resources/sounds/som.mp3
Binary file not shown.

0 comments on commit 413a026

Please sign in to comment.