Program.cs 1.75 KB
Newer Older
1
using System;
2
using TrackerBridge;
3 4 5 6 7

namespace GazeWebSocketServer
{
    public class Program
    {
8
        private static GazeServer gazeServer;
9

10 11
        public static void Main(string[] args)
        {
12 13 14
            ConfigurationData.InitializeUnexistingWithDefaults();
            ConfigurationData config = ConfigurationData.ParseToObject();

15
            IBridgeTracker tracker;
16
            if (args.Length > 0 && args[0] == "-d")
17
            {
18
                tracker = new FakeTracker(600);
19 20 21
            }
            else
            {
22
                tracker = new TobiiEyeTracker(config.TrackerSerialNumber);
23
            }
24

25 26 27 28 29
            tracker.ConnectionEvent += OnConnectionEstablished;
            tracker.ConnectionTimeout += OnConnectionTimeout;
            tracker.GazeDataAvailable += OnGazeDataAvailable;
            tracker.Connect();

30 31 32 33 34
            gazeServer = new GazeServer(config.WebSocketPort, config.WebSocketEndpoint);
            gazeServer.Start();
            Console.ReadLine();
        }

35
        
36

37
        private static void OnGazeDataAvailable(GazeData data, Object sender)
38
        {
39 40 41 42
            if (gazeServer != null && gazeServer.isRunning)
            {
                gazeServer.Publish(data);
            }
43 44
        }

45
        private static void OnConnectionTimeout(IBridgeTracker sender)
46 47 48 49
        {
            Console.WriteLine("Timeout while searching for trackers.");
        }

50
        private static void OnConnectionEstablished(IBridgeTracker sender)
51
        {
52
            Console.WriteLine($"Tracker {sender.SerialNumber} connected.");
53
            ConfigurationData config = ConfigurationData.ParseToObject();
54 55
            sender.TrackingFrequency = config.TrackerFrequency;
            sender.OutputFrequency = config.OutputFrequency;
56 57 58
        }
    }
}