Ejemplo n.º 1
0
        public void Test_0490_QLDevice_ImportSettings_UsingDeviceGroupId()
        {
            // Note: This only uses the initially chosen device.

            string setting = QL_SETTINGS.QL_SETTING_DEVICE_IMAGE_PROCESSING_EYES_TO_FIND;

            int     deviceGroupId;
            QLError error = QuickLink2API.QLDeviceGroup_Create(out deviceGroupId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.Greater(deviceGroupId, 0);

            error = QuickLink2API.QLDeviceGroup_AddDevice(deviceGroupId, Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            int outSettingsID;

            error = QuickLink2API.QLSettings_Create(0, out outSettingsID);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLSettings_AddSetting(outSettingsID, setting);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_ExportSettings(Test_SetUp.Helper.DeviceId, outSettingsID);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            int outSettingValue;

            error = QuickLink2API.QLSettings_GetValueInt(outSettingsID, setting, out outSettingValue);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            int originalSettingValue = outSettingValue;

            int inSettingsID;

            error = QuickLink2API.QLSettings_Create(0, out inSettingsID);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            QLDeviceEyesToUse inSettingValue = ((QLDeviceEyesToUse)outSettingValue != QLDeviceEyesToUse.QL_DEVICE_EYES_TO_USE_LEFT) ? QLDeviceEyesToUse.QL_DEVICE_EYES_TO_USE_LEFT : QLDeviceEyesToUse.QL_DEVICE_EYES_TO_USE_RIGHT;

            error = QuickLink2API.QLSettings_SetValueInt(inSettingsID, setting, (int)inSettingValue);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_ImportSettings(deviceGroupId, inSettingsID);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_ExportSettings(Test_SetUp.Helper.DeviceId, outSettingsID);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLSettings_GetValueInt(outSettingsID, setting, out outSettingValue);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            Assert.AreEqual(inSettingValue, (QLDeviceEyesToUse)outSettingValue);

            error = QuickLink2API.QLSettings_SetValueInt(inSettingsID, setting, originalSettingValue);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_ImportSettings(deviceGroupId, inSettingsID);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 2
0
        public void Test_0470_QLDeviceGroup_GetFrame()
        {
            // Note: This only uses the initially chosen device.

            // Note: This could be much more robust (i.e., by checking the data
            // in the received frame for correctness).

            int     deviceGroupId;
            QLError error = QuickLink2API.QLDeviceGroup_Create(out deviceGroupId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.Greater(deviceGroupId, 0);

            error = QuickLink2API.QLDeviceGroup_AddDevice(deviceGroupId, Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_Start(deviceGroupId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            int numFrames = 1;

            QLFrameData[] frameDataArray = new QLFrameData[numFrames];
            frameDataArray[0] = new QLFrameData();
            error             = QuickLink2API.QLDeviceGroup_GetFrame(deviceGroupId, 2000, ref numFrames, frameDataArray);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(1, numFrames);

            Assert.AreEqual(Test_SetUp.Helper.DeviceId, frameDataArray[0].DeviceId);

            error = QuickLink2API.QLDevice_Stop(deviceGroupId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
        public void Test_0330_QLCalibration_Save_Load()
        {
            int     calibrationId;
            QLError error = QuickLink2API.QLCalibration_Create(0, out calibrationId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            // Try to load non-existent calibration data into the container.
            // Check that the correct error is returned.
            string fakeCalibrationFilename = System.IO.Path.Combine(QLHelper.ConfigDirectory, "qlcalibrationFake.qlc");

            error = QuickLink2API.QLCalibration_Load(fakeCalibrationFilename, ref calibrationId);
            Assert.AreNotEqual(QLError.QL_ERROR_OK, error);

            // Try to load a previously saved calibration file into the container.
            // Check that the correct error is returned.
            error = QuickLink2API.QLCalibration_Load(Test_SetUp.Helper.CalibrationFilename, ref calibrationId);
            Assert.AreNotEqual(QLError.QL_ERROR_INVALID_PATH, error, "Calibration file not found.  You may need to run the SetupDevice example first.");
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            // Save the calibration to a different path and check that the two files are the same
            string duplicateCalibrationFilename = System.IO.Path.Combine(QLHelper.ConfigDirectory, "qlcalibrationDuplicate.qlc");

            if (System.IO.File.Exists(duplicateCalibrationFilename))
            {
                System.IO.File.Delete(duplicateCalibrationFilename);
            }
            error = QuickLink2API.QLCalibration_Save(duplicateCalibrationFilename, calibrationId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            string calibration1 = System.IO.File.ReadAllText(Test_SetUp.Helper.CalibrationFilename);
            string calibration2 = System.IO.File.ReadAllText(duplicateCalibrationFilename);

            Assert.AreEqual(calibration1, calibration2);
            System.IO.File.Delete(duplicateCalibrationFilename);
        }
Ejemplo n.º 4
0
        private static bool ApplyDeviceDistance(int deviceId, int value)
        {
            int     settingsId;
            QLError error = QuickLink2API.QLSettings_Create(0, out settingsId);

            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_Create() returned {0}.", error.ToString());
                return(false);
            }

            error = QuickLink2API.QLSettings_SetValueInt(settingsId, QL_SETTINGS.QL_SETTING_DEVICE_DISTANCE, value);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_SetValueInt() returned {0}.", error.ToString());
                return(false);
            }

            error = QuickLink2API.QLDevice_ImportSettings(deviceId, settingsId);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLDevice_ImportSettings() returned {0}.", error.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public void Test_0450_QLDevice_Start_Stop_UsingDeviceGroupId()
        {
            // Note: This only uses the initially chosen device.

            int     deviceGroupId;
            QLError error = QuickLink2API.QLDeviceGroup_Create(out deviceGroupId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.Greater(deviceGroupId, 0);

            error = QuickLink2API.QLDeviceGroup_AddDevice(deviceGroupId, Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_Start(deviceGroupId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            QLDeviceStatus status;

            error = QuickLink2API.QLDevice_GetStatus(Test_SetUp.Helper.DeviceId, out status);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(QLDeviceStatus.QL_DEVICE_STATUS_STARTED, status);

            error = QuickLink2API.QLDevice_Stop(deviceGroupId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_GetStatus(Test_SetUp.Helper.DeviceId, out status);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(QLDeviceStatus.QL_DEVICE_STATUS_STOPPED, status);
        }
Ejemplo n.º 6
0
        private static bool SaveDeviceDistance(string settingsFilename, int value)
        {
            int     settingsId = 0;
            QLError error      = QuickLink2API.QLSettings_Load(settingsFilename, ref settingsId);

            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_Load() returned {0}.", error.ToString());
                return(false);
            }

            error = QuickLink2API.QLSettings_SetValueInt(settingsId, QL_SETTINGS.QL_SETTING_DEVICE_DISTANCE, value);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_SetValueInt() returned {0}.", error.ToString());
                return(false);
            }

            error = QuickLink2API.QLSettings_Save(settingsFilename, settingsId);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_Save() returned {0}.", error.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Given an array populated with device IDs, print the ID number, model, and serial number of
        /// each device on the console--one device per line.  If an error is encountered, details are
        /// output to the console.  This can be used to show a list of devices so that the user may
        /// choose a specific one.
        /// </summary>
        /// <param name="deviceIds">
        /// An array containing the ID numbers of the devices to print information about.  These ID
        /// numbers are obtained by calling the function
        /// <see cref="QuickLink2DotNet.QuickLink2API.QLDevice_Enumerate" />.
        /// </param>
        /// <exception cref="DllNotFoundException">
        /// The QuickLink2 DLLs ("QuickLink2.dll," "PGRFlyCapture.dll," and "SMX11MX.dll") must be placed
        /// in the same directory as your program's binary executable; otherwise, this exception will be
        /// thrown.
        /// </exception>
        public static void PrintListOfDeviceInfo(int[] deviceIds)
        {
            if (deviceIds == null || deviceIds.Length == 0)
            {
                Console.WriteLine("No devices detected.");
            }

            Console.WriteLine("Detected {0} devices:{1}", deviceIds.Length, Environment.NewLine);

            for (int i = 0; i < deviceIds.Length; i++)
            {
                int deviceId = deviceIds[i];

                QLDeviceInfo info;
                QLError      error = QuickLink2API.QLDevice_GetInfo(deviceId, out info);
                if (error != QLError.QL_ERROR_OK)
                {
                    Console.WriteLine("  ID: {0}; QLDevice_GetInfo() returned {1}{2}", deviceId, error.ToString(), Environment.NewLine);
                }
                else
                {
                    Console.WriteLine("  ID: {0}; Model: {1}; Serial: {2}{3}", deviceId, info.modelName, info.serialNumber, Environment.NewLine);
                }
            }
        }
        public void Test_0110_QLDevice_GetStatus()
        {
            QLDeviceStatus status;
            QLError        error = QuickLink2API.QLDevice_GetStatus(Test_SetUp.Helper.DeviceId, out status);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
        public void Test_0300_QLCalibration_Create()
        {
            int     calibrationId;
            QLError error = QuickLink2API.QLCalibration_Create(0, out calibrationId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 10
0
        private bool ShowVideoStream()
        {
            // Start the device.
            QLError error = QuickLink2API.QLDevice_Start(this.DeviceId);

            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLDevice_Start() returned {0}.", error.ToString());
                return(false);
            }

            using (QLHelper.VideoForm videoForm = new QLHelper.VideoForm(this))
            {
                videoForm.ShowDialog();
            }

            error = QuickLink2API.QLDevice_Stop(this.DeviceId);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLDevice_Stop() returned {0}.", error.ToString());
                return(false);
            }

            return(true);
        }
        public void Test_0350_QLCalibration_GetTargets()
        {
            int     calibrationId;
            QLError error = QuickLink2API.QLCalibration_Create(0, out calibrationId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_Start(Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLCalibration_Initialize(Test_SetUp.Helper.DeviceId, calibrationId, QLCalibrationType.QL_CALIBRATION_TYPE_16);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            int numTargets = 16;

            QLCalibrationTarget[] targets = new QLCalibrationTarget[numTargets];
            error = QuickLink2API.QLCalibration_GetTargets(calibrationId, ref numTargets, targets);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(16, numTargets);

            error = QuickLink2API.QLCalibration_Cancel(calibrationId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_Stop(Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get the deviceIDs of every eye tracker device detected on the system.  When the method
        /// returns successfully, the <paramref name="deviceIds"/> array will be sized exactly to contain
        /// the number of devices detected.  So, for example, if there is one device detected then the
        /// array will have length 1; if 10 devices are detected then the array will have length 10; if
        /// no devices are detected then the array will have length 0.
        /// </summary>
        /// <param name="deviceIds">
        /// A reference to an uninitialized integer array which will contain the ID of every device
        /// detected on the system upon the method's successful return.
        /// </param>
        /// <returns>
        /// The success of the method.  Returns <see cref="QLError.QL_ERROR_OK"/> on success.
        /// </returns>
        /// <exception cref="DllNotFoundException">
        /// The QuickLink2 DLLs ("QuickLink2.dll," "PGRFlyCapture.dll," and "SMX11MX.dll") must be placed
        /// in the same directory as your program's binary executable; otherwise, this exception will be
        /// thrown.
        /// </exception>
        public static QLError DeviceEnumerate(out int[] deviceIds)
        {
            int numDevices = 1;

            deviceIds = new int[numDevices];

            QLError error = QuickLink2API.QLDevice_Enumerate(ref numDevices, deviceIds);

            if (error == QLError.QL_ERROR_BUFFER_TOO_SMALL)
            {
                // Array too small.  Try again with a properly sized array.
                deviceIds = new int[numDevices];
                error     = QuickLink2API.QLDevice_Enumerate(ref numDevices, deviceIds);
            }

            if (numDevices == 0)
            {
                deviceIds = new int[0];
                return(error);
            }

            for (int i = 0; i < numDevices; i++)
            {
                if (deviceIds[i] <= 0)
                {
                    Console.WriteLine("Illegal device ID detected in data returned from QLDevice_Enumerate()!  Position {0} contains ID {1}.", i, deviceIds[i]);
                    return(QLError.QL_ERROR_INTERNAL_ERROR);
                }
            }

            return(error);
        }
Ejemplo n.º 13
0
        public void Test_0440_QLDeviceGroup_RemoveDevice()
        {
            // Note: This only uses the initially chosen device.

            int     deviceGroupId;
            QLError error = QuickLink2API.QLDeviceGroup_Create(out deviceGroupId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.Greater(deviceGroupId, 0);

            error = QuickLink2API.QLDeviceGroup_AddDevice(deviceGroupId, Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            int numDevices = 1;

            int[] deviceIds = new int[numDevices];
            error = QuickLink2API.QLDeviceGroup_Enumerate(deviceGroupId, ref numDevices, deviceIds);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(1, numDevices);
            Assert.AreEqual(Test_SetUp.Helper.DeviceId, deviceIds[0]);

            QLFrameData frameData = new QLFrameData();

            error = QuickLink2API.QLDevice_GetFrame(Test_SetUp.Helper.DeviceId, 2000, ref frameData);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDeviceGroup_RemoveDevice(deviceGroupId, Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDeviceGroup_Enumerate(deviceGroupId, ref numDevices, deviceIds);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(0, numDevices);
        }
Ejemplo n.º 14
0
        public void Test_0410_QLDeviceGroup_Create()
        {
            int     deviceGroupId;
            QLError error = QuickLink2API.QLDeviceGroup_Create(out deviceGroupId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.Greater(deviceGroupId, 0);
        }
Ejemplo n.º 15
0
        public static bool AutoCalibrate(int deviceId, QLCalibrationType calibrationType, ref int calibrationId)
        {
            QLError qlerror = QLError.QL_ERROR_OK;

            //Initialize the calibration using the inputted data.
            qlerror = QuickLink2API.QLCalibration_Initialize(deviceId, calibrationId, calibrationType);

            // If the calibrationId was not valid then create a new calibration container and use it.
            if (qlerror == QLError.QL_ERROR_INVALID_CALIBRATION_ID)
            {
                QuickLink2API.QLCalibration_Create(0, out calibrationId);
                qlerror = QuickLink2API.QLCalibration_Initialize(deviceId, calibrationId, calibrationType);
            }

            // If the initialization failed then print an error and return false.
            if (qlerror == QLError.QL_ERROR_INVALID_DEVICE_ID)
            {
                System.Console.WriteLine("QLCalibration_Initialize() failed with error code {0}.", qlerror);
                return(false);
            }

            //Create a buffer for the targets. This just needs to be large enough to hold the targets.
            const int bufferSize = 20;
            int       numTargets = bufferSize;

            QLCalibrationTarget[] targets = new QLCalibrationTarget[bufferSize];

            //Get the targets.  After the call, numTargets will contain the number of actual targets.
            qlerror = QuickLink2API.QLCalibration_GetTargets(calibrationId, ref numTargets, targets);

            // If the buffer was not large enough then print an error and return false.
            if (qlerror == QLError.QL_ERROR_BUFFER_TOO_SMALL)
            {
                System.Console.WriteLine("The target buffer is too small.");
                return(false);
            }

            // Create a window for doing the calibration.
            CalibrationForm calibrationForm = new CalibrationForm();

            calibrationForm.PerformCalibration(calibrationId, numTargets, targets);

            System.Console.WriteLine("Do you want to improve the calibration? y/n");
            while (Console.ReadKey(true).Key == ConsoleKey.Y)
            {
                calibrationForm.ImproveCalibration(calibrationId, numTargets, targets);
                System.Console.WriteLine("Do you want to improve the calibration? y/n");
            }

            QuickLink2API.QLCalibration_Finalize(calibrationId);

            return(true);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Construct a <see cref="T:QuickLink2DotNetHelper.QLHelper" /> object using a specified device.  If an error is
        /// encountered, details are output to the console.
        /// </summary>
        /// <seealso cref="ChooseDevice" />
        /// <param name="deviceId">
        /// The ID for the device to use when creating the <see cref="T:QuickLink2DotNetHelper.QLHelper" /> object.  This ID is
        /// obtained by calling the function
        /// <see cref="QuickLink2DotNet.QuickLink2API.QLDevice_Enumerate" />.
        /// </param>
        /// <returns>
        /// A <see cref="T:QuickLink2DotNetHelper.QLHelper" /> object constructed using the chosen device.  Returns null if an
        /// error occurs, no devices are found, or the user opts to quit.
        /// </returns>
        /// <exception cref="DllNotFoundException">
        /// The QuickLink2 DLLs ("QuickLink2.dll," "PGRFlyCapture.dll," and "SMX11MX.dll") must be placed
        /// in the same directory as your program's binary executable; otherwise, this exception will be
        /// thrown.
        /// </exception>
        public static QLHelper FromDeviceId(int deviceId)
        {
            QLDeviceInfo info;
            QLError      error = QuickLink2API.QLDevice_GetInfo(deviceId, out info);

            if (error != QLError.QL_ERROR_OK)
            {
                return(null);
            }

            return(new QLHelper(deviceId, info));
        }
Ejemplo n.º 17
0
        public void Test_0420_QLDeviceGroup_AddDevice()
        {
            // Note: This only uses the initially chosen device.

            int     deviceGroupId;
            QLError error = QuickLink2API.QLDeviceGroup_Create(out deviceGroupId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.Greater(deviceGroupId, 0);

            error = QuickLink2API.QLDeviceGroup_AddDevice(deviceGroupId, Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 18
0
        public void Test_0010_QLAPI_GetVersion()
        {
            string expectedVersionString = "2.5.1.0";

            int buffSize = expectedVersionString.Length + 1; // +1 for the null that terminates the string.

            System.Text.StringBuilder version = new System.Text.StringBuilder(buffSize);

            QLError error = QuickLink2API.QLAPI_GetVersion(buffSize, version);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);
            Assert.AreEqual(version.ToString(), expectedVersionString);
        }
        public void Test_0360_QLDevice_ApplyCalibration()
        {
            int     calibrationId;
            QLError error = QuickLink2API.QLCalibration_Create(0, out calibrationId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLCalibration_Load(Test_SetUp.Helper.CalibrationFilename, ref calibrationId);
            Assert.AreNotEqual(QLError.QL_ERROR_INVALID_PATH, error, "Calibration file not found.  You may need to run the SetupDevice example first.");
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_ApplyCalibration(Test_SetUp.Helper.DeviceId, calibrationId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            int     deviceId = Initialize.QL2Initialize(filename_Password);
            QLError error    = QuickLink2API.QLDevice_Start(deviceId);

            if (error != QLError.QL_ERROR_OK)
            {
                System.Console.WriteLine("Device not started successfully!");
                System.Console.ReadLine();
                return;
            }

            System.Console.WriteLine("Press any key to begin calibration.");
            Console.ReadKey(true);

            //Calibrate the device
            int calibrationId = 0;

            if (Calibrate.AutoCalibrate(deviceId, QLCalibrationType.QL_CALIBRATION_TYPE_16, ref calibrationId))
            {
                System.Console.WriteLine("\n\nPress \'q\' to quit. \n");

                // If the calibration was successful then apply the calibration to the device.
                QuickLink2API.QLDevice_ApplyCalibration(deviceId, calibrationId);

                // Display the gaze information until the user quits.
                QLFrameData frameData = new QLFrameData();
                while ((!Console.KeyAvailable) || (Console.ReadKey(true).Key != ConsoleKey.Q))
                {
                    QuickLink2API.QLDevice_GetFrame(deviceId, 10000, ref frameData);
                    if (frameData.WeightedGazePoint.Valid)
                    {
                        System.Console.Write("\rX:{0:F}    Y:{1:F}", frameData.WeightedGazePoint.x,
                                             frameData.WeightedGazePoint.y);
                    }
                }
            }
            else
            {
                System.Console.WriteLine("The calibration did not finish successfully!");
                System.Console.Read();
                QuickLink2API.QLDevice_Stop(deviceId);
                return;
            }

            // Stop the device.
            QuickLink2API.QLDevice_Stop(deviceId);

            return;
        }
Ejemplo n.º 21
0
        private static bool SavePassword(string settingsFilename, string password)
        {
            // Read the settings out the file (if it exists) into a new setting container.
            int     settingsId = 0;
            QLError error      = QuickLink2API.QLSettings_Load(settingsFilename, ref settingsId);

            if (error == QLError.QL_ERROR_INVALID_PATH || error == QLError.QL_ERROR_INTERNAL_ERROR)
            {
                // The file does not exist to load from; create a new settings container.
                error = QuickLink2API.QLSettings_Create(-1, out settingsId);
                if (error != QLError.QL_ERROR_OK)
                {
                    Console.WriteLine("QLSettings_Create() returned {0}.", error.ToString());
                    return(false);
                }
            }
            else if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_Load() returned {0}.", error.ToString());
                return(false);
            }

            // Remove the password if it already exists in the container.
            error = QuickLink2API.QLSettings_RemoveSetting(settingsId, QLHelper._passwordSettingName);
            if (error != QLError.QL_ERROR_OK && error != QLError.QL_ERROR_NOT_FOUND)
            {
                Console.WriteLine("QLSettings_RemoveSetting() returned {0}.", error.ToString());
                return(false);
            }

            // Add the password to the container.
            error = QuickLink2API.QLSettings_SetValueString(settingsId, QLHelper._passwordSettingName, password);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_SetValueString() returned {0}.", error.ToString());
                return(false);
            }

            // Save the settings container to the file.
            error = QuickLink2API.QLSettings_Save(settingsFilename, settingsId);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_Save() returned {0}.", error.ToString());
                return(false);
            }

            return(true);
        }
        public void Test_0310_QLCalibration_Initialize()
        {
            int     calibrationId;
            QLError error = QuickLink2API.QLCalibration_Create(0, out calibrationId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_Start(Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLCalibration_Initialize(Test_SetUp.Helper.DeviceId, calibrationId, QLCalibrationType.QL_CALIBRATION_TYPE_16);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLDevice_Stop(Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 23
0
        private static void DoTask()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            QLHelper helper = QLHelper.ChooseDevice();

            if (helper == null)
            {
                return;
            }

            if (!helper.SetupPassword())
            {
                return;
            }

            if (!helper.SetupCalibration())
            {
                return;
            }

            // Start the device.
            QLError error = QuickLink2API.QLDevice_Start(helper.DeviceId);

            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLDevice_Start() returned {0} for device {1}.", error.ToString(), helper.DeviceId);
                return;
            }
            Console.WriteLine("Device has been started.");
            Console.WriteLine();

            using (GazeForm mainForm = new GazeForm(helper.DeviceId))
            {
                mainForm.ShowDialog();
            }

            // Stop the device.
            error = QuickLink2API.QLDevice_Stop(helper.DeviceId);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLDevice_Stop() returned {0} for device {1}.", error.ToString(), helper.DeviceId);
                return;
            }
            Console.WriteLine("Stopped Device.");
        }
        public void Test_0340_QLCalibration_AddBias()
        {
            int     calibrationId;
            QLError error = QuickLink2API.QLCalibration_Create(0, out calibrationId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLCalibration_Load(Test_SetUp.Helper.CalibrationFilename, ref calibrationId);
            Assert.AreNotEqual(QLError.QL_ERROR_INVALID_PATH, error, "Calibration file not found.  You may need to run the SetupDevice example first.");
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLCalibration_AddBias(calibrationId, QLEyeType.QL_EYE_TYPE_LEFT, .2f, .2f);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            error = QuickLink2API.QLCalibration_AddBias(calibrationId, QLEyeType.QL_EYE_TYPE_RIGHT, .2f, .2f);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 25
0
        private static string LoadPassword(string settingsFilename)
        {
            if (!File.Exists(settingsFilename))
            {
                //Console.WriteLine("Cannot load device password from settings file '{0}' because it does not exist.", settingsFilename);
                return(null);
            }

            // Read the settings out of a file into a new setting container.
            int     settingsId = -1;
            QLError error      = QuickLink2API.QLSettings_Load(settingsFilename, ref settingsId);

            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_Load() returned {0}.", error.ToString());
                return(null);
            }

            // Check for the device password already in settings and fetch its size.
            int passwordSettingSize;

            error = QuickLink2API.QLSettings_GetValueStringSize(settingsId, QLHelper._passwordSettingName, out passwordSettingSize);
            if (error == QLError.QL_ERROR_NOT_FOUND)
            {
                Console.WriteLine("The device password does not exist in the specified settings file.");
                return(null);
            }
            else if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_GetValueStringSize() returned {0}.", error.ToString());
                return(null);
            }

            // Load the password from the settings file.
            System.Text.StringBuilder password = new System.Text.StringBuilder(passwordSettingSize);
            error = QuickLink2API.QLSettings_GetValueString(settingsId, QLHelper._passwordSettingName, passwordSettingSize, password);
            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLSettings_GetValueString() returned {0}.", error.ToString());
                return(null);
            }

            // Return the password.
            return(password.ToString());
        }
Ejemplo n.º 26
0
        bool IGazeDataProvider.Initialize()
        {
            deviceId = Initialize.QL2Initialize("QL2Passwords.txt");
            QLError error = QuickLink2API.QLDevice_Start(deviceId);

            if (error != QLError.QL_ERROR_OK)
            {
                return(false);
            }

            IntPtr calibrationId = IntPtr.Zero;

            //Calibrate.AutoCalibrate(deviceId, QLCalibrationType.QL_CALIBRATION_TYPE_16, ref calibrationId);
            //QuickLink2API.QLDevice_ApplyCalibration(deviceId, calibrationId);

            _timer = new DispatcherTimer(TimeSpan.FromSeconds(1.0 / 15), DispatcherPriority.Normal, Tick, Dispatcher.CurrentDispatcher);

            return(true);
        }
        public void Test_0130_QLDevice_GetFrame()
        {
            // Note: This could be much more robust (i.e., by checking the data
            // in the received frame for correctness).

            QLError error = QuickLink2API.QLDevice_Start(Test_SetUp.Helper.DeviceId);

            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            QLFrameData frameData = new QLFrameData();

            error = QuickLink2API.QLDevice_GetFrame(Test_SetUp.Helper.DeviceId, 2000, ref frameData);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);

            Assert.AreEqual(Test_SetUp.Helper.DeviceId, frameData.DeviceId);

            error = QuickLink2API.QLDevice_Stop(Test_SetUp.Helper.DeviceId);
            Assert.AreEqual(QLError.QL_ERROR_OK, error);
        }
Ejemplo n.º 28
0
        private static void doTask()
        {
            int[]   deviceIds;
            QLError error = QLHelper.DeviceEnumerate(out deviceIds);

            if (error != QLError.QL_ERROR_OK)
            {
                Console.WriteLine("QLDevice_Enumerate() returned {0}.", error.ToString());
                return;
            }

            QLHelper.PrintListOfDeviceInfo(deviceIds);

            Console.WriteLine();

            for (int i = 0; i < deviceIds.Length; i++)
            {
                QLHelper helper = QLHelper.FromDeviceId(deviceIds[i]);

                if (!helper.SetupPassword())
                {
                    continue;
                }

                error = QuickLink2API.QLDevice_Start(helper.DeviceId);
                if (error != QLError.QL_ERROR_OK)
                {
                    Console.WriteLine("QLDevice_Start() returned {0} for device {1}.", error.ToString(), helper.DeviceId);
                    continue;
                }

                error = QuickLink2API.QLDevice_Stop(helper.DeviceId);
                if (error != QLError.QL_ERROR_OK)
                {
                    Console.WriteLine("QLDevice_Stop() returned {0} for device {1}.", error.ToString(), helper.DeviceId);
                    continue;
                }

                Console.WriteLine("Device {0} stopped.", helper.DeviceId);
            }
        }
Ejemplo n.º 29
0
            private void FrameReader()
            {
                while (true)
                {
                    QLError error = QuickLink2API.QLDevice_GetFrame(this._helper.DeviceId, 2000, ref this._frameData);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLDevice_GetFrame() returned {0}.", error.ToString());
                        continue;
                    }

                    this._latestImage = QLHelper.BitmapFromQLImageData(ref this._frameData.ImageData);

                    this._videoPictureBox.Invalidate();

                    lock (this._frameData_Lock)
                    {
                        Monitor.Wait(this._frameData_Lock);
                    }
                }
            }
Ejemplo n.º 30
0
            private bool UpdateScores()
            {
                // Get scores.
                for (int i = 0; i < this._numberOfTargets; i++)
                {
                    QLError error = QuickLink2API.QLCalibration_GetScoring(this._calibrationId, this.Targets[i].targetId, QLEyeType.QL_EYE_TYPE_LEFT, out this.LeftScores[i]);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLCalibration_GetScoring(left) returned {0}.", error.ToString());
                        return(false);
                    }

                    error = QuickLink2API.QLCalibration_GetScoring(this._calibrationId, this.Targets[i].targetId, QLEyeType.QL_EYE_TYPE_RIGHT, out this.RightScores[i]);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLCalibration_GetScoring(right) returned {0}.", error.ToString());
                        return(false);
                    }
                }

                return(true);
            }