Skip to content

Commit

Permalink
Updated to v.0.9.40
Browse files Browse the repository at this point in the history
  • Loading branch information
Hskovsgaard committed Jul 30, 2014
1 parent 793a987 commit 886057e
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 110 deletions.
5 changes: 2 additions & 3 deletions Calibration/CalibrationSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="TETCSharpClient, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="TETCSharpClient">
<HintPath>..\TETDLLs\TETCSharpClient.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
Expand Down Expand Up @@ -103,7 +102,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TETControls\TETControls.csproj">
<Project>{E8F5FE05-A82B-47BC-81AC-B5635D8425A6}</Project>
<Project>{c93b12c7-9872-47a3-a2db-d92623476fe5}</Project>
<Name>TETControls</Name>
</ProjectReference>
</ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Calibration/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
<Window x:Class="Calibration.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:TrackBox="clr-namespace:TETControls.TrackBox;assembly=TETControls"
Title="The Eye Tribe BasicUI"
Height="340"
Width="310"
Closed="WindowClosed"
WindowStartupLocation="CenterScreen"
Background="Black"
Icon="favicon.ico">

<Grid>
<Grid x:Name="TrackingStatusGrid">
<TrackBox:TrackBoxStatus x:Name="trackingStatus" Width="300" Height="250" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Top"/>
</Grid>
<Grid x:Name="TrackingStatusGrid" Width="300" Height="250" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Top" />

<Grid x:Name="ButtonControls" VerticalAlignment="Bottom">
<Button x:Name="btnCalibrate" Content="Calibrate" Click="CalibrateClicked" Height="35" Margin="10" VerticalAlignment="Bottom" Background="#FF575757" Foreground="White" />
<Button x:Name="btnAction" Content="Calibrate" Click="ButtonClicked" Height="35" Margin="10" VerticalAlignment="Bottom" Background="#FF575757" Foreground="White" />
</Grid>

<TextBlock x:Name="RatingText" HorizontalAlignment="Center" Text="" VerticalAlignment="Top" Foreground="White" FontSize="15" TextAlignment="Right" TextWrapping="Wrap" FontWeight="Bold" />
</Grid>
</Window>
103 changes: 78 additions & 25 deletions Calibration/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,98 @@
*
*/
using System;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using TETControls.Calibration;
using TETControls.TrackBox;
using TETCSharpClient.Data;
using System.Windows.Interop;
using TETCSharpClient;
using MessageBox = System.Windows.MessageBox;


namespace Calibration
{
public partial class MainWindow
public partial class MainWindow : IConnectionStateListener
{
public MainWindow()
{
ConnectClient();
InitializeComponent();
Loaded += (sender, args) => InitClient();
}

private void ConnectClient()
{
// Create a client for the eye tracker
GazeManager.Instance.Activate(GazeManager.ApiVersion.VERSION_1_0, GazeManager.ClientMode.Push);
InitializeComponent();
}

if (!GazeManager.Instance.IsActivated)
{
MessageBox.Show("EyeTribe Server has not been started");
Close();
}
else if (GazeManager.Instance.IsCalibrated)
private void InitClient()
{
// Default content of the action button
btnAction.Content = "Calibrate";

// Add a fresh instance of the trackbox in case we reinitialize the client connection.
TrackingStatusGrid.Children.Clear();
TrackingStatusGrid.Children.Add(new TrackBoxStatus());

// Add listener if EyeTribe Server is closed
GazeManager.Instance.AddConnectionStateListener(this);

// What is the current connection state
OnConnectionStateChanged(GazeManager.Instance.IsActivated);

if (GazeManager.Instance.IsCalibrated)
{
// Get the latest successful calibration from the EyeTribe server
RatingText.Text = RatingFunction(GazeManager.Instance.LastCalibrationResult);
btnCalibrate.Content = "Re-Calibrate";
btnAction.Content = "Re-Calibrate";
}
}

private void CalibrateClicked(object sender, RoutedEventArgs e)
private void ButtonClicked(object sender, RoutedEventArgs e)
{
btnCalibrate.Content = "Re-Calibrate";
Calibrate();
if (GazeManager.Instance.IsActivated)
{
Calibrate();
}
else
{
ConnectClient();
InitClient();
}
}

private void Calibrate()
{
btnAction.Content = "Re-Calibrate";

//Run the calibration on 'this' monitor
var ActiveScreen = Screen.FromHandle(new WindowInteropHelper(this).Handle);

// Initialize and start the calibration
CalibrationRunner calRunner = new CalibrationRunner(ActiveScreen, ActiveScreen.Bounds.Size, 9);
calRunner.OnResult += calRunner_OnResult;
calRunner.Start();
}

var isCalibrated = calRunner.Start();
if (!isCalibrated) return;
private void calRunner_OnResult(object sender, CalibrationRunnerEventArgs e)
{
if (RatingText.Dispatcher.Thread != Thread.CurrentThread)
{
this.Dispatcher.BeginInvoke(new MethodInvoker(() => calRunner_OnResult(sender, e)));
return;
}

// Show the rating of last accepted current calibration
RatingText.Text = RatingFunction(GazeManager.Instance.LastCalibrationResult);
if (e.Result == CalibrationRunnerResult.Success)
{
RatingText.Text = RatingFunction(e.CalibrationResult);
}
else
{
System.Windows.MessageBox.Show("Calibration failed, please try again");
}
}

private void WindowClosed(object sender, EventArgs e)
Expand All @@ -72,22 +113,34 @@ public string RatingFunction(CalibrationResult result)
var accuracy = result.AverageErrorDegree;

if (accuracy < 0.5)
{
return "Calibration Quality: PERFECT";
}

if (accuracy < 0.7)
{
return "Calibration Quality: GOOD";
}

if (accuracy < 1)
{
return "Calibration Quality: MODERATE";
}

if (accuracy < 1.5)
{
return "Calibration Quality: POOR";
}

return "Calibration Quality: REDO";
}

public void OnConnectionStateChanged(bool IsActivated)
{
// The connection state listener detects when the connection to the EyeTribe server changes
if (btnAction.Dispatcher.Thread != Thread.CurrentThread)
{
this.Dispatcher.BeginInvoke(new MethodInvoker(() => OnConnectionStateChanged(IsActivated)));
return;
}
if (!IsActivated)
{
GazeManager.Instance.Deactivate();
RatingText.Text = "";
btnAction.Content = "Re-Connect";
}
}
}
}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ To build, open solution file in compliant [Visual Studio](http://www.visualstudi

Changelog
----
0.9.40 (2014-07-30)

- Stability improvements for the calibration runner
- Updated C# SDK
- Minor performance improvements

0.9.35 (2014-05-20)

- Updated license
- Calibration result null check in the calibration sample
- Updated C# SDK
- Fixed stability issue in the calibration runner
- Calibration aborts if the Tracker is disconnected
- minor performance improvements
- Minor performance improvements

0.9.27 (2014-02-12)

Expand Down
Loading

0 comments on commit 886057e

Please sign in to comment.