Tobii Pro SDK C API
gaze_data.c
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
// Define a custom sleep function that's compatible with both windows and linux systems.
// You might want to put functions like this in a common helper file.
#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));
}
static void buffer_overflow_notification_callback(TobiiResearchNotification* notification, void* user_data) {
(void)user_data;
// Make sure we are handling the correct notification
//notification->value.text contains which streams' buffer is overflowing
printf("Buffer overflow occured in %s stream buffer", notification->value.text);
}
}
void gaze_data_example(TobiiResearchEyeTracker* eyetracker) {
char* serial_number = NULL;
tobii_research_get_serial_number(eyetracker, &serial_number);
printf("Subscribing to gaze data for eye tracker with serial number %s.\n", serial_number);
// Subscribe to notifications, passing a callback function defined above.
TobiiResearchStatus status = tobii_research_subscribe_to_notifications(eyetracker, buffer_overflow_notification_callback, NULL);
if (status != TOBII_RESEARCH_STATUS_OK)
return;
// Subscribe to gaze stream here. If your code takes to long too process the callback,
// the circular buffer will overflow and buffer_overflow_notification_callback will be called.
// For further information, we refer to our section on "streambufferoverflow".
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);
tobii_research_unsubscribe_from_notifications(eyetracker, buffer_overflow_notification_callback);
}
TobiiResearchNormalizedPoint2D::y
float y
Definition: tobii_research.h:392
TobiiResearchNotification::value
union TobiiResearchNotification::@0 value
TobiiResearchGazeData::device_time_stamp
int64_t device_time_stamp
Definition: tobii_research_streams.h:131
TobiiResearchPoint3D::y
float y
Definition: tobii_research.h:407
TobiiResearchEyeData::gaze_point
TobiiResearchGazePoint gaze_point
Definition: tobii_research_streams.h:101
tobii_research_unsubscribe_from_gaze_data
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_unsubscribe_from_gaze_data(TobiiResearchEyeTracker *eyetracker, tobii_research_gaze_data_callback callback)
Unsubscribes from gaze data for the eye tracker.
TOBII_RESEARCH_NOTIFICATION_STREAM_BUFFER_OVERFLOW
@ TOBII_RESEARCH_NOTIFICATION_STREAM_BUFFER_OVERFLOW
Definition: tobii_research_streams.h:476
TobiiResearchNotification
Definition: tobii_research_streams.h:488
TobiiResearchGazeData::system_time_stamp
int64_t system_time_stamp
Definition: tobii_research_streams.h:136
tobii_research_get_serial_number
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_get_serial_number(TobiiResearchEyeTracker *eyetracker, char **serial_number)
Gets the serial number of the eye tracker. All physical eye trackers have a unique serial number.
tobii_research_eyetracker.h
Functionality for an eye tracker.
TobiiResearchPoint3D::x
float x
Definition: tobii_research.h:403
tobii_research_free_string
TOBII_RESEARCH_API void TOBII_RESEARCH_CALL tobii_research_free_string(char *str)
Free memory allocation for a string allocated by the SDK.
tobii_research_subscribe_to_notifications
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_subscribe_to_notifications(TobiiResearchEyeTracker *eyetracker, tobii_research_notification_callback callback, void *user_data)
Subscribes to notifications for the eye tracker.
TobiiResearchGazeOrigin::position_in_user_coordinates
TobiiResearchPoint3D position_in_user_coordinates
Definition: tobii_research_streams.h:46
tobii_research_streams.h
Functionality for eye tracker streams.
tobii_research_unsubscribe_from_notifications
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_unsubscribe_from_notifications(TobiiResearchEyeTracker *eyetracker, tobii_research_notification_callback callback)
Unsubscribes from notifications for the eye tracker.
TobiiResearchGazeData::right_eye
TobiiResearchEyeData right_eye
Definition: tobii_research_streams.h:126
TobiiResearchGazeData
Definition: tobii_research_streams.h:117
TobiiResearchEyeTracker
struct TobiiResearchEyeTracker TobiiResearchEyeTracker
Definition: tobii_research.h:315
TobiiResearchNormalizedPoint2D::x
float x
Definition: tobii_research.h:388
TobiiResearchNotification::text
TobiiResearchNotificationString text
Definition: tobii_research_streams.h:512
TobiiResearchEyeData::gaze_origin
TobiiResearchGazeOrigin gaze_origin
Definition: tobii_research_streams.h:111
TobiiResearchGazePoint::position_on_display_area
TobiiResearchNormalizedPoint2D position_on_display_area
Definition: tobii_research_streams.h:81
TobiiResearchGazeData::left_eye
TobiiResearchEyeData left_eye
Definition: tobii_research_streams.h:121
TobiiResearchPoint3D::z
float z
Definition: tobii_research.h:411
TOBII_RESEARCH_STATUS_OK
@ TOBII_RESEARCH_STATUS_OK
Definition: tobii_research.h:49
tobii_research_subscribe_to_gaze_data
TOBII_RESEARCH_API TobiiResearchStatus TOBII_RESEARCH_CALL tobii_research_subscribe_to_gaze_data(TobiiResearchEyeTracker *eyetracker, tobii_research_gaze_data_callback callback, void *user_data)
Subscribes to gaze data for the eye tracker.
TobiiResearchStatus
TobiiResearchStatus
Definition: tobii_research.h:45
TobiiResearchNotification::notification_type
TobiiResearchNotificationType notification_type
Definition: tobii_research_streams.h:496