Home Forums Software Development Waiting until Calibration/Calibration testing is done. Reply To: Waiting until Calibration/Calibration testing is done.

#2681
Patrik [Tobii]
Participant

Hello Albin,

There is currently no way of knowing when calibration testing is completed. There are currently discussions about adding a callback in the API for this, so hopefully this feature will be available in a future release.

There is a workaround though, but it is an unsupported hack and not something that should be relied on:

  • You could check for the process Tobii.TestEyeTracking and wait for the process to exit.

It’s not very robust, and you should be aware that the name of this process can change at any time.
You might however use it as a temporary hack until there is something proper in the API.

Below is a simple Console application (C#) that demonstrates the workaround.

using System;
using System.Diagnostics;
using System.Threading;

namespace CalibrationTestingDetection
{
    public class Program
    {
        static void Main(string[] args)
        {
            var handle = new ManualResetEvent(false);

            // Subscribe to CTRL+C
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                handle.Set();                
            };

            Console.WriteLine("Press CTRL+C to quit.\n");

            // Wait for calibration testing to start and finish.
            if (WaitForCalibrationTestingToComplete(handle))
            {
                Console.WriteLine("Successfully detected start and stop.");
            }
            else
            {
                Console.WriteLine("Application aborted (CTRL+C pressed).");
            }

            // Wait for the user to quit.
            Console.WriteLine("\nPress ANY key to quit");
            Console.ReadKey(true);
        }

        public static bool WaitForCalibrationTestingToComplete(WaitHandle handle)
        {
            Console.WriteLine("Waiting for calibration testing to start.");

            while (!handle.WaitOne(0))
            {
                try
                {
                    var processes = Process.GetProcessesByName("Tobii.TestEyeTracking");
                    if (processes.Length > 0)
                    {
                        Console.WriteLine("Calibration testing was started!");

                        var process = processes[0];
                        while (!handle.WaitOne(500))
                        {
                            if (process.HasExited)
                            {
                                Console.WriteLine("Calibration testing completed!");
                                return true;
                            }
                        }
                    }
                }
                finally
                {
                    handle.WaitOne(500);
                }
            }
            return false;
        }
    }
}

Best regards
Patrik