-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSMITEDummyMode.m
201 lines (172 loc) · 7.53 KB
/
SMITEDummyMode.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
% SMITE is a toolbox providing convenient access to eye tracking
% functionality using SMI eye trackers
%
% SMITE can be found at https://github.com/dcnieho/SMITE. When using SMITE,
% please cite the following paper:
% Niehorster, D.C., & Nyström, M., (2019). SMITE: A toolbox for creating
% Psychtoolbox and Psychopy experiments with SMI eye trackers.
% doi: 10.3758/s13428-019-01226-0.
classdef SMITEDummyMode < SMITE
properties
isBuffering = false;
end
methods
function obj = SMITEDummyMode(SMITEInstance)
qPassedSuperClass = false;
if ischar(SMITEInstance)
% direct construction, thats fine
name = SMITEInstance;
elseif isa(SMITEInstance,'SMITE')
qPassedSuperClass = true;
name = SMITEInstance.settings.tracker;
end
% construct default base class, below we overwrite some
% settings, if a super class was passed in
obj = obj@SMITE(name);
if qPassedSuperClass
% passed the superclass. "cast" into subclass by copying
% over all properties. This is what TMW recommends when you
% want to downcast...
C = metaclass(SMITEInstance);
P = C.Properties;
for k = 1:length(P)
if ~P{k}.Dependent && ~strcmp(P{k}.SetAccess,'private')
obj.(P{k}.Name) = SMITEInstance.(P{k}.Name);
end
end
end
% check we overwrite all public methods (for developer, to make
% sure we override all accessible baseclass calls with no-ops)
if 0
thisInfo = metaclass(obj);
superMethods = thisInfo.SuperclassList.MethodList;
superMethods(~strcmp({superMethods.Access},'public') | (~~[superMethods.Static])) = [];
thisMethods = thisInfo.MethodList;
% delete, getOptions and setOptions still work in dummy mode
thisMethods(~strcmp({thisMethods.Access},'public') | (~~[thisMethods.Static]) | ismember({thisMethods.Name},{'SMITEDummyMode','delete','getOptions','setOptions'})) = [];
% now check for problems:
% 1. any methods we define here that are not in superclass?
notInSuper = ~ismember({thisMethods.Name},{superMethods.Name});
if any(notInSuper)
fprintf('methods that are in %s but not in %s:\n',thisInfo.Name,thisInfo.SuperclassList.Name);
fprintf(' %s\n',thisMethods(notInSuper).Name);
end
% 2. methods from superclas that are not overridden.
qNotOverridden = arrayfun(@(x) strcmp(x.DefiningClass.Name,thisInfo.SuperclassList.Name), thisMethods);
if any(qNotOverridden)
fprintf('methods from %s not overridden in %s:\n',thisInfo.SuperclassList.Name,thisInfo.Name);
fprintf(' %s\n',thisMethods(qNotOverridden).Name);
end
% 3. right number of input arguments? (NB: this code only
% makes sense if there are no overloads with a different
% number of inputs)
qMatchingInput = false(size(qNotOverridden));
for p=1:length(thisMethods)
superMethod = superMethods(strcmp({superMethods.Name},thisMethods(p).Name));
if isscalar(superMethod)
qMatchingInput(p) = length(superMethod.InputNames) == length(thisMethods(p).InputNames);
else
qMatchingInput(p) = true;
end
end
if any(~qMatchingInput)
fprintf('methods in %s with wrong number of input arguments (mismatching %s):\n',thisInfo.Name,thisInfo.SuperclassList.Name);
fprintf(' %s\n',thisMethods(~qMatchingInput).Name);
end
% 4. right number of output arguments?
qMatchingOutput = false(size(qNotOverridden));
for p=1:length(thisMethods)
superMethod = superMethods(strcmp({superMethods.Name},thisMethods(p).Name));
if isscalar(superMethod)
qMatchingOutput(p) = length(superMethod.OutputNames) == length(thisMethods(p).OutputNames);
else
qMatchingOutput(p) = true;
end
end
if any(~qMatchingOutput)
fprintf('methods in %s with wrong number of output arguments (mismatching %s):\n',thisInfo.Name,thisInfo.SuperclassList.Name);
fprintf(' %s\n',thisMethods(~qMatchingOutput).Name);
end
end
end
function out = setDummyMode(obj)
% we're already in dummy mode, just pass out the same instance
out = obj;
end
function out = init(obj)
out = [];
% mark as inited
obj.isInitialized = true;
end
function out = calibrate(~,~,~)
out = [];
end
function startRecording(obj,~)
% so we only get data when 'recording'
obj.isRecording = true;
end
function startBuffer(obj,~)
% so we only get data when 'buffering'
obj.isBuffering = true;
end
function data = consumeBufferData(obj,varargin)
% at least returns one sample all the time...
if obj.isBuffering
data = obj.getMouseSample();
else
data = [];
end
end
function data = peekBufferData(obj,varargin)
% at least returns one sample all the time...
if obj.isBuffering
data = obj.getMouseSample();
else
data = [];
end
end
function sample = getLatestSample(obj)
if obj.isRecording
sample = obj.getMouseSample();
else
sample = [];
end
end
function stopBuffer(obj,~)
obj.isBuffering = false;
end
function stopRecording(obj)
obj.isRecording = false;
end
function out = isConnected(~)
out = true;
end
function sendMessage(~,~)
end
function setBegazeTrialImage(~,~)
end
function setBegazeKeyPress(~,~)
end
function setBegazeMouseClick(~,~,~,~)
end
function startEyeImageRecording(~,~,~,~)
end
function stopEyeImageRecording(~)
end
function saveData(~,~,~,~,~)
end
function out = deInit(~,~)
out = [];
% mark as deinited
obj.isInitialized = false;
end
end
methods (Access = private, Hidden)
function sample = getMouseSample(~)
[mx, my] = GetMouse();
% put into fake SampleStruct
edat = struct('gazeX',mx,'gazeY',my,'diam',0,'eyePositionX',0,'eyePositionY',0,'eyePositionZ',0);
sample = struct('timestamp',round(GetSecs*1000*1000),'leftEye',edat,'rightEye',edat);
end
end
end