Commit 27926ae6 by Stefan Schreistetter

Added server-side gaze simulation via mouse input.

parent a3cc0c2e
...@@ -11,6 +11,7 @@ namespace GazeWebSocketServer ...@@ -11,6 +11,7 @@ namespace GazeWebSocketServer
class GazeServer class GazeServer
{ {
private WebSocketServer wssv; private WebSocketServer wssv;
public Boolean isRunning = false;
public GazeServer(Int32 port, String endpoint) public GazeServer(Int32 port, String endpoint)
{ {
wssv = new WebSocketServer(port); wssv = new WebSocketServer(port);
...@@ -20,6 +21,7 @@ namespace GazeWebSocketServer ...@@ -20,6 +21,7 @@ namespace GazeWebSocketServer
public void Start() public void Start()
{ {
wssv.Start(); wssv.Start();
isRunning = true;
} }
public void Publish(GazeData gazeData) public void Publish(GazeData gazeData)
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
......
...@@ -5,6 +5,8 @@ using WebSocketSharp; ...@@ -5,6 +5,8 @@ using WebSocketSharp;
using WebSocketSharp.Server; using WebSocketSharp.Server;
using Tobii.Research; using Tobii.Research;
using TrackerBridge; using TrackerBridge;
using System.Windows.Forms;
using System.Drawing;
namespace GazeWebSocketServer namespace GazeWebSocketServer
{ {
...@@ -16,21 +18,48 @@ namespace GazeWebSocketServer ...@@ -16,21 +18,48 @@ namespace GazeWebSocketServer
ConfigurationData.InitializeUnexistingWithDefaults(); ConfigurationData.InitializeUnexistingWithDefaults();
ConfigurationData config = ConfigurationData.ParseToObject(); ConfigurationData config = ConfigurationData.ParseToObject();
TobiiEyeTracker tobiiEyeTracker = new TobiiEyeTracker(config.TrackerSerialNumber); if (args[0] == "-d")
tobiiEyeTracker.ConnectionEvent += OnConnectionEstablished; {
tobiiEyeTracker.ConnectionTimeout += OnConnectionTimeout; Task.Run(() => SimulateGazeData(300));
tobiiEyeTracker.GazeDataAvailable += OnGazeDataAvailable; }
tobiiEyeTracker.Connect(); 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 = new GazeServer(config.WebSocketPort, config.WebSocketEndpoint);
gazeServer.Start(); gazeServer.Start();
Console.ReadLine(); 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) private static void OnGazeDataAvailable(TobiiEyeTracker sender, GazeData data)
{ {
Console.WriteLine(data); Console.WriteLine(data);
gazeServer.Publish(data); if (gazeServer != null && gazeServer.isRunning)
{
gazeServer.Publish(data);
}
} }
private static void OnConnectionTimeout(TobiiEyeTracker sender) private static void OnConnectionTimeout(TobiiEyeTracker sender)
......
...@@ -21,10 +21,10 @@ namespace TrackerBridge ...@@ -21,10 +21,10 @@ namespace TrackerBridge
public GazeData Extract(GazeDataEventArgs e) public GazeData Extract(GazeDataEventArgs e)
{ {
GazeData data = new GazeData(e.LeftEye.GazePoint.PositionOnDisplayArea.X*screenWidth, GazeData data = new GazeData(e.LeftEye.GazePoint.PositionOnDisplayArea.X * screenWidth,
e.LeftEye.GazePoint.PositionOnDisplayArea.Y*screenHeight, e.LeftEye.GazePoint.PositionOnDisplayArea.Y * screenHeight,
e.RightEye.GazePoint.PositionOnDisplayArea.X*screenWidth, e.RightEye.GazePoint.PositionOnDisplayArea.X * screenWidth,
e.RightEye.GazePoint.PositionOnDisplayArea.Y*screenHeight, e.RightEye.GazePoint.PositionOnDisplayArea.Y * screenHeight,
e.DeviceTimeStamp, e.DeviceTimeStamp,
e.SystemTimeStamp); e.SystemTimeStamp);
return data; 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