using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tobii.Research; namespace GazeWebSocketServer { class EyeTrackerClient { private IEyeTracker eyeTracker; private GazeDataProcessor gazeDataProcessor; private List gazeCoordinateBehaviors; public EyeTrackerClient(ConfigurationData config) { gazeCoordinateBehaviors = new List(); while (eyeTracker == null) { EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers(); if (eyeTrackers.Count > 0) { foreach(IEyeTracker t in eyeTrackers) { if(config.TrackerSerialNumber == t.SerialNumber) { eyeTracker = t; } } } } gazeDataProcessor = new GazeDataProcessor(); eyeTracker.SetGazeOutputFrequency(config.TrackerFrequency); } public void Start(GazeCoordinateBehavior gazeCoordinateBehavior) { gazeCoordinateBehaviors.Add(gazeCoordinateBehavior); eyeTracker.GazeDataReceived += GazeDataReceivedHandler; } public void Stop() { eyeTracker.GazeDataReceived -= GazeDataReceivedHandler; } private void GazeDataReceivedHandler(object sender, GazeDataEventArgs e) { GazeData gazeData = gazeDataProcessor.Extract(e); foreach(GazeCoordinateBehavior behavior in gazeCoordinateBehaviors) { behavior.Publish(gazeData); } Console.WriteLine(gazeData.ToString()); } } }