Tobii Pro SDK C API
gaze_data.c
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#if _WIN32 || _WIN64
#include <windows.h>
static void sleep_ms(int time) {
Sleep(time);
}
#else
#include <unistd.h>
static void sleep_ms(int time) {
usleep(time * 1000);
}
#endif
void gaze_data_callback(TobiiResearchGazeData* gaze_data, void* user_data) {
memcpy(user_data, gaze_data, sizeof(*gaze_data));
}
void gaze_data_example(TobiiResearchEyeTracker* eyetracker) {
char* serial_number;
tobii_research_get_serial_number(eyetracker, &serial_number);
printf("Subscribing to gaze data for eye tracker with serial number %s.\n", serial_number);
TobiiResearchStatus status = tobii_research_subscribe_to_gaze_data(eyetracker, gaze_data_callback, &gaze_data);
if (status != TOBII_RESEARCH_STATUS_OK)
return;
/* Wait while some gaze data is collected. */
sleep_ms(2000);
status = tobii_research_unsubscribe_from_gaze_data(eyetracker, gaze_data_callback);
printf("Unsubscribed from gaze data with status %i.\n", status);
printf("Last received gaze package:\n");
printf("System time stamp: %" PRId64 "\n", gaze_data.system_time_stamp);
printf("Device time stamp: %" PRId64 "\n", gaze_data.device_time_stamp);
printf("Left eye 2D gaze point on display area: (%f, %f)\n",
printf("Right eye 3d gaze origin in user coordinates (%f, %f, %f)\n",
/* Wait while some gaze data is collected. */
sleep_ms(2000);
}