-
Notifications
You must be signed in to change notification settings - Fork 15
/
Titta.m
8584 lines (8120 loc) · 497 KB
/
Titta.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Titta is a toolbox providing convenient access to eye tracking
% functionality using Tobii eye trackers
%
% Titta can be found at https://github.com/dcnieho/Titta. Check there
% for the latest version.
% When using Titta, please cite the following paper:
%
% Niehorster, D.C., Andersson, R. & Nystrom, M., (2020). Titta: A
% toolbox for creating Psychtoolbox and Psychopy experiments with Tobii
% eye trackers. Behavior Research Methods.
% doi: https://doi.org/10.3758/s13428-020-01358-8
%
% For detailed documentation, refer to <a href="https://github.com/dcnieho/Titta/blob/master/readme.md">the readme on GitHub</a>.
%
% For help on the constructor method, type:
% <a href="matlab: help Titta.Titta">help Titta.Titta</a>
%
% For static methods:
% <a href="matlab: help Titta.getDefaults">help Titta.getDefaults</a>
% <a href="matlab: help Titta.getFileName">help Titta.getFileName</a>
% <a href="matlab: help Titta.getTimeAsSystemTime">help Titta.getTimeAsSystemTime</a>
% <a href="matlab: help Titta.getValidationQualityMessage">help Titta.getValidationQualityMessage</a>
% <a href="matlab: help Titta.saveData">help Titta.saveData</a>
% <a href="matlab: help Titta.saveDataToParquet">help Titta.saveDataToParquet</a>
% <a href="matlab: help Titta.saveGazeDataToTSV">help Titta.saveGazeDataToTSV</a>
%
% For methods:
% <a href="matlab: help Titta.setDummyMode">help Titta.setDummyMode</a>
% <a href="matlab: help Titta.getOptions">help Titta.getOptions</a>
% <a href="matlab: help Titta.setOptions">help Titta.setOptions</a>
% <a href="matlab: help Titta.init">help Titta.init</a>
% <a href="matlab: help Titta.calibrate">help Titta.calibrate</a>
% <a href="matlab: help Titta.calibrateAdvanced">help Titta.calibrateAdvanced</a>
% <a href="matlab: help Titta.sendMessage">help Titta.sendMessage</a>
% <a href="matlab: help Titta.getMessages">help Titta.getMessages</a>
% <a href="matlab: help Titta.collectSessionData">help Titta.collectSessionData</a>
% <a href="matlab: help Titta.deInit">help Titta.deInit</a>
%
% For properties:
% <a href="matlab: help Titta.geom">help Titta.geom</a>
% <a href="matlab: help Titta.calibrateHistory">help Titta.calibrateHistory</a>
% <a href="matlab: help Titta.buffer">help Titta.buffer</a>
% <a href="matlab: help Titta.deviceName">help Titta.deviceName</a>
% <a href="matlab: help Titta.serialNumber">help Titta.serialNumber</a>
% <a href="matlab: help Titta.model">help Titta.model</a>
% <a href="matlab: help Titta.firmwareVersion">help Titta.firmwareVersion</a>
% <a href="matlab: help Titta.runtimeVersion">help Titta.runtimeVersion</a>
% <a href="matlab: help Titta.address">help Titta.address</a>
% <a href="matlab: help Titta.capabilities">help Titta.capabilities</a>
% <a href="matlab: help Titta.frequency">help Titta.frequency</a>
% <a href="matlab: help Titta.trackingMode">help Titta.trackingMode</a>
% <a href="matlab: help Titta.supportedFrequencies">help Titta.supportedFrequencies</a>
% <a href="matlab: help Titta.supportedModes">help Titta.supportedModes</a>
% <a href="matlab: help Titta.systemInfo">help Titta.systemInfo</a>
classdef Titta < handle
properties (Access = protected, Hidden = true)
% message buffer
msgs;
% state
isInitialized = false;
usingFTGLTextRenderer;
keyState;
mouseState;
qFloatColorRange;
calibrateLeftEye = true;
calibrateRightEye = true;
wpnts;
eyeImageCanvasSize = [];
% settings and external info
settings;
scrInfo;
end
properties (SetAccess=protected)
% Information about eye tracking setup's geometry
%
% Titta.geom is a struct with information about the setup
% geometry known to the eye tracker, such as screen width and
% height, and the screen's location in the eye tracker's user
% coordinate system. Filled when Titta.init() is called.
geom;
% Information about all performed calibration attempts
%
% Titta.calibrateHistory is a cell array with information about
% all calibration attempts during the current session.
calibrateHistory;
% Handle to TittaMex instance for interaction with eye tracker
%
% Titta.buffer is a handle to TittaMex instance for interaction
% with the eye tracker's data streams, or for directly
% interacting with the eye tracker through the Tobii Pro SDK.
% Note that this is at your own risk. Titta should have minimal
% assumptions about eye-tracker state, but I cannot guarantee
% that direct interaction with the eye tracker does not
% interfere with later use of Titta in the same session.
% Initialized when Titta.init() is called.
buffer;
end
properties (Dependent, SetAccess=private)
% Get connected eye tracker's device name
deviceName
% Get connected eye tracker's serial number
serialNumber
% Get connected eye tracker's model name
model
% Get connected eye tracker's firmware version
firmwareVersion
% Get connected eye tracker's runtime version
runtimeVersion
% Get connected eye tracker's address
address
% Get connected eye tracker's exposed capabilities
capabilities
% Get connected eye tracker's supported sampling frequencies
supportedFrequencies
% Get connected eye tracker's supported tracking modes
supportedModes
% Get information about connected eye tracker
%
% Titta.systemInfo is a struct that contains information about
% the device name, serial number, model name, firmware version,
% runtime version, address, sampling frequency, tracking mode,
% capabilities, supported sampling frequencies, and supported
% tracking modes of the connected eye tracker.
systemInfo
end
properties (Dependent)
% Get or set connected eye tracker's sampling frequency
frequency
% Get or set connected eye tracker's tracking mode
trackingMode
end
methods
function obj = Titta(settingsOrETName)
% Construct Titta instance
%
% EThndl = Titta(TRACKERMODEL) constructs a Titta instance
% with the default settings for the given TRACKERMODEL eye
% tracker.
%
% EThndl = Titta(SETTINGS) constructs a Titta instance
% with the settings specified in SETTINGS.
% deal with inputs
if ischar(settingsOrETName)
% only eye-tracker name provided, load defaults for this
% tracker
obj.setOptions(obj.getDefaults(settingsOrETName));
else
obj.setOptions(settingsOrETName);
end
obj.msgs = simpleVec(cell(1,2),1024); % (re)initialize with space for 1024 messages
end
function delete(obj)
obj.deInit();
end
function out = setDummyMode(obj)
% Enable dummy mode
%
% Turn the current Titta instance into a dummy mode class.
% EThndl = Titta.setDummyMode() returns a handle to a
% TittaDummyMode instance.
assert(nargout==1,'Titta: you must use the output argument of setDummyMode, like: TobiiHandle = TobiiHandle.setDummyMode(), or TobiiHandle = setDummyMode(TobiiHandle)')
out = TittaDummyMode(obj);
end
function out = getOptions(obj)
% Get active settings
%
% SETTINGS = Titta.getOptions() returns the currently active
% settings. Only those settings that can be changed in the
% current state are returned (which is a subset of all
% settings once Titta.init() has been called)
%
% See also TITTA.SETOPTIONS
out = obj.settings;
if ~obj.isInitialized
% no-op, return all settings
else
% return only the subset that can be changed "live"
remOpts = obj.getDisAllowedOptions();
for p=1:numel(remOpts)
out = rmfield(out,remOpts{p});
end
end
end
function setOptions(obj,settings)
% Change active settings
%
% Titta.setOptions(SETTINGS) changes the active settings to
% those specified in SETTINGS. First use getOptions() to get
% an up-to-date settings struct, then edit the wanted
% settings and use this function to apply themm.
%
% See also TITTA.GETOPTIONS
% special handling of changes to frequency and tracking mode:
% setting them on the Titta object has them changed on the eye
% tracker
if isfield(settings,'freq') && isfield(obj.settings,'freq') && settings.freq ~= obj.settings.freq
obj.frequency = settings.freq;
end
if isfield(settings,'trackingMode') && isfield(obj.settings,'trackingMode') && ~strcmp(settings.trackingMode,obj.settings.trackingMode)
obj.trackingMode = settings.trackingMode;
end
% handle other settings
if obj.isInitialized
% only a subset of settings is allowed. Overwrite those
% that are not allowed to be changed so that we are certain
% they do exist in the input and have not been tampered
% with
cantTouch = obj.getDisAllowedOptions();
for p=1:numel(cantTouch)
settings.(cantTouch{p}) = obj.settings.(cantTouch{p});
end
obj.settings = settings;
else
defaults = obj.getDefaults(settings.tracker);
expected = getStructFieldsString(defaults);
input = getStructFieldsString(settings);
qMissing = ~ismember(expected,input);
qAdded = ~ismember(input,expected);
if any(qMissing)
params = sprintf('\n settings.%s',expected{qMissing});
error('Titta: For the %s tracker, the following settings are expected, but were not provided by you:%s\nAdd these to your settings input.',settings.tracker,params);
end
if any(qAdded)
params = sprintf('\n settings.%s',input{qAdded});
error('Titta: For the %s tracker, the following settings are not expected, but were provided by you:%s\nRemove these from your settings input.',settings.tracker,params);
end
obj.settings = settings;
end
% check requested eye calibration mode
obj.changeAndCheckCalibEyeMode();
% calibration point setup
assert(isempty(settings.cal.pointPosTrackerSpace ) || isequal(size(settings.cal.pointPosTrackerSpace ),size(settings.cal.pointPos)) ,'settings.cal.pointPosTrackerSpace should either be empty or the same size as settings.cal.pointPos')
if ~isempty(settings.cal.pointPosTrackerSpace)
assert(~isequal(obj.settings.cal.pointPosTrackerSpace,obj.settings.cal.pointPos),'if settings.cal.pointPosTrackerSpace is set, it should not contain the same values as settings.cal.pointPos')
assert(~isempty(settings.val.pointPosTrackerSpace),'If the position of calibration points is specified using settings.cal.pointPosTrackerSpace, the position of validation points in tracker space should also be specified using settings.val.pointPosTrackerSpace')
assert(~isequal(obj.settings.val.pointPosTrackerSpace,obj.settings.val.pointPos),'if settings.val.pointPosTrackerSpace is set, it should not contain the same values as settings.val.pointPos')
else
assert( isempty(settings.val.pointPosTrackerSpace),'settings.val.pointPosTrackerSpace should not be specified if settings.cal.pointPosTrackerSpace is empty')
end
% setup colors
obj.settings.UI.val.eyeColors = color2RGBA(obj.settings.UI.val.eyeColors);
obj.settings.UI.val.onlineGaze.eyeColors = color2RGBA(obj.settings.UI.val.onlineGaze.eyeColors);
obj.settings.UI.val.avg.text.eyeColors = color2RGBA(obj.settings.UI.val.avg.text.eyeColors);
obj.settings.UI.val.hover.text.eyeColors = color2RGBA(obj.settings.UI.val.hover.text.eyeColors);
obj.settings.UI.val.menu.text.eyeColors = color2RGBA(obj.settings.UI.val.menu.text.eyeColors);
obj.settings.UI.setup.bgColor = color2RGBA(obj.settings.UI.setup.bgColor);
obj.settings.UI.setup.refCircleClr = color2RGBA(obj.settings.UI.setup.refCircleClr);
obj.settings.UI.setup.headCircleEdgeClr = color2RGBA(obj.settings.UI.setup.headCircleEdgeClr);
obj.settings.UI.setup.headCircleFillClr = color2RGBA(obj.settings.UI.setup.headCircleFillClr);
obj.settings.UI.setup.eyeClr = color2RGBA(obj.settings.UI.setup.eyeClr);
obj.settings.UI.setup.eyeClrPosMissing = color2RGBA(obj.settings.UI.setup.eyeClrPosMissing);
obj.settings.UI.setup.eyeBorderClr = color2RGBA(obj.settings.UI.setup.eyeBorderClr);
obj.settings.UI.setup.eyeLidClr = color2RGBA(obj.settings.UI.setup.eyeLidClr);
obj.settings.UI.setup.pupilClr = color2RGBA(obj.settings.UI.setup.pupilClr);
obj.settings.UI.setup.crossClr = color2RGBA(obj.settings.UI.setup.crossClr);
obj.settings.UI.setup.fixBackColor = color2RGBA(obj.settings.UI.setup.fixBackColor);
obj.settings.UI.setup.fixFrontColor = color2RGBA(obj.settings.UI.setup.fixFrontColor);
obj.settings.UI.setup.instruct.color = color2RGBA(obj.settings.UI.setup.instruct.color);
obj.settings.UI.setup.menu.bgColor = color2RGBA(obj.settings.UI.setup.menu.bgColor);
obj.settings.UI.setup.menu.itemColor = color2RGBA(obj.settings.UI.setup.menu.itemColor);
obj.settings.UI.setup.menu.itemColorActive = color2RGBA(obj.settings.UI.setup.menu.itemColorActive);
obj.settings.UI.setup.menu.text.color = color2RGBA(obj.settings.UI.setup.menu.text.color);
obj.settings.UI.cal.errMsg.color = color2RGBA(obj.settings.UI.cal.errMsg.color);
obj.settings.UI.val.bgColor = color2RGBA(obj.settings.UI.val.bgColor);
obj.settings.UI.val.fixBackColor = color2RGBA(obj.settings.UI.val.fixBackColor);
obj.settings.UI.val.fixFrontColor = color2RGBA(obj.settings.UI.val.fixFrontColor);
obj.settings.UI.val.onlineGaze.fixBackColor = color2RGBA(obj.settings.UI.val.onlineGaze.fixBackColor);
obj.settings.UI.val.onlineGaze.fixFrontColor= color2RGBA(obj.settings.UI.val.onlineGaze.fixFrontColor);
obj.settings.UI.val.avg.text.color = color2RGBA(obj.settings.UI.val.avg.text.color);
obj.settings.UI.val.waitMsg.color = color2RGBA(obj.settings.UI.val.waitMsg.color);
obj.settings.UI.val.hover.bgColor = color2RGBA(obj.settings.UI.val.hover.bgColor);
obj.settings.UI.val.hover.text.color = color2RGBA(obj.settings.UI.val.hover.text.color);
obj.settings.UI.val.menu.bgColor = color2RGBA(obj.settings.UI.val.menu.bgColor);
obj.settings.UI.val.menu.itemColor = color2RGBA(obj.settings.UI.val.menu.itemColor);
obj.settings.UI.val.menu.itemColorActive = color2RGBA(obj.settings.UI.val.menu.itemColorActive);
obj.settings.UI.val.menu.text.color = color2RGBA(obj.settings.UI.val.menu.text.color);
obj.settings.cal.bgColor = color2RGBA(obj.settings.cal.bgColor);
obj.settings.cal.fixBackColor = color2RGBA(obj.settings.cal.fixBackColor);
obj.settings.cal.fixFrontColor = color2RGBA(obj.settings.cal.fixFrontColor);
obj.settings.UI.button.setup.toggEyeIm.fillColor= color2RGBA(obj.settings.UI.button.setup.toggEyeIm.fillColor);
obj.settings.UI.button.setup.toggEyeIm.edgeColor= color2RGBA(obj.settings.UI.button.setup.toggEyeIm.edgeColor);
obj.settings.UI.button.setup.toggEyeIm.textColor= color2RGBA(obj.settings.UI.button.setup.toggEyeIm.textColor);
obj.settings.UI.button.setup.cal.fillColor = color2RGBA(obj.settings.UI.button.setup.cal.fillColor);
obj.settings.UI.button.setup.cal.edgeColor = color2RGBA(obj.settings.UI.button.setup.cal.edgeColor);
obj.settings.UI.button.setup.cal.textColor = color2RGBA(obj.settings.UI.button.setup.cal.textColor);
obj.settings.UI.button.setup.prevcal.fillColor = color2RGBA(obj.settings.UI.button.setup.prevcal.fillColor);
obj.settings.UI.button.setup.prevcal.edgeColor = color2RGBA(obj.settings.UI.button.setup.prevcal.edgeColor);
obj.settings.UI.button.setup.prevcal.textColor = color2RGBA(obj.settings.UI.button.setup.prevcal.textColor);
obj.settings.UI.button.setup.changeeye.fillColor= color2RGBA(obj.settings.UI.button.setup.changeeye.fillColor);
obj.settings.UI.button.setup.changeeye.edgeColor= color2RGBA(obj.settings.UI.button.setup.changeeye.edgeColor);
obj.settings.UI.button.setup.changeeye.textColor= color2RGBA(obj.settings.UI.button.setup.changeeye.textColor);
obj.settings.UI.button.val.recal.fillColor = color2RGBA(obj.settings.UI.button.val.recal.fillColor);
obj.settings.UI.button.val.recal.edgeColor = color2RGBA(obj.settings.UI.button.val.recal.edgeColor);
obj.settings.UI.button.val.recal.textColor = color2RGBA(obj.settings.UI.button.val.recal.textColor);
obj.settings.UI.button.val.reval.fillColor = color2RGBA(obj.settings.UI.button.val.reval.fillColor);
obj.settings.UI.button.val.reval.edgeColor = color2RGBA(obj.settings.UI.button.val.reval.edgeColor);
obj.settings.UI.button.val.reval.textColor = color2RGBA(obj.settings.UI.button.val.reval.textColor);
obj.settings.UI.button.val.continue.fillColor = color2RGBA(obj.settings.UI.button.val.continue.fillColor);
obj.settings.UI.button.val.continue.edgeColor = color2RGBA(obj.settings.UI.button.val.continue.edgeColor);
obj.settings.UI.button.val.continue.textColor = color2RGBA(obj.settings.UI.button.val.continue.textColor);
obj.settings.UI.button.val.selcal.fillColor = color2RGBA(obj.settings.UI.button.val.selcal.fillColor);
obj.settings.UI.button.val.selcal.edgeColor = color2RGBA(obj.settings.UI.button.val.selcal.edgeColor);
obj.settings.UI.button.val.selcal.textColor = color2RGBA(obj.settings.UI.button.val.selcal.textColor);
obj.settings.UI.button.val.setup.fillColor = color2RGBA(obj.settings.UI.button.val.setup.fillColor);
obj.settings.UI.button.val.setup.edgeColor = color2RGBA(obj.settings.UI.button.val.setup.edgeColor);
obj.settings.UI.button.val.setup.textColor = color2RGBA(obj.settings.UI.button.val.setup.textColor);
obj.settings.UI.button.val.toggGaze.fillColor = color2RGBA(obj.settings.UI.button.val.toggGaze.fillColor);
obj.settings.UI.button.val.toggGaze.edgeColor = color2RGBA(obj.settings.UI.button.val.toggGaze.edgeColor);
obj.settings.UI.button.val.toggGaze.textColor = color2RGBA(obj.settings.UI.button.val.toggGaze.textColor);
obj.settings.UI.button.val.toggCal.fillColor = color2RGBA(obj.settings.UI.button.val.toggCal.fillColor);
obj.settings.UI.button.val.toggCal.edgeColor = color2RGBA(obj.settings.UI.button.val.toggCal.edgeColor);
obj.settings.UI.button.val.toggCal.textColor = color2RGBA(obj.settings.UI.button.val.toggCal.textColor);
obj.settings.UI.button.val.toggPlot.fillColor = color2RGBA(obj.settings.UI.button.val.toggPlot.fillColor);
obj.settings.UI.button.val.toggPlot.edgeColor = color2RGBA(obj.settings.UI.button.val.toggPlot.edgeColor);
obj.settings.UI.button.val.toggPlot.textColor = color2RGBA(obj.settings.UI.button.val.toggPlot.textColor);
obj.settings.UI.operator.setup.bgColor = color2RGBA(obj.settings.UI.operator.setup.bgColor);
obj.settings.UI.operator.setup.refCircleClr = color2RGBA(obj.settings.UI.operator.setup.refCircleClr);
obj.settings.UI.operator.setup.headCircleEdgeClr = color2RGBA(obj.settings.UI.operator.setup.headCircleEdgeClr);
obj.settings.UI.operator.setup.headCircleFillClr = color2RGBA(obj.settings.UI.operator.setup.headCircleFillClr);
obj.settings.UI.operator.setup.eyeClr = color2RGBA(obj.settings.UI.operator.setup.eyeClr);
obj.settings.UI.operator.setup.eyeClrPosMissing = color2RGBA(obj.settings.UI.operator.setup.eyeClrPosMissing);
obj.settings.UI.operator.setup.eyeBorderClr = color2RGBA(obj.settings.UI.operator.setup.eyeBorderClr);
obj.settings.UI.operator.setup.eyeLidClr = color2RGBA(obj.settings.UI.operator.setup.eyeLidClr);
obj.settings.UI.operator.setup.pupilClr = color2RGBA(obj.settings.UI.operator.setup.pupilClr);
obj.settings.UI.operator.setup.crossClr = color2RGBA(obj.settings.UI.operator.setup.crossClr);
obj.settings.UI.operator.setup.instruct.color = color2RGBA(obj.settings.UI.operator.setup.instruct.color);
obj.settings.UI.operator.cal.eyeColors = color2RGBA(obj.settings.UI.operator.cal.eyeColors);
obj.settings.UI.operator.cal.bgColor = color2RGBA(obj.settings.UI.operator.cal.bgColor);
obj.settings.UI.operator.cal.fixBackColor = color2RGBA(obj.settings.UI.operator.cal.fixBackColor);
obj.settings.UI.operator.cal.fixFrontColor = color2RGBA(obj.settings.UI.operator.cal.fixFrontColor);
obj.settings.UI.operator.val.eyeColors = color2RGBA(obj.settings.UI.operator.val.eyeColors);
obj.settings.UI.operator.val.bgColor = color2RGBA(obj.settings.UI.operator.val.bgColor);
obj.settings.UI.operator.val.fixBackColor = color2RGBA(obj.settings.UI.operator.val.fixBackColor);
obj.settings.UI.operator.val.fixFrontColor = color2RGBA(obj.settings.UI.operator.val.fixFrontColor);
obj.settings.UI.operator.val.onlineGaze.eyeColors = color2RGBA(obj.settings.UI.operator.val.onlineGaze.eyeColors);
obj.settings.UI.operator.val.onlineGaze.fixBackColor = color2RGBA(obj.settings.UI.operator.val.onlineGaze.fixBackColor);
obj.settings.UI.operator.val.onlineGaze.fixFrontColor = color2RGBA(obj.settings.UI.operator.val.onlineGaze.fixFrontColor);
obj.settings.UI.plot.bgColor = color2RGBA(obj.settings.UI.plot.bgColor);
obj.settings.UI.plot.eyeColors = color2RGBA(obj.settings.UI.plot.eyeColors);
obj.settings.UI.plot.dotPosLine.color = color2RGBA(obj.settings.UI.plot.dotPosLine.color);
obj.settings.UI.plot.referenceLine.color = color2RGBA(obj.settings.UI.plot.referenceLine.color);
obj.settings.UI.plot.ax.bgColor = color2RGBA(obj.settings.UI.plot.ax.bgColor);
obj.settings.UI.plot.ax.lineColor = color2RGBA(obj.settings.UI.plot.ax.lineColor);
obj.settings.UI.plot.ax.highlightColor = color2RGBA(obj.settings.UI.plot.ax.highlightColor);
obj.settings.UI.plot.ax.axisLbl.color = color2RGBA(obj.settings.UI.plot.ax.axisLbl.color);
obj.settings.UI.plot.ax.tickLbl.color = color2RGBA(obj.settings.UI.plot.ax.tickLbl.color);
obj.settings.UI.plot.ax.valLbl.color = color2RGBA(obj.settings.UI.plot.ax.valLbl.color);
obj.settings.UI.plot.but.exit.fillColor = color2RGBA(obj.settings.UI.plot.but.exit.fillColor);
obj.settings.UI.plot.but.exit.edgeColor = color2RGBA(obj.settings.UI.plot.but.exit.edgeColor);
obj.settings.UI.plot.but.exit.textColor = color2RGBA(obj.settings.UI.plot.but.exit.textColor);
obj.settings.UI.plot.but.valSel.fillColor = color2RGBA(obj.settings.UI.plot.but.valSel.fillColor);
obj.settings.UI.plot.but.valSel.edgeColor = color2RGBA(obj.settings.UI.plot.but.valSel.edgeColor);
obj.settings.UI.plot.but.valSel.textColor = color2RGBA(obj.settings.UI.plot.but.valSel.textColor);
obj.settings.UI.advcal.instruct.color = color2RGBA(obj.settings.UI.advcal.instruct.color);
obj.settings.UI.button.advcal.changeEye.fillColor = color2RGBA(obj.settings.UI.button.advcal.changeEye.fillColor);
obj.settings.UI.button.advcal.changeEye.edgeColor = color2RGBA(obj.settings.UI.button.advcal.changeEye.edgeColor);
obj.settings.UI.button.advcal.changeEye.textColor = color2RGBA(obj.settings.UI.button.advcal.changeEye.textColor);
obj.settings.UI.button.advcal.toggEyeIm.fillColor = color2RGBA(obj.settings.UI.button.advcal.toggEyeIm.fillColor);
obj.settings.UI.button.advcal.toggEyeIm.edgeColor = color2RGBA(obj.settings.UI.button.advcal.toggEyeIm.edgeColor);
obj.settings.UI.button.advcal.toggEyeIm.textColor = color2RGBA(obj.settings.UI.button.advcal.toggEyeIm.textColor);
obj.settings.UI.button.advcal.calval.fillColor = color2RGBA(obj.settings.UI.button.advcal.calval.fillColor);
obj.settings.UI.button.advcal.calval.edgeColor = color2RGBA(obj.settings.UI.button.advcal.calval.edgeColor);
obj.settings.UI.button.advcal.calval.textColor = color2RGBA(obj.settings.UI.button.advcal.calval.textColor);
obj.settings.UI.button.advcal.continue.fillColor = color2RGBA(obj.settings.UI.button.advcal.continue.fillColor);
obj.settings.UI.button.advcal.continue.edgeColor = color2RGBA(obj.settings.UI.button.advcal.continue.edgeColor);
obj.settings.UI.button.advcal.continue.textColor = color2RGBA(obj.settings.UI.button.advcal.continue.textColor);
obj.settings.UI.button.advcal.calibrate.fillColor = color2RGBA(obj.settings.UI.button.advcal.calibrate.fillColor);
obj.settings.UI.button.advcal.calibrate.edgeColor = color2RGBA(obj.settings.UI.button.advcal.calibrate.edgeColor);
obj.settings.UI.button.advcal.calibrate.textColor = color2RGBA(obj.settings.UI.button.advcal.calibrate.textColor);
obj.settings.UI.button.advcal.discard.fillColor = color2RGBA(obj.settings.UI.button.advcal.discard.fillColor);
obj.settings.UI.button.advcal.discard.edgeColor = color2RGBA(obj.settings.UI.button.advcal.discard.edgeColor);
obj.settings.UI.button.advcal.discard.textColor = color2RGBA(obj.settings.UI.button.advcal.discard.textColor);
obj.settings.UI.button.advcal.snapshot.fillColor = color2RGBA(obj.settings.UI.button.advcal.snapshot.fillColor);
obj.settings.UI.button.advcal.snapshot.edgeColor = color2RGBA(obj.settings.UI.button.advcal.snapshot.edgeColor);
obj.settings.UI.button.advcal.snapshot.textColor = color2RGBA(obj.settings.UI.button.advcal.snapshot.textColor);
obj.settings.UI.button.advcal.toggHead.fillColor = color2RGBA(obj.settings.UI.button.advcal.toggHead.fillColor);
obj.settings.UI.button.advcal.toggHead.edgeColor = color2RGBA(obj.settings.UI.button.advcal.toggHead.edgeColor);
obj.settings.UI.button.advcal.toggHead.textColor = color2RGBA(obj.settings.UI.button.advcal.toggHead.textColor);
obj.settings.UI.button.advcal.toggGaze.fillColor = color2RGBA(obj.settings.UI.button.advcal.toggGaze.fillColor);
obj.settings.UI.button.advcal.toggGaze.edgeColor = color2RGBA(obj.settings.UI.button.advcal.toggGaze.edgeColor);
obj.settings.UI.button.advcal.toggGaze.textColor = color2RGBA(obj.settings.UI.button.advcal.toggGaze.textColor);
obj.settings.UI.button.advcal.toggAuto.fillColor = color2RGBA(obj.settings.UI.button.advcal.toggAuto.fillColor);
obj.settings.UI.button.advcal.toggAuto.edgeColor = color2RGBA(obj.settings.UI.button.advcal.toggAuto.edgeColor);
obj.settings.UI.button.advcal.toggAuto.textColor = color2RGBA(obj.settings.UI.button.advcal.toggAuto.textColor);
obj.settings.UI.button.advcal.toggPlot.fillColor = color2RGBA(obj.settings.UI.button.advcal.toggPlot.fillColor);
obj.settings.UI.button.advcal.toggPlot.edgeColor = color2RGBA(obj.settings.UI.button.advcal.toggPlot.edgeColor);
obj.settings.UI.button.advcal.toggPlot.textColor = color2RGBA(obj.settings.UI.button.advcal.toggPlot.textColor);
obj.settings.UI.advcal.menu.bgColor = color2RGBA(obj.settings.UI.advcal.menu.bgColor);
obj.settings.UI.advcal.menu.itemColor = color2RGBA(obj.settings.UI.advcal.menu.itemColor);
obj.settings.UI.advcal.menu.itemColorActive = color2RGBA(obj.settings.UI.advcal.menu.itemColorActive);
obj.settings.UI.advcal.menu.text.color = color2RGBA(obj.settings.UI.advcal.menu.text.color);
obj.settings.UI.advcal.menu.text.eyeColors = color2RGBA(obj.settings.UI.advcal.menu.text.eyeColors);
obj.settings.UI.advcal.avg.text.color = color2RGBA(obj.settings.UI.advcal.avg.text.color);
obj.settings.UI.advcal.avg.text.eyeColors = color2RGBA(obj.settings.UI.advcal.avg.text.eyeColors);
obj.settings.UI.advcal.hover.bgColor = color2RGBA(obj.settings.UI.advcal.hover.bgColor);
obj.settings.UI.advcal.hover.text.color = color2RGBA(obj.settings.UI.advcal.hover.text.color);
obj.settings.UI.advcal.hover.text.eyeColors = color2RGBA(obj.settings.UI.advcal.hover.text.eyeColors);
obj.settings.UI.advcal.onlineGaze.eyeColors = color2RGBA(obj.settings.UI.advcal.onlineGaze.eyeColors);
obj.settings.UI.advcal.plot.bgColor = color2RGBA(obj.settings.UI.advcal.plot.bgColor);
obj.settings.UI.advcal.plot.eyeColors = color2RGBA(obj.settings.UI.advcal.plot.eyeColors);
obj.settings.UI.advcal.plot.dotPosLine.color = color2RGBA(obj.settings.UI.advcal.plot.dotPosLine.color);
obj.settings.UI.advcal.plot.referenceLine.color = color2RGBA(obj.settings.UI.advcal.plot.referenceLine.color);
obj.settings.UI.advcal.plot.ax.bgColor = color2RGBA(obj.settings.UI.advcal.plot.ax.bgColor);
obj.settings.UI.advcal.plot.ax.lineColor = color2RGBA(obj.settings.UI.advcal.plot.ax.lineColor);
obj.settings.UI.advcal.plot.ax.highlightColor = color2RGBA(obj.settings.UI.advcal.plot.ax.highlightColor);
obj.settings.UI.advcal.plot.ax.axisLbl.color = color2RGBA(obj.settings.UI.advcal.plot.ax.axisLbl.color);
obj.settings.UI.advcal.plot.ax.tickLbl.color = color2RGBA(obj.settings.UI.advcal.plot.ax.tickLbl.color);
obj.settings.UI.advcal.plot.ax.valLbl.color = color2RGBA(obj.settings.UI.advcal.plot.ax.valLbl.color);
obj.settings.UI.advcal.plot.but.exit.fillColor = color2RGBA(obj.settings.UI.advcal.plot.but.exit.fillColor);
obj.settings.UI.advcal.plot.but.exit.edgeColor = color2RGBA(obj.settings.UI.advcal.plot.but.exit.edgeColor);
obj.settings.UI.advcal.plot.but.exit.textColor = color2RGBA(obj.settings.UI.advcal.plot.but.exit.textColor);
obj.settings.UI.advcal.plot.but.valSel.fillColor = color2RGBA(obj.settings.UI.advcal.plot.but.valSel.fillColor);
obj.settings.UI.advcal.plot.but.valSel.edgeColor = color2RGBA(obj.settings.UI.advcal.plot.but.valSel.edgeColor);
obj.settings.UI.advcal.plot.but.valSel.textColor = color2RGBA(obj.settings.UI.advcal.plot.but.valSel.textColor);
obj.settings.UI.advcal.refCircleClr = color2RGBA(obj.settings.UI.advcal.refCircleClr);
obj.settings.UI.advcal.headCircleEdgeClr = color2RGBA(obj.settings.UI.advcal.headCircleEdgeClr);
obj.settings.UI.advcal.headCircleFillClr = color2RGBA(obj.settings.UI.advcal.headCircleFillClr);
obj.settings.UI.advcal.eyeClr = color2RGBA(obj.settings.UI.advcal.eyeClr);
obj.settings.UI.advcal.eyeClrPosMissing = color2RGBA(obj.settings.UI.advcal.eyeClrPosMissing);
obj.settings.UI.advcal.eyeBorderClr = color2RGBA(obj.settings.UI.advcal.eyeBorderClr);
obj.settings.UI.advcal.eyeLidClr = color2RGBA(obj.settings.UI.advcal.eyeLidClr);
obj.settings.UI.advcal.pupilClr = color2RGBA(obj.settings.UI.advcal.pupilClr);
obj.settings.UI.advcal.crossClr = color2RGBA(obj.settings.UI.advcal.crossClr);
obj.settings.UI.advcal.eyeColors = color2RGBA(obj.settings.UI.advcal.eyeColors);
obj.settings.UI.advcal.bgColor = color2RGBA(obj.settings.UI.advcal.bgColor);
obj.settings.UI.advcal.fixBackColor = color2RGBA(obj.settings.UI.advcal.fixBackColor);
obj.settings.UI.advcal.fixFrontColor = color2RGBA(obj.settings.UI.advcal.fixFrontColor);
obj.settings.UI.advcal.fixPoint.text.color = color2RGBA(obj.settings.UI.advcal.fixPoint.text.color);
obj.settings.UI.advcal.participant.refCircleClr = color2RGBA(obj.settings.UI.advcal.participant.refCircleClr);
obj.settings.UI.advcal.participant.headCircleEdgeClr= color2RGBA(obj.settings.UI.advcal.headCircleEdgeClr);
obj.settings.UI.advcal.participant.headCircleFillClr= color2RGBA(obj.settings.UI.advcal.participant.headCircleFillClr);
obj.settings.UI.advcal.participant.eyeClr = color2RGBA(obj.settings.UI.advcal.participant.eyeClr);
obj.settings.UI.advcal.participant.eyeClrPosMissing = color2RGBA(obj.settings.UI.advcal.participant.eyeClrPosMissing);
obj.settings.UI.advcal.participant.eyeBorderClr = color2RGBA(obj.settings.UI.advcal.participant.eyeBorderClr);
obj.settings.UI.advcal.participant.eyeLidClr = color2RGBA(obj.settings.UI.advcal.participant.eyeLidClr);
obj.settings.UI.advcal.participant.pupilClr = color2RGBA(obj.settings.UI.advcal.participant.pupilClr);
obj.settings.UI.advcal.participant.crossClr = color2RGBA(obj.settings.UI.advcal.participant.crossClr);
obj.settings.advcal.bgColor = color2RGBA(obj.settings.advcal.bgColor);
obj.settings.advcal.fixBackColor = color2RGBA(obj.settings.advcal.fixBackColor);
obj.settings.advcal.fixFrontColor = color2RGBA(obj.settings.advcal.fixFrontColor);
end
% getters
function systemInfo = get.systemInfo(obj)
systemInfo = [];
if ~isempty(obj.buffer)
systemInfo = obj.buffer.getEyeTrackerInfo();
systemInfo.SDKVersion = obj.buffer.SDKVersion; % SDK version consumed by MEX file
end
end
function deviceName = get.deviceName(obj)
deviceName = [];
if ~isempty(obj.buffer)
deviceName = obj.buffer.deviceName;
end
end
function serialNumber = get.serialNumber(obj)
serialNumber = [];
if ~isempty(obj.buffer)
serialNumber = obj.buffer.serialNumber;
end
end
function model = get.model(obj)
model = [];
if ~isempty(obj.buffer)
model = obj.buffer.model;
end
end
function firmwareVersion = get.firmwareVersion(obj)
firmwareVersion = [];
if ~isempty(obj.buffer)
firmwareVersion = obj.buffer.firmwareVersion;
end
end
function runtimeVersion = get.runtimeVersion(obj)
runtimeVersion = [];
if ~isempty(obj.buffer)
runtimeVersion = obj.buffer.runtimeVersion;
end
end
function address = get.address(obj)
address = [];
if ~isempty(obj.buffer)
address = obj.buffer.address;
end
end
function capabilities = get.capabilities(obj)
capabilities = [];
if ~isempty(obj.buffer)
capabilities = obj.buffer.capabilities;
end
end
function supportedFrequencies = get.supportedFrequencies(obj)
supportedFrequencies = [];
if ~isempty(obj.buffer)
supportedFrequencies = obj.buffer.supportedFrequencies;
end
end
function supportedModes = get.supportedModes(obj)
supportedModes = [];
if ~isempty(obj.buffer)
supportedModes = obj.buffer.supportedModes;
end
end
function frequency = get.frequency(obj)
frequency = [];
if ~isempty(obj.buffer)
frequency = obj.buffer.frequency;
end
end
function trackingMode = get.trackingMode(obj)
trackingMode = [];
if ~isempty(obj.buffer)
trackingMode = obj.buffer.trackingMode;
end
end
% setters
function set.frequency(obj,frequency)
assert(nargin>1,'Titta::set.frequency: provide frequency argument.');
if ~isempty(obj.buffer)
obj.buffer.frequency = frequency;
% if successful (would have thrown on previous line if
% not), update frequency stored in settings as well
obj.settings.freq = obj.buffer.frequency;
end
end
function set.trackingMode(obj,trackingMode)
assert(nargin>1,'Titta::set.trackingMode: provide tracking mode argument.');
if ~isempty(obj.buffer)
obj.buffer.trackingMode = trackingMode;
% if successful (would have thrown on previous line if
% not), update tracking mode stored in settings as well
obj.settings.trackingMode = obj.buffer.trackingMode;
end
end
function out = init(obj, address)
% Initialize Titta instance
%
% INSTANCE = Titta.init() uses the currently active settings to
% search and connect to the indicated Tobii eye tracker and
% initializes it.
%
% INSTANCE = Titta.init(ADDRESS) bypasses the search for all
% connected eyetrackers and opens the tracker at the
% specified ADDRESS.
%
% See also TITTA.TITTA, TITTA.GETOPTIONS, TITTA.SETOPTIONS
% Load in our callback buffer mex
obj.buffer = TittaMex();
obj.buffer.startLogging();
% Connect to eyetracker
trackers = [];
qHaveAddress = nargin>=2 && ~isempty(address);
if qHaveAddress
% if user provided an eye tracker address to connect to,
% get info about this eye tracker
trackers = obj.buffer.getEyeTrackerFromAddress(address);
end
iTry = 1;
if exist('WaitSecs','file')==3
wfunc = @(x) WaitSecs('YieldSecs',x);
else
wfunc = @pause;
end
while true
if iTry<obj.settings.nTryReConnect+1 && ~qHaveAddress
func = @warning;
else
func = @error;
end
% see which eye trackers are available
if ~qHaveAddress
trackers = obj.buffer.findAllEyeTrackers();
end
% find matching eye-tracker, first by model
if isempty(trackers) || ~any(strcmp({trackers.model},obj.settings.tracker))
extra = '';
if iTry==obj.settings.nTryReConnect+1 || qHaveAddress
if ~isempty(trackers)
if qHaveAddress
extra = sprintf('\nYou requested to connect to the eye tracker at %s, but this eye tracker is a %s, not a %s as expected from the settings you specified',address, trackers.model, obj.settings.tracker);
else
extra = sprintf('\nI did find the following:%s',sprintf('\n %s',trackers.model));
end
else
extra = sprintf('\nNo eye trackers connected.');
end
end
func('Titta: No eye trackers of model ''%s'' connected%s',obj.settings.tracker,extra);
wfunc(obj.settings.connectRetryWait(min(iTry,end)));
iTry = iTry+1;
continue;
end
qModel = strcmp({trackers.model},obj.settings.tracker);
% If obligatory serial also given, check on that.
% A serial number preceeded by '*' denotes the serial
% number is optional. That means that if only a single
% other tracker of the same type is found, that one will be
% used.
assert(sum(qModel)==1 || ~isempty(obj.settings.serialNumber),'Titta: If more than one connected eye tracker is of the requested model, a serial number must be provided to allow connecting to the right one')
if sum(qModel)>1 || (~isempty(obj.settings.serialNumber) && obj.settings.serialNumber(1)~='*')
% more than one tracker found or non-optional serial
serial = obj.settings.serialNumber;
if serial(1)=='*'
serial(1) = [];
end
qTracker = qModel & strcmp({trackers.serialNumber},serial);
if ~any(qTracker)
extra = '';
if qHaveAddress
extra = sprintf('\nYou requested to connect to the %s eye tracker at %s, but this eye tracker has the serial number %s, not %s as expected from the settings you specified', trackers.model, address, trackers.serialNumber, serial);
elseif iTry==obj.settings.nTryReConnect+1
extra = sprintf('\nI did find eye trackers of model ''%s'' with the following serial numbers:%s',obj.settings.tracker,sprintf('\n %s',trackers.serialNumber));
end
func('Titta: No eye trackers of model ''%s'' with serial ''%s'' connected.%s',obj.settings.tracker,serial,extra);
wfunc(obj.settings.connectRetryWait(min(iTry,end)));
iTry = iTry+1;
continue;
else
break;
end
else
% the single tracker we found is fine, use it
qTracker = qModel;
break;
end
end
% get our instance
theTracker = trackers(qTracker);
% provide callback buffer mex with eye tracker
obj.buffer.init(theTracker.address);
% apply license(s) if needed
if ~isempty(obj.settings.licenseFile)
if ~iscell(obj.settings.licenseFile)
obj.settings.licenseFile = {obj.settings.licenseFile};
end
% load license files
nLicenses = length(obj.settings.licenseFile);
licenses = cell(1,nLicenses);
for l = 1:nLicenses
fid = fopen(obj.settings.licenseFile{l},'r'); % users should provide fully qualified paths or paths that are valid w.r.t. pwd
licenses{l} = fread(fid,inf,'*uint8');
fclose(fid);
end
% apply to selected eye tracker.
applyResults = obj.buffer.applyLicenses(licenses);
qFailed = ~strcmp(applyResults,'TOBII_RESEARCH_LICENSE_VALIDATION_RESULT_OK');
if any(qFailed)
info = cell(sum(2,qFailed));
info(1,:) = applyResults(qFailed);
info(2,:) = obj.settings.licenseFile(qFailed);
info = sprintf(' %s (%s)\n',info{:}); info(end) = [];
error('Titta: the following provided license(s) couldn''t be applied:\n%s',info);
end
% applying license may have changed eye tracker's
% capabilities or other info. get a fresh copy
theTracker = obj.buffer.getEyeTrackerInfo();
end
% set tracker-specific internal paramters
switch obj.settings.tracker
case 'Tobii Pro Fusion'
obj.eyeImageCanvasSize = [600 300]; % width x height
end
% set tracker to operate at requested tracking frequency
try
obj.buffer.frequency = obj.settings.freq;
catch ME
% provide nice error message
allFs = ['[' sprintf('%d, ',theTracker.supportedFrequencies) ']']; allFs(end-2:end-1) = [];
error('Titta: Error setting tracker sampling frequency to %d. Possible tracking frequencies for this %s are %s.\nRaw error info:\n%s',obj.settings.freq,obj.settings.tracker,allFs,ME.getReport('extended'))
end
% set eye tracking mode.
if ~isempty(obj.settings.trackingMode)
try
obj.buffer.trackingMode = obj.settings.trackingMode;
catch ME
% add info about possible tracking modes.
allModes = ['[' sprintf('''%s'', ',theTracker.supportedModes{:}) ']']; allModes(end-2:end-1) = [];
error('Titta: Error setting tracker mode to ''%s''. Possible tracking modes for this %s are %s. If a mode you expect is missing, check whether the eye tracker firmware is up to date.\nRaw error info:\n%s',obj.settings.trackingMode,obj.settings.tracker,allModes,ME.getReport('extended'))
end
end
% if monocular tracking is requested, check that it is
% supported
obj.changeAndCheckCalibEyeMode();
% get info about the system
assert(obj.systemInfo.frequency==obj.settings.freq,'Titta: Tracker not running at requested sampling rate (%d Hz), but at %d Hz',obj.settings.freq,obj.systemInfo.frequency);
out.systemInfo = obj.systemInfo;
% get information about display geometry and trackbox
obj.geom.displayArea = obj.buffer.getDisplayArea();
try
obj.geom.trackBox = obj.buffer.getTrackBox();
% get width and height of trackbox at middle depth
obj.geom.trackBox.halfWidth = mean([obj.geom.trackBox.frontUpperRight(1) obj.geom.trackBox.backUpperRight(1)])/10;
obj.geom.trackBox.halfHeight = mean([obj.geom.trackBox.frontUpperRight(2) obj.geom.trackBox.backUpperRight(2)])/10;
catch
% tracker does not support trackbox
obj.geom.trackBox.halfWidth = [];
obj.geom.trackBox.halfHeight = [];
end
out.geom = obj.geom;
% mark as inited
obj.isInitialized = true;
end
function out = calibrate(obj,wpnt,flag,previousCalibs)
% Do participant setup and calibration
%
% CALIBRATIONATTEMPT = Titta.calibrate(WPNT) displays the
% participant setup and calibration interface on the
% PsychToolbox window specified by WPNT.
%
% WPNT can also be an array of two window pointers.
% In this case, the first window pointer is taken to refer
% to the participant screen, and the second to an operator
% screen. A minimal interface is then presented on the
% participant screen, while full information is shown on the
% operator screen, including a live view of gaze data and
% eye images (if available) during calibration and
% validation.
%
% CALIBRATIONATTEMPT is a struct containing information
% about the calibration/validation run.
%
% CALIBRATIONATTEMPT = Titta.calibrate(WPNT,FLAG) provides
% control over whether the call causes the eye tracker's
% calibration mode to be entered or left. The available
% flags are:
% 1 - enter calibration mode when starting calibration
% 2 - exit calibration mode when calibration finished
% 3 - (default) both enter and exit calibration mode
%
% FLAG is used for bimonocular calibrations, when
% Titta.calibrate() is called twice in a row, first to
% calibrate the first eye (use FLAG=1 to enter calibration
% mode here but not exit), and then a second time to
% calibrate the other eye (use FLAG=2 to exit calibration
% mode when done).
%
% CALIBRATIONATTEMPT = Titta.calibrate(WPNT,FLAG,PREVIOUSCALIBS)
% allows to prepopulate the interface with previous
% calibration(s). The previously selected calibration is
% made active and it can then be revalidated and used, or
% replaced. PREVIOUSCALIBS is expected to be a
% CALIBRATIONATTEMPT output from a previous run of
% Titta.calibrate. Note that the PREVIOUSCALIBS
% functionality should be used together with bimonocular
% calibration _only_ when the calibration of the first eye
% is not replaced (validating it is ok, and recommended).
% This because prepopulating calibrations for the second eye
% will load this previous calibration, and thus undo any new
% calibration for the first eye.
%
% INTERFACE
% During anywhere on the participant setup and calibration
% screens, the following key combinations are available:
% shift-escape - hard exit from the calibration mode. By
% default (see
% settings.UI.hardExitClosesPTB), this
% causes en error to be thrown and script
% execution to stop if that error is not
% caught.
% shift-s - skip calibration. If still at setup
% screen for the first time, the last
% calibration (perhaps of a previous
% session) remains active. To clear any
% calibration, first enter the calibration
% screen and immediately then skip with
% this key combination.
% shift-d - take screenshot of the participant
% display, which will be stored to the
% current active directory (cd).
% shift-o - when in dual-screen mode, take a
% screenshot of the operator display, which
% will be stored to the current active
% directory (cd).
% shift-g - when in dual screen mode, by default the
% show gaze button on the validation result
% screen only shows real-time gaze position
% on the operator's screen. If the shift
% key is held down while clicking the
% button with the mouse, or when pressing
% the functionality's hotkey (g by
% default, see documentation of validation
% results screen interface below),
% real-time gaze will also be shown on the
% participant's screen.
%
% In addition to these, the three different screens that
% make up this procedure each have their own keys available.
% Some of these are hardcoded, others can be changed through
% Titta's settings. In the latter case, their default value
% is listed here, and the settings name is indicated in
% abbreviated form (e.g. `setup.toggEyeIm` refers to the
% setting `settings.UI.button.setup.toggEyeIm.accelerator`,
% gotten from Titta.getDefaults() or Titta.getOptions()).
% For the setup and validation result displays, these keys
% have a clickable button in the interface associated with
% them. Most of these buttons are visible by default, but
% some are not. You can change button visibility by
% changing, e.g.,
% `settings.UI.button.setup.toggEyeIm.visible`. Invisible
% buttons can still be activated or deactivated by means of
% the configured keys.
%
% Setup display:
% spacebar - start a calibration (setup.cal)
% e - toggle eye images, if available
% (setup.toggEyeIm)
% p - return to validation result display,
% available if there are any previous
% calibrations (setup.prevcal)
% c - open menu to change which eye will be
% calibrated (both, left, right). The menu can
% be keyboard-controlled: each of the items in
% the menu are preceded by the number to press
% to activate that option. Available only if
% the eye tracker supports monocular
% calibration (setup.changeeye)
%
% Calibration and validation display:
% escape - return to setup screen.
% r - restart calibration sequence from the
% beginning
% backspace - redo the current calibration/validation
% point. When using the
% AnimatedCalibrationDisplay class
% (settings.cal.drawFunction), this causes the
% currently displayed point to blink.
% spacebar - accept current calibration/validation point.
% Whether it is needed to press spacebar to
% collect data for a point depends on the
% settings.cal.autoPace setting.
%
% Validation result display:
% spacebar - select currently displayed calibration and
% exit the interface/continue experiment
% (val.continue)
% escape - start a new calibration (val.recal)
% v - revalidate the current calibration
% (val.reval)
% s - return to the setup screen (val.setup)
% c - bring up a menu from which other
% calibrations performed in the same session
% can be selected (val.selcal)
% g - toggle whether online gaze position is
% visualized on the screen. When in dual
% screen mode, gaze will only be visualized to
% the operator. Press shift-g (or hold down
% shift while pressing the interface button
% with the mouse) to also show the online
% gaze position on the participant screen
% (val.toggGaze)
% p - bring up plot of gaze and pupil data
% collected during validation (val.toggPlot)
% t - toggle between whether gaze data collected
% during validation or during calibration is
% shown in the interface (val.toggCal)
% x - toggle between whether gaze data and
% calibrations are shown in screen space or
% tracker space (these are the same unless
% settings.cal.pointPosTrackerSpace is
% specified) are shown in the interface
% (val.toggSpace)
%
% See also TITTA.CALIBRATEADVANCED, TITTA.GETOPTIONS,
% TITTA.GETDEFAULTS
% this function does all setup, draws the interface, etc
% flag is for if you want to calibrate the two eyes separately,
% monocularly. When doing first eye, set flag to 1, when second
% eye set flag to 2. Internally for Titta flag 1 has the
% meaning "first calibration" and flag 2 "final calibration".
% This is checked against with bitand, so when user didn't
% specify we assume a single calibration will be done (which is
% thus both first and final) and thus set flag to 3.
if nargin<3 || isempty(flag)
flag = 3;
end
if nargin<4 || isempty(previousCalibs)
previousCalibs = [];
end
% get info about screen
screenState = obj.getScreenInfo(wpnt);
% init key, mouse state
[~,~,obj.keyState] = KbCheck();
[~,~,obj.mouseState] = GetMouse();
% make sure we get eye openness data if available
qHasEyeOpenness = obj.buffer.hasStream('eyeOpenness');
if qHasEyeOpenness
prevEyeOpennessState = obj.buffer.setIncludeEyeOpennessInGaze(true);
end
%%% 1. some preliminary setup, to make sure we are in known state
if bitand(flag,1)
obj.buffer.leaveCalibrationMode(true); % make sure we're not already in calibration mode (start afresh)
end
obj.StopRecordAll();
%%% 2. enter the setup/calibration screens
% The below is a big loop that will run possibly multiple
% calibration until exiting because skipped or a calibration is
% selected by user.
% there are two start modes:
% 0. skip head positioning, go straight to calibration
% 1. start with head positioning interface
startScreen = obj.settings.UI.startScreen;
qHasEnteredCalMode = false;
qGoToValidationViewer = false;
if ~isempty(previousCalibs)
assert(strcmp(previousCalibs.type,'standard'),'Titta.calibrate: only previous calibrations created by Titta.calibrate can be loaded, not those from Titta.calibrateAdvanced')
% prepopulate with previous calibrations passed by user
out = previousCalibs;
% preload the one previously selected by user
kCal = out.selectedCal; % index into list of calibration attempts
if bitand(flag,1) && ~qHasEnteredCalMode
% else, assume calibration mode has already been
% entered. If that is not the case, its user error when
% the loadOtherCal() below fails.
obj.doEnterCalibrationMode();
qHasEnteredCalMode = true;
end
obj.loadOtherCal(out.attempt{kCal},kCal,[],true);
currentSelection = kCal; % keeps track of calibration that is currently applied
% NB: qNewCal should also in this case be true, as the
% setup screen shown first is the start of a potential new
% calibration, if users skip to previously loaded
% calibrations, they cancel this potential new calibration
% like normal. Also, without this, when loading a previous
% calibration (this code branch) and then pressing
% continue/calibrate on the setup screen, a new validation
% is added for the loaded calibration, not a new
% calibration started.
if startScreen==0
% when user wants to skip the setup screen, bring them
% straight to the validation result screen when loading
% a previous calibration.
qGoToValidationViewer = true;
end
else
kCal = 0; % index into list of calibration attempts
currentSelection = nan; % keeps track of calibration that is currently applied
end
qNewCal = true;
out.type = 'standard';
out.selectedCal = nan;
out.wasSkipped = false;
while true
if qNewCal
if ~kCal
kCal = 1;
else