Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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.");
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
0
        private static bool LoadDeviceDistance(string settingsFilename, out int value)
        {
            value = 0;

            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_GetValueInt(settingsId, QL_SETTINGS.QL_SETTING_DEVICE_DISTANCE, out value);
            if (error != QLError.QL_ERROR_OK && error != QLError.QL_ERROR_INVALID_PATH && error != QLError.QL_ERROR_NOT_FOUND)
            {
                Console.WriteLine("QLSettings_GetValueInt() returned {0}.", error.ToString());
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
                    }
                }
            }
Exemplo n.º 10
0
        /// <summary>
        /// Detects all eye tracker devices on the system and lists them on the console, then prompts the
        /// user to choose a device.  A <see cref="T:QuickLink2DotNetHelper.QLHelper" /> object is then constructed using the
        /// chosen device.  If only one device is found, that device is used without prompting the user
        /// for input.  If an error is encountered, details are output to the console.
        /// </summary>
        /// <seealso cref="FromDeviceId" />
        /// <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 ChooseDevice()
        {
            int[] deviceIds;

            QLError error = DeviceEnumerate(out deviceIds);

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

            PrintListOfDeviceInfo(deviceIds);

            if (deviceIds == null || deviceIds.Length == 0)
            {
                return(null);
            }

            if (deviceIds.Length == 1)
            {
                Console.WriteLine("Using detected device with ID: {0}.\n", deviceIds[0]);
                return(FromDeviceId(deviceIds[0]));
            }

            int deviceId = -1;

            do
            {
                Console.Write("Enter the ID of the device to use (or enter q to quit): ");
                string answer = Console.ReadLine();

                if (answer.ToLower().Equals("q"))
                {
                    break;
                }
                else
                {
                    try
                    {
                        deviceId = Int32.Parse(answer);
                    }
                    catch (ArgumentException) { continue; }
                    catch (FormatException) { continue; }
                    catch (OverflowException) { continue; }
                }

                for (int i = 0; i < deviceIds.Length; i++)
                {
                    if (deviceId == deviceIds[i])
                    {
                        Console.WriteLine("Using detected device with ID: {0}.\n", deviceId);
                        return(FromDeviceId(deviceId));
                    }
                }
            } while (deviceId < 0);

            if (deviceId > 0)
            {
                return(FromDeviceId(deviceId));
            }

            return(null);
        }
Exemplo n.º 11
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);
                }
            }
        }
Exemplo n.º 12
0
            /// <summary>
            /// Performs the calibration sequence, displaying 5, 9, or 16-targets as specified in the
            /// form's constructor.  After each target is displayed, but before each target is
            /// calibrated, the method pauses for <see cref="DelayTimePerTarget"/> milliseconds in order
            /// to give the user time to adjust to the newly displayed target.  After the initial
            /// sequence is complete, this method retries the calibration of any targets whose left-right
            /// averaged score exceeds the value in <see cref="MaximumScore"/> up to
            /// <see cref="MaximumRetries"/> times.  The fields <see cref="CalibrationId"/>,
            /// <see cref="Targets"/>, <see cref="LeftScores"/>, and <see cref="RightScores"/> will be
            /// set to valid values when this method returns successfully.
            /// </summary>
            /// <returns>
            /// True on success (even if some targets exceed <see cref="MaximumScore" />, false on
            /// failure.
            /// </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 bool Calibrate()
            {
                // Create a new calibration container.
                QLError error = QuickLink2API.QLCalibration_Create(0, out this._calibrationId);

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

                error = QuickLink2API.QLCalibration_Initialize(this._deviceId, this._calibrationId, this._calibrationType);
                if (error != QLError.QL_ERROR_OK)
                {
                    Console.WriteLine("QLCalibration_Initialize() returned {0}.", error.ToString());
                    return(false);
                }

                int numTargets = this._numberOfTargets;

                error = QuickLink2API.QLCalibration_GetTargets(this._calibrationId, ref numTargets, this.Targets);
                if (error != QLError.QL_ERROR_OK)
                {
                    Console.WriteLine("QLCalibration_GetTargets() returned {0}.", error.ToString());
                    return(false);
                }
                if (numTargets != this._numberOfTargets)
                {
                    Console.WriteLine("QLCalibration_GetTargets() returned an unexpected number of targets.  Expected {0}; got {1}.", this._numberOfTargets, numTargets);
                    return(false);
                }

                //this.TopMost = true;
                //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                //this.Show();

                // For each target, draw it and then perform calibration.
                for (int i = 0; i < numTargets; i++)
                {
                    if (!CalibrateTarget(i))
                    {
                        return(false);
                    }
                }

                if (!UpdateScores())
                {
                    return(false);
                }

                if (this._maximumScore > 0)
                {
                    if (!ImproveCalibration())
                    {
                        return(false);
                    }
                }

                //this.TopMost = false;
                //this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                this.Hide();

                return(true);
            }
Exemplo n.º 13
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);
            }
Exemplo n.º 14
0
            private bool CalibrateTarget(int targetIndex)
            {
                if (!this.Visible)
                {
                    this.Show();
                }

                if (!this.TopMost)
                {
                    this.TopMost = true;
                }

                if (this.WindowState != FormWindowState.Maximized)
                {
                    this.WindowState = FormWindowState.Maximized;
                }

                if (ActiveForm != this)
                {
                    this.Activate();
                }

                this._targetX = (int)Math.Truncate((this.Targets[targetIndex].x / 100f) * (float)this.Size.Width);
                this._targetY = (int)Math.Truncate((this.Targets[targetIndex].y / 100f) * (float)this.Size.Height);

                bool success = false;

                while (true)
                {
                    // Tell the picture box to draw the new target, and wait for it
                    // to wake us.
                    this._drawTarget = true;
                    this._calibrationPictureBox.Refresh();
                    lock (this._drawTargetLock)
                    {
                        while (this._drawTarget)
                        {
                            Monitor.Wait(this._drawTargetLock);
                        }
                    }

                    // Give the user time to look at the target.
                    Thread.Sleep(_delayTimePerTarget);

                    // Calibrate the target.
                    QLError error = QuickLink2API.QLCalibration_Calibrate(this._calibrationId, this.Targets[targetIndex].targetId, this._targetDuration, true);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLCalibration_Calibrate() returned {0}.", error.ToString());
                        success = false;
                        break;
                    }

                    // Get the status of the last target.
                    QLCalibrationStatus status;
                    error = QuickLink2API.QLCalibration_GetStatus(this._calibrationId, this.Targets[targetIndex].targetId, out status);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLCalibration_GetStatus() returned {0}.", error.ToString());
                        success = false;
                        break;
                    }

                    if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_NO_LEFT_DATA)
                    {
                        DialogResult result = MessageBox.Show("Left eye not found.  Retry?", "Left Eye Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result != DialogResult.Yes)
                        {
                            Console.WriteLine("User cancelled.");
                            success = false;
                            break;
                        }
                    }
                    else if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_NO_RIGHT_DATA)
                    {
                        DialogResult result = MessageBox.Show("Right eye not found.  Retry?", "Right Eye Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result != DialogResult.Yes)
                        {
                            Console.WriteLine("User cancelled.");
                            success = false;
                            break;
                        }
                    }
                    else if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_NO_DATA)
                    {
                        DialogResult result = MessageBox.Show("Neither eye found.  Retry?", "Neither Eye Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result != DialogResult.Yes)
                        {
                            Console.WriteLine("User cancelled.");
                            success = false;
                            break;
                        }
                    }
                    else if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_OK)
                    {
                        success = true;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Calibration failed!");
                        success = false;
                        break;
                    }
                }

                return(success);
            }
Exemplo n.º 15
0
        private static bool Calibrate(int deviceId, string calibrationFilename, int deviceDistance, QLCalibrationType calibrationType, int targetDuration)
        {
            // Start the device.
            QLError error = QuickLink2API.QLDevice_Start(deviceId);

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

            bool calibrationSuccessful = false;

            using (CalibrationForm calibrationForm = new CalibrationForm(deviceId, calibrationType, targetDuration))
            {
                if (calibrationForm.Calibrate())
                {
                    // Calculate the total average score.
                    float avg = 0;
                    for (int i = 0; i < calibrationForm.LeftScores.Length; i++)
                    {
                        avg += calibrationForm.LeftScores[i].score;
                        avg += calibrationForm.RightScores[i].score;
                    }
                    avg /= (float)calibrationForm.LeftScores.Length * 2f;

                    Console.WriteLine("Calibration Score: {0}.", avg);

                    while (true)
                    {
                        // Flush the input buffer.
                        while (Console.KeyAvailable)
                        {
                            Console.ReadKey(true);
                        }

                        if (!PromptToApplyCalibration())
                        {
                            Console.WriteLine("Not applying calibration.");
                            calibrationSuccessful = false;
                            break;
                        }
                        else
                        {
                            error = QuickLink2API.QLCalibration_Finalize(calibrationForm.CalibrationId);
                            if (error != QLError.QL_ERROR_OK)
                            {
                                Console.WriteLine("QLCalibration_Finalize() returned {0}.", error.ToString());
                                calibrationSuccessful = false;
                                break;
                            }

                            error = QuickLink2API.QLDevice_ApplyCalibration(deviceId, calibrationForm.CalibrationId);
                            if (error != QLError.QL_ERROR_OK)
                            {
                                Console.WriteLine("QLCalibration_ApplyCalibration() returned {0}", error.ToString());
                                calibrationSuccessful = false;
                                break;
                            }

                            error = QuickLink2API.QLCalibration_Save(calibrationFilename, calibrationForm.CalibrationId);
                            if (error != QLError.QL_ERROR_OK)
                            {
                                Console.WriteLine("QLCalibration_Save() returned {0}", error.ToString());
                                calibrationSuccessful = false;
                                break;
                            }

                            calibrationSuccessful = true;
                            break;
                        }
                    }
                }
            }

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

            return(calibrationSuccessful);
        }