-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHandleCalibWorkflow.m
140 lines (111 loc) · 4.94 KB
/
HandleCalibWorkflow.m
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
function [pts,TrackError,calibplot] = HandleCalibWorkflow(Calib,Constants)
%HandleCalibWorkflow Main function for handling the calibration workflow.
% Input:
% Calib: The calib config structure (see SetCalibParams)
% Output:
% pts: The list of points used for calibration. These could be
% further used for the analysis such as the variance, mean etc.
global EXPWIN GREY
TrackError=[];
calLoop=1;
while(1)
disp('1')
try
mOrder = randperm(Calib.points.n);
disp('2')
calibplot = Calibrate_infant(Calib,mOrder, 0, [],Constants);
disp('3')
% Show calibration points and compute calibration.
%do the same but with psychtoolbox and more info + user interaction
[pts, TrackError] = PlotCalibrationPoints_Psychtoolbox(calibplot, mOrder, Calib);
while(calLoop)
clear keyIsDown keyCode
while KbCheck; end %wait for release
FlushEvents; go=1;
while go %accept calibration prompt?
[~,~,keyCode,~] = KbCheck;
if(find(keyCode)== 13 | find(keyCode)== 89 )
disp('Stopping Calibration')
return
elseif(find(keyCode)== 78)
go=0;
disp('Recalibrating')
end
end
Screen('FillRect',EXPWIN,GREY);
DrawFormattedText(EXPWIN,'Recalibrate all points (a) or some points (b)? Type a or b and return','Center',Calib.screen.height/2, [0 0 0]);
Screen(EXPWIN,'Flip');
clear keyIsDown keyCode
while KbCheck; end %wait for release
FlushEvents; go=1;
while go %accept calibration prompt?
[~,~,keyCode,~] = KbCheck;
if(find(keyCode)== 65 )
go=0; allpts=1;
elseif(find(keyCode)== 66)
go=0; allpts=0;
end
end
if allpts
close all;
break;
else
Screen('FillRect',EXPWIN,GREY);
DrawFormattedText(EXPWIN,'Please enter (space separated) the points you wish to recalibrate, eg. 1 3, Followed by return:','Center',Calib.screen.height/2, [0 0 0]);
Screen(EXPWIN,'Flip');
h = input('Please enter (space separated) the point numbers that you wish to recalibrate e.g. 1 3, Followed by return: ', 's');
recalibpts = str2num(h);
[calibplot, calibError] = Calibrate(Calib,mOrder, 1, recalibpts);
if(calibError)
Screen('FillRect',EXPWIN,GREY);
Screen('TextSize',EXPWIN , 15);
DrawFormattedText(EXPWIN,'Failed to compute calibration. Starting full calibration','Center',Calib.screen.height/2, [0 0 0]);
Screen(EXPWIN,'Flip');
WaitSecs(3);
break;
end
[pts, TrackError] = PlotCalibrationPoints_Psychtoolbox(calibplot, mOrder, Calib);% Show calibration points and compute calibration.
clear keyIsDown keyCode
while KbCheck; end %wait for release
FlushEvents; go=1;
while go %accept calibration prompt?
[~,~,keyCode,~] = KbCheck;
if(find(keyCode)== 13 | find(keyCode)== 89 )
disp('Stopping Calibration')
return
elseif(find(keyCode)== 78)
go=0;
disp('Recalibrating')
allpts=1;
end
end
end
end
catch ME % Calibration failed
Screen('FillRect',EXPWIN,GREY);
Screen('TextSize',EXPWIN , 15);
DrawFormattedText(EXPWIN,'Not enough calibration data. Do you want to try again([y]/n), Else continue to Experiment','Center',Calib.screen.height/2, [0 0 0]);
Screen(EXPWIN,'Flip');
ME
clear keyIsDown keyCode
while KbCheck; end %wait for release
FlushEvents; go=1;
while go %accept calibration prompt?
[~,~,keyCode,~] = KbCheck;
if(find(keyCode)== 89 | find(keyCode)== 13)
go=0; not_enough_calData=1;
elseif(find(keyCode)== 78)
go=0; not_enough_calData=0;
end
end
pts=[];
if not_enough_calData %recalibrate
try
tetio_stopCalib
end
continue;
else
return; %quit calib
end
end
end