-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrackStatus.m
More file actions
145 lines (112 loc) · 4.92 KB
/
TrackStatus.m
File metadata and controls
145 lines (112 loc) · 4.92 KB
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
144
145
function TrackStatus(Calib)
%TrackStatus script. Will show one dot per eye when the user positions himself in front of the eye tracker.
%Use spacebar (or any other) key press to continue.
% Input:
% Calib: The calib config structure (see SetCalibParams)
%global CENTER
global KEYBOARD SPACEKEY EXPWIN BLACK
Screen('FillRect',EXPWIN,Calib.bkcolor*255);
if Calib.resize
figloc(1) = round(Calib.screen.x + Calib.screen.width/4);
figloc(2) = round(Calib.screen.y + Calib.screen.height/4);
figloc(3) = round(Calib.screen.width - Calib.screen.width/4);
figloc(4) = round(Calib.screen.height - Calib.screen.height/4);
figlocWidth = figloc(3) - figloc (1);
figlocHeight = figloc(4) - figloc (2);
else
figloc(1) = Calib.screen.x;
figloc(2) = Calib.screen.y;
figloc(3) = Calib.screen.width;
figloc(4) = Calib.screen.height;
end
Screen('FillRect',EXPWIN,[0 0 100], figloc);
Screen(EXPWIN, 'Flip');
updateFrequencyInHz = 60;
tetio_startTracking;
pause(1)
while 1
pause(1/updateFrequencyInHz);
[lefteye, righteye, ~, ~] = tetio_readGazeData;
if (isempty(lefteye) || isempty(righteye) )
Screen('FillRect',EXPWIN,[0 0 100], figloc);
DrawFormattedText(EXPWIN, 'Eyes not detected. Reposition Participant',...
'Center', Calib.screen.height*.2,BLACK);
Screen(EXPWIN, 'Flip');
continue;
end
GazeData = ParseGazeData(lefteye(end,:), righteye(end,:)); % Parse last gaze data.
%Calculate participant's distance to ET
if lefteye((end),3) > 0 && righteye((end),3) > 0
ET_Distance = round(((lefteye((end),3) + righteye((end),3))/2)/10);
elseif lefteye((end),3) == 0 && righteye((end),3) > 0
ET_Distance = round(righteye((end),3)/10);
elseif lefteye((end),3) > 0 && righteye((end),3) == 0
ET_Distance = round(lefteye((end),3)/10);
else
ET_Distance = [];
end
%draw eyes
%decide color for indication of validity
% These color scheme & code is taken from the Talk2Tobii software
% http://www.cbcd.bbk.ac.uk/people/affiliated/fani/talk2tobii
% developed by Fani Deligianni
switch GazeData.left_validity
case 0,
Left_eyeDotColor = [0 255 0];
case 1,
Left_eyeDotColor = [64 192 0];
case 2,
Left_eyeDotColor = [128 128 0];
case 3,
Left_eyeDotColor = [192 64 0];
otherwise,
Left_eyeDotColor = [255 0 0];
end
switch GazeData.right_validity
case 0,
Right_eyeDotColor = [0 255 0];
case 1,
Right_eyeDotColor = [64 192 0];
case 2,
Right_eyeDotColor = [128 128 0];
case 3,
Right_eyeDotColor = [192 64 0];
otherwise,
Right_eyeDotColor = [255 0 0];
end
%[GazeData.left_validity GazeData.right_validity]
validLeftEyePos = GazeData.left_validity <= 2;
validRightEyePos = GazeData.right_validity < 2; % If both left and right validities are 2 then only draw left.
Screen('FillRect',EXPWIN,[0 0 100], figloc)
if ~isempty(ET_Distance)
DrawFormattedText(EXPWIN, ['Tracker Distance: ' int2str(ET_Distance) 'cm'],...
'Center', Calib.screen.height*.2,BLACK);
end
DrawFormattedText(EXPWIN,...
'Make sure eyes are visibile and stable green. Press space to start calibration',...
'Center',Calib.screen.height*.8, BLACK);
if validLeftEyePos || validRightEyePos
if validLeftEyePos
sLeft(1) = (1-GazeData.left_eye_position_3d_relative.x) * figlocWidth + figlocWidth/2- 15 ;
sLeft(2) = GazeData.left_eye_position_3d_relative.y * figlocHeight + figlocHeight/2 - 15 ;
sLeft(3) = (1-GazeData.left_eye_position_3d_relative.x) * figlocWidth + figlocWidth/2 + 15 ;
sLeft(4) = GazeData.left_eye_position_3d_relative.y * figlocHeight + figlocHeight/2 + 15;
Screen('FillOval',EXPWIN,Right_eyeDotColor, sLeft);
end
if validRightEyePos
sRight(1) = (1-GazeData.right_eye_position_3d_relative.x) * figlocWidth + figlocWidth/2 - 15 ;
sRight(2) = GazeData.right_eye_position_3d_relative.y * figlocHeight + figlocHeight/2 - 15 ;
sRight(3) = (1-GazeData.right_eye_position_3d_relative.x) * figlocWidth + figlocWidth/2 + 15 ;
sRight(4) = GazeData.right_eye_position_3d_relative.y * figlocHeight + figlocHeight/2 + 15;
Screen('FillOval',EXPWIN,Left_eyeDotColor, sRight);
end
%Screen('DrawingFinished',EXPWIN);
Screen(EXPWIN, 'Flip');
end
[~,~,keyCode]=PsychHID('KbCheck', KEYBOARD);
if keyCode(SPACEKEY)
break;
end
end
tetio_stopTracking;
end