function [eye,a]=EyeTracking(cmd,eye) % [eye,a]=EyeTracking(cmd,eye) % initiates eye tracking params, tracks, and tests for eye-in-window % if eye.trackEYES=1, otherwise does nothing % % INPUTS: % cmd: determines action % eye: a structure of eye-trecking params and data % OUTPUTS: % a: a matrix with the last eye position results % % USAGE: % cmd='init' initiates parameters. Make appropriate changes to desired params after % this call % cmd='trackEye' - place this call in the loop that displays each stimulus frame % cmd='resetArray' - place this call before each stimulus presentation trial % cmd='getEyePosArray' - place this call after each stim presentation trial with % output parameter a (and save eye position data in it, if needed. % cmd='setZero' - sets zero value (the center for the eye window) % cmd='isINwindow' - tests whether eye is whithin a circular window; needs % a second output parameter a: a=1, if eye is whithin predefined radius % from the center (zero point), and a=0, if it is not % gtb 01/20/2001 global display; a=[]; if ~eye.trackEYES, return; end; switch cmd, case 'init', eye.winrad=1024; % eye window in pixels eye.plotEYEpos=0; % change this value after initiation if want plotting numPts=3600; eye.Array=zeros(numPts,2); % use smaller array if things slow down eye.Samples=0; % change these below! eye.pos=[0 0]; eye.rad=3; % radius of the eye position spot eye.maxin=10; if exist('eyePositions.mat') %this file is generated by eyecalib load eyePositions; eye.zero=mean(eyePositions'); else eye.zero=[]; end; case 'resetArray', eye.Samples=0; eye.Array=zeros(numPts,2); case 'setZero', datain=mean(analin2ch(4,20)); % ie /10*2048. eye.pos(1)=round(datain(1)*display.X/2/eye.maxin+display.X/2); eye.pos(2)=round(display.Y-datain(2)*display.Y/2/eye.maxin-display.Y/2); eye.zero=eye.pos; case 'isINwindow', if nargout<2, error('Need 2 output params with this command'); end; datain=mean(analin2ch(4,20)); % ie /10*2048. eye.pos(1)=round(datain(1)*display.X/2/eye.maxin+display.X/2); eye.pos(2)=round(display.Y-datain(2)*display.Y/2/eye.maxin-display.Y/2); if sum((eye.pos-eye.zero).^2) > eye.winrad^2, a=0; else a=1; end; case 'trackEye', eye.Samples=eye.Samples+1; if isfield(eye,'plotEYEpos'), if eye.plotEYEpos, %erasing old eye position SCREEN(display.windowPtr,'FillOval',0,... [eye.pos(1)-eye.rad eye.pos(2)-eye.rad eye.pos(1)+eye.rad eye.pos(2)+eye.rad]); end; end; datain=mean(analin2ch(4,20)); % ie /10*2048. eye.pos(1)=round(datain(1)*display.X/2/eye.maxin+display.X/2); eye.pos(2)=round(display.Y-datain(2)*display.Y/2/eye.maxin-display.Y/2); eye.Array(eye.Samples,:)=eye.pos; % storing eye data if eye.winrad*eye.winrad>sum(eye.pos.^2), gp.fix.color=3; else gp.fix.color=2; end; if isfield(eye,'plotEYEpos'), if eye.plotEYEpos, %drawing new eye position SCREEN(display.windowPtr,'FillOval',2,... [eye.pos(1)-eye.rad eye.pos(2)-eye.rad eye.pos(1)+eye.rad eye.pos(2)+eye.rad]); end; end; case 'getEyePosArray', if nargout==2, a=eye.Array(1:eye.Samples,:); else error('no output for eye positions provided!'); end; otherwise error('bad Eye Tracking command'); end;