Commit 6906eca1 by Stefan Schreistetter

Improved mock gaze input via mouse.

parent 3cdd786a
using System;
using System.Threading.Tasks;
using System.Threading;
using WebSocketSharp;
using WebSocketSharp.Server;
using Tobii.Research;
using TrackerBridge;
using System.Windows.Forms;
using System.Drawing;
using System.Timers;
namespace GazeWebSocketServer
{
......@@ -20,7 +17,7 @@ namespace GazeWebSocketServer
if (args.Length > 0 && args[0] == "-d")
{
Task.Run(() => SimulateGazeData(300));
Task.Run(() => SimulateGazeDataHz(120));
}
else
{
......@@ -36,21 +33,20 @@ namespace GazeWebSocketServer
Console.ReadLine();
}
private static void SimulateGazeData(UInt16 frequencyHz)
private static void SimulateGazeDataHz(Int32 frequency)
{
TimeSpan period = new TimeSpan(Convert.ToInt64((1.0 / frequencyHz) * 10e7));
while (true)
System.Timers.Timer timer = new System.Timers.Timer(1.0/frequency);
timer.Elapsed += (Object sender, ElapsedEventArgs e) =>
{
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);
}
};
timer.AutoReset = true;
timer.Start();
}
private static void OnGazeDataAvailable(TobiiEyeTracker sender, GazeData 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