Tobii Pro SDK C API
calibration_data.c
#include <stdio.h>
#include <stdlib.h>
void calibration_data_example(TobiiResearchEyeTracker* eyetracker) {
/* Save the calibration to file. */
char* filename = "saved_calibration.bin";
char* serial_number;
FILE* f = fopen(filename, "wb");
TobiiResearchCalibrationData* calibration_data = NULL;
TobiiResearchStatus status = tobii_research_retrieve_calibration_data(eyetracker, &calibration_data);
if (status != TOBII_RESEARCH_STATUS_OK)
return;
tobii_research_get_serial_number(eyetracker, &serial_number);
/* None is returned on empty calibration. */
if (calibration_data->size != 0) {
printf("Saving calibration to file for eye tracker with serial number %s.\n", serial_number);
fwrite(calibration_data->data, calibration_data->size, 1, f);
} else {
printf("No calibration available for eye tracker with serial number %s.\n", serial_number);
}
fclose(f);
{
/* Read the calibration from file. */
FILE *calibration_file = fopen(filename, "rb" );
size_t file_size;
if( !calibration_file ) {
printf("Calibration file not found!\n");
return;
}
fseek(calibration_file, 0, SEEK_END);
file_size = (size_t)ftell(calibration_file);
rewind(calibration_file);
if(file_size <= 0) {
printf("Calibration file is empty!\n");
return;
};
TobiiResearchCalibrationData calibration_data_to_write;
calibration_data_to_write.data = malloc(file_size);
calibration_data_to_write.size = file_size;
file_size = fread(calibration_data_to_write.data, calibration_data_to_write.size, 1, calibration_file);
/* Don't apply empty calibrations. */
if (file_size > 0) {
printf("Applying calibration on eye tracker with serial number %s.\n", serial_number);
tobii_research_apply_calibration_data(eyetracker, &calibration_data_to_write);
}
free(calibration_data_to_write.data);
fclose(calibration_file);
}
}