Commit 27926ae6 by Stefan Schreistetter

Added server-side gaze simulation via mouse input.

parent a3cc0c2e
......@@ -11,6 +11,7 @@ namespace GazeWebSocketServer
class GazeServer
{
private WebSocketServer wssv;
public Boolean isRunning = false;
public GazeServer(Int32 port, String endpoint)
{
wssv = new WebSocketServer(port);
......@@ -20,6 +21,7 @@ namespace GazeWebSocketServer
public void Start()
{
wssv.Start();
isRunning = true;
}
public void Publish(GazeData gazeData)
......
......@@ -39,6 +39,8 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......
......@@ -5,6 +5,8 @@ using WebSocketSharp;
using WebSocketSharp.Server;
using Tobii.Research;
using TrackerBridge;
using System.Windows.Forms;
using System.Drawing;
namespace GazeWebSocketServer
{
......@@ -16,22 +18,49 @@ namespace GazeWebSocketServer
ConfigurationData.InitializeUnexistingWithDefaults();
ConfigurationData config = ConfigurationData.ParseToObject();
if (args[0] == "-d")
{
Task.Run(() => SimulateGazeData(300));
}
else
{
TobiiEyeTracker tobiiEyeTracker = new TobiiEyeTracker(config.TrackerSerialNumber);
tobiiEyeTracker.ConnectionEvent += OnConnectionEstablished;
tobiiEyeTracker.ConnectionTimeout += OnConnectionTimeout;
tobiiEyeTracker.GazeDataAvailable += OnGazeDataAvailable;
tobiiEyeTracker.Connect();
}
gazeServer = new GazeServer(config.WebSocketPort, config.WebSocketEndpoint);
gazeServer.Start();
Console.ReadLine();
}
private static void SimulateGazeData(UInt16 frequencyHz)
{
TimeSpan period = new TimeSpan(Convert.ToInt64((1.0 / frequencyHz) * 10e7));
while (true)
{
DateTime start = DateTime.Now;
Point mousePosition = Control.MousePosition;
GazeData data = new GazeData(mousePosition.X, mousePosition.Y, mousePosition.X, mousePosition.Y, 0, 0);
if (gazeServer != null && gazeServer.isRunning)
{
gazeServer.Publish(data);
}
TimeSpan delay = period - (DateTime.Now - start);
Thread.Sleep(delay.Ticks >= 0 ? delay.Milliseconds : 0);
}
}
private static void OnGazeDataAvailable(TobiiEyeTracker sender, GazeData data)
{
Console.WriteLine(data);
if (gazeServer != null && gazeServer.isRunning)
{
gazeServer.Publish(data);
}
}
private static void OnConnectionTimeout(TobiiEyeTracker sender)
{
......
......@@ -21,10 +21,10 @@ namespace TrackerBridge
public GazeData Extract(GazeDataEventArgs e)
{
GazeData data = new GazeData(e.LeftEye.GazePoint.PositionOnDisplayArea.X*screenWidth,
e.LeftEye.GazePoint.PositionOnDisplayArea.Y*screenHeight,
e.RightEye.GazePoint.PositionOnDisplayArea.X*screenWidth,
e.RightEye.GazePoint.PositionOnDisplayArea.Y*screenHeight,
GazeData data = new GazeData(e.LeftEye.GazePoint.PositionOnDisplayArea.X * screenWidth,
e.LeftEye.GazePoint.PositionOnDisplayArea.Y * screenHeight,
e.RightEye.GazePoint.PositionOnDisplayArea.X * screenWidth,
e.RightEye.GazePoint.PositionOnDisplayArea.Y * screenHeight,
e.DeviceTimeStamp,
e.SystemTimeStamp);
return data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment