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); }
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); }
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); }
/// <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); }