Myex: A Matlab Interface for the Tobii Eyex Eye-Tracker

Myex is a Matlab interface for the Tobii EyeX eye-tracker. It allows Matlab users to receive incoming data from the eye-tracker, by providing a data buffer that can receive data from the EyeX, and be queried by the user on demand. Myex enables Matlab users to take advantage of low-cost, portable eye-tracking technology, ideal for use in gaze-contingent psychophysical paradigms, or for users looking to develop assistive devices for individuals with impaired mobility.


Introduction
The Tobii EyeX (Tobii Technology, Stockholm, Sweden) is a cheap, portable eye-tracker, with integrated head-tracking.It uses near-infrared light reflected from the user's cornea to measure point-of-gaze (2D screen coordinates, in pixels) and eye-ball position (3D spatial coordinates, in millimeters from the screen).The device automatically partials-out head-movements from the gaze estimates, so the user is not required to user a chin or forehead rest.
Unlike most 'research-grade' eye-trackers -which buffer data internally -the EyeX pushes incoming data directly to a user-specified function.This makes it impossible to interface the EyeX directly using Matlab (The MathWorks, Natick, USA), because Matlab is unable to pass invokable function-pointers to external applications.
The present software solves this problem using an intermediate C subrountine ("myex.mex"),which is capable of receiving/buffering data from the Tobii EyeX on the one hand, and of passing the data on demand to Matlab on the other.

Implementation and architecture
The software was written primarily in C, and can be compiled into a Mex file for use with Matlab.Example compilations are provided for windows 32-bit and 64-bit.The distribution additionally includes a Minimal Working Example written in Matlab.
Use has been intentionally kept extremely simple.There are no dependencies on 3 rd party Matlab toolboxes, and the code provides just three commands: myex(' connect'), myex('getdata'), and myex(' disconnect').A full Minimal Working Example is given in Listing 1.This code is also included as part of the distribution.
Only one connection is permitted at a time, and "disconnect" should be used to close the connection to the eye-tracker after use.Matlab's "clear all" command will also force any open connection to close, and can be used defensively prior to the use of "connect".
The "getdata" command returns a matrix containing any/all additional data since the previous call (one row per sample).Thus, a call to "getdata" every 500 milliseconds would be expected to return a matrix with approximately 25 rows of data (i.e., given the hardware's sampling rate of ~50 Hz).Note, however, that the eye-tracker only pushes data when at least one eye is being tracked, so fewer rows (samples) than expected may be returned.If no new data are available, an empty matrix is returned.Each row (sample) of data contains 12 columns, as detailed in Table 1.

Quality control
Myex has been used continuously within our lab since 2016, and has been used successfully for several gazecontingent psychophysical experiments.Furthermore, manual end-to-end testing has been carried out to ensure stability across different machines and Matlab versions.Note that the code does not in any way modify or affect the data returned by the Tobii EyeX Engine, and Myex introduces negligible additional processing overheads and/or lag.(NB: the latency of any gaze estimate is determined primarily by any smoothing applied within the Tobii EyeX engine itself, and by the transmission speed of the USB connection: <10 ms.).

Operating system
Myex is compatible with Windows 7 and Windows 10 (the only platforms supported by the EyeX eye-tracker).

Programming language
Myex is compatible with all known versions of Matlab.

Additional system requirements
Myex is designed to interface with the Tobii EyeX eyetracker (Tobii Technology, Stockholm, Sweden), which requires a USB 3.0 connection.

Dependencies
Myex requires is compatible with all versions of the Tobii EyeX Interaction Engine from v1.2.0 onwards (at the time of writing the latest version is v1.9.4).There are no Matlab dependencies.However, users wishing to compile Myex from source may need to install an appropriate C/C++ compiler (run "mex -setup" from within Matlab for more info.

Listing 1 :
Minimal Working Example demonstrating how the code can be used to interface with the EyeX hardware (see body text for details).