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);
        }
Exemplo n.º 2
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);
        }