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); }
private void CalibrateTarget(int calibrationId, QLCalibrationTarget target) { QLCalibrationStatus status = QLCalibrationStatus.QL_CALIBRATION_STATUS_OK; do { // Wait for a little bit so show the blanked screen. Thread.Sleep(100); // The target positions are in percentage of the area to be tracked so // we need to scale to the calibration window size. this.x = Convert.ToInt32(Math.Truncate(target.x / 100 * this.Size.Width)); this.y = Convert.ToInt32(Math.Truncate(target.y) / 100 * this.Size.Height); this.drawTarget = true; //Draw a target this.Refresh(); //Wait a little bit so the user can see the target before we calibrate. Thread.Sleep(250); // Calibrate the target for 1500 ms. This can be done two ways; blocking and // non-blocking. For blocking set the block variable to true. for // non-blocking set it to false. bool block = true; QuickLink2API.QLCalibration_Calibrate(calibrationId, target.targetId, 1500, block); // Get the status of the target. QuickLink2API.QLCalibration_GetStatus(calibrationId, target.targetId, out status); } while (status != QLCalibrationStatus.QL_CALIBRATION_STATUS_OK); }
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); }