Skip to content

Commit fd85a61

Browse files
committed
move connection checks in a subfunction
1 parent ce0b4a8 commit fd85a61

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/eyeTracker.m

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,9 @@
5353
EyelinkUpdateDefaults(el);
5454

5555
% Initialize EL and make sure it worked: returns 0 if OK, -1 if error.
56-
% Exit program if this fails.
57-
elInit = Eyelink('Initialize');
58-
if ELinit ~= 0
59-
fprintf('Eyelink is not initialized, aborted.\n');
60-
Eyelink('Shutdown');
61-
CleanUp();
62-
return
63-
end
6456

65-
% Make sure EL is still connected: returns 1 if connected, -1 if dummy-connected,
66-
% 2 if broadcast-connected and 0 if not connected. Exit program if this fails.
67-
elConnection = Eyelink('IsConnected');
68-
if ELconnection ~= 1
69-
fprintf('Eyelink is not connected, aborted.\n');
70-
Eyelink('Shutdown');
71-
CleanUp();
72-
return
73-
end
74-
75-
% Last check that the EL is up to work and exit program if this fails.
76-
if ~EyelinkInit(0, 1)
77-
fprintf('Eyelink Init aborted.\n');
78-
CleanUp();
79-
return
80-
end
57+
% Check that EL is initialzed and connected, otherwise abort experiment
58+
eyetrackerCheckConnection
8159

8260
% Open the edf file to write the data.
8361
edfFile = 'demo.edf';
@@ -139,7 +117,7 @@
139117
end
140118

141119
% Set EDF file contents (not clear what this lines are used for).
142-
el.vsn = regexp(el.vs, '\d', 'match'); % wont work on EL
120+
el.vsn = regexp(el.vs, '\d', 'match'); % won't work on EL
143121

144122
% Enter Eyetracker camera setup mode, calibration and validation.
145123
EyelinkDoTrackerSetup(el);
@@ -239,6 +217,25 @@
239217

240218
end
241219

220+
function eyetrackerCheckConnection
221+
222+
% Initialize EL and make sure it worked: returns 0 if OK, -1 if error.
223+
% Exit program if this fails.
224+
elInit = Eyelink('Initialize');
225+
if ELinit ~= 0
226+
error('Eyelink is not initialized, aborted.\n');
227+
end
228+
229+
% Make sure EL is still connected: returns 1 if connected, -1 if dummy-connected,
230+
% 2 if broadcast-connected and 0 if not connected. Exit program if this fails.
231+
elConnection = Eyelink('IsConnected');
232+
if ELconnection ~= 1
233+
error('Eyelink is not connected, aborted.\n');
234+
end
235+
236+
end
237+
238+
242239
%% subfunctions for iView
243240

244241
% function ivx = eyeTrackInit(cfg)

0 commit comments

Comments
 (0)