-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheyeTrackingAdmin.m
109 lines (104 loc) · 4.4 KB
/
eyeTrackingAdmin.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
function [ obj ] = eyeTrackingAdmin( mode, obj )
%EYETRACKINGADMIN This function is the main hub for any eyetracking setup,
%administration or tear down. A typical usage might look something like the
%following:
%eyetracker = eyeTrackingAdmin('start');
%eyetracker = eyeTrackingAdmin('calibrate',eyetracker);
%Have subject do something
%While subject is doing something:
%setState(eyetracker, 'ENABLE_SEND_DATA', '1');
%setState(eyetracker, 'ENABLE_SEND_POG_FIX', '1');
%After they finish:
%setState(eyetracker, 'ENABLE_SEND_POG_FIX', '0');
%setState(eyetracker, 'ENABLE_SEND_DATA', '0');
%gp = {};counter = 0;
%while (get(eyetracker.client_socket, 'BytesAvailable') > 0)
% counter = counter+1;
% gp{counter} = fscanf(eyetracker.client_socket);
%end
%Alternatively, If you have psychtoolbox installed, use KBWaitEyetrack to
%collect eyetracking data while waiting for subject response.
if strcmp(mode,'start')
%This creates a session with the eye tracker, using the default settings
obj = [];
obj.ip_address='127.0.0.1';
obj.port_number = 4242;
try
obj.client_socket = tcpip(obj.ip_address, obj.port_number);
set(obj.client_socket, 'InputBufferSize', 4096);
fopen(obj.client_socket);
obj.client_socket.Terminator = 'CR/LF';
gazepoint_info = strcat('Connected to:', obj.ip_address, ' on port:', num2str(obj.port_number), '\n');
fprintf(gazepoint_info);
catch err
fprintf('Make sure GazepointControl is open on host machine.');
rethrow(err);
end
elseif strcmp(mode,'calibrate')
%This performs the 9-point calibration, edit the points if you want
%a shorter or longer pattern.
setState(obj, 'CALIBRATE_CLEAR'); %remove old calibration pattern
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.1', '.1');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.5', '.1');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.9', '.1');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.9', '.5');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.5', '.5');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.1', '.5');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.1', '.9');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.5', '.9');
setState(obj, 'CALIBRATE_ADDPOINT', '1', '.9', '.9');
setState(obj, 'CALIBRATE_SHOW','1');
setState(obj, 'CALIBRATE_START','1');
pause(20); %make sure you edit this if you alter the number of points
setState(obj, 'CALIBRATE_SHOW','0');
setState(obj, 'CALIBRATE_SHOW','0');
setState(obj, 'CALIBRATE_START','0')
fprintf(obj.client_socket, '<GET ID="CALIBRATE_RESULT_SUMMARY" />');
setState(obj, 'ENABLE_SEND_DATA','0')
disp('done with calibration')
while (get(obj.client_socket, 'BytesAvailable') > 0)
results = fscanf(obj.client_socket);
%fprintf(results);
pause(.01);
end
pause(1);
fprintf(obj.client_socket, '<SET ID="ENABLE_SEND_DATA" STATE="1" />');
elseif strcmp(mode,'end')
%call this when you are done to close TCPIP socket to camera
fprintf('Shutting down connection')
fprintf(obj.client_socket, '<SET ID="ENABLE_SEND_DATA" STATE="0" />');
fclose(obj.client_socket);
delete(obj.client_socket);
clear obj.client_socket
elseif strcmp(mode, 'test')
%%check for packet loss, run this when testing new camera/computer
%%setup
fprintf('Testing initiated. First, checking for packet loss.\n')
fprintf(obj.client_socket, '<SET ID="ENABLE_SEND_COUNTER" STATE="1" />');
fprintf(obj.client_socket, '<SET ID="ENABLE_SEND_DATA" STATE="1" />');
counter = 1;
all_results = zeros(200,1);
while (get(obj.client_socket, 'BytesAvailable') > 0) && counter < 201
results = fscanf(obj.client_socket);
if strcmp(results, '<REC />')
pause(.01);
else
pause(.01);
results = strsplit(results, '"');
if size(results,2)>3
else
all_results(counter) = str2num(results{2});
counter = counter+1;
end
if mod(counter,20)==0
fprintf('%.f percent finished with packet test\n',round(counter/2))
end
end
end
fprintf(obj.client_socket, '<SET ID="ENABLE_SEND_COUNTER" STATE="0" />');
fprintf(obj.client_socket, '<SET ID="ENABLE_SEND_DATA" STATE="0" />');
results = safeRead(obj);
n_loss = sum(diff(results)==1);
fprintf('Out of 200 packets, %.f lost\n', [n_loss])
end
end