This is example 18. This example demonstrates the following:

  1. Processing online blink events

This example is based on example 10. This example adds an onBlinkEvent() event handler function to print blink start, end and update events.

Source code

Source file: example18.c

Initialization

In the eyevec_create_thread() function in the initialization part we provide a blink event callback function.

int main(void)
{
    .
    .

    EyeVecResult err = eyevec_create_thread(eyevec,
        onModeChange,
        NULL,   // onDisplayData,
        NULL,   // onEyeData,
        onBlinkEvent, (1)
        NULL,   // onSaccadeEvent,
        NULL,   // onFixationEvent,
        NULL,   // onTestItemEvent,
        &clientdata);
    printError("eyevec_create_thread()", err);
    if (err) return EXIT_FAILURE;

    .
    .
1 Callback function for blink start, end and update events.

processInput()

onBlinkEvent()

In the onBlinkEvent() event handler function we call onBlinkStart(), onBlinkEnd() or onBlinkUpdate() depending on the flag parameter provided to the onBlinkEvent() function.

static int onBlinkEvent(const EyeVec* eyevec, int64_t eventtime,
    const EyeVecBlinkEventData* blinkdata, int flag, void* cldata)
{
    const ClientData* clientdata = (const ClientData*)cldata;
    if (clientdata == NULL) return 0;

    if (flag == 0)
        return onBlinkStart(eyevec, eventtime, blinkdata, clientdata); (1)

    if (flag > 0)
        return onBlinkEnd(eyevec, eventtime, blinkdata, clientdata); (2)

    return onBlinkUpdate(eyevec, eventtime, blinkdata, clientdata); (3)
}
1 Call onBlinkStart() with provided blink data.
2 Call onBlinkEnd() with provided blink data.
3 Call onBlinkUpdate() with provided blink data.

onBlinkStart()

This function prints the relevant EyeVecBlinkEventData attributes defined for the blink start event.

static int onBlinkStart(const EyeVec* eyevec, int64_t eventtime,
    const EyeVecBlinkEventData* blinkdata, const ClientData* clientdata)
{
    (void)eyevec;

    if (clientdata->showgazeevents) {
        printf("onBlinkStart:\n");
        printf("    eventtime:                  %" PRId64 "\n",
            eventtime);
        printf("    side:                       %s\n",
            side_string(blinkdata->side));
        printf("    starttime:                  %" PRId64 "\n",
            blinkdata->starttime);
    }

    return 0;
}

onBlinkEnd()

This function prints the relevant EyeVecBlinkEventData attributes defined for the blink end event.

static int onBlinkEnd(const EyeVec* eyevec, int64_t eventtime,
    const EyeVecBlinkEventData* blinkdata, const ClientData* clientdata)
{
    (void)eyevec;

    if (clientdata->showgazeevents) {
        printf("onBlinkEnd:\n");
        printf("    eventtime:                  %" PRId64 "\n",
            eventtime);
        printf("    side:                       %s\n",
            side_string(blinkdata->side));
        printf("    starttime:                  %" PRId64 "\n",
            blinkdata->starttime);
        if (blinkdata->endtime > 0) {
            printf("    duration:                   %d\n",
                (int)(blinkdata->endtime - blinkdata->starttime));
        }
        else if (blinkdata->endtime == 0) {
            printf("    duration:                   timed out\n");
        }
        else {
            printf("    duration:                   lost\n");
        }

    }

    return 0;
}

onBlinkUpdate()

This function prints the relevant EyeVecBlinkEventData attributes defined for the blink update event.

static int onBlinkUpdate(const EyeVec* eyevec, int64_t eventtime,
    const EyeVecBlinkEventData* blinkdata, const ClientData* clientdata)
{
    (void)eyevec;

    if (clientdata->showgazeevents) {
        printf("onBlinkUpdate:\n");
        printf("    eventtime:                  %" PRId64 "\n",
            eventtime);
        printf("    side:                       %s\n",
            side_string(blinkdata->side));
        printf("    starttime:                  %" PRId64 "\n",
            blinkdata->starttime);
        printf("    duration:                   %d\n",
            (int)(blinkdata->endtime - blinkdata->starttime));
    }

    return 0;
}

Running

After a succesful build run the program:

  1. Press o to call eyevec_open(). Eye-tracker should go from off mode to idle mode.

  2. Press z to call eyevec_enter_data_mode(). Eye-tracker should go from idle mode to data mode. Note, we’re skipping setup and calibration here; still make sure the eye-tracker can see your eyes.

  3. Press g to call eyevec_set_gaze_event_enabled(0, EYEVEC_ENABLE_SEND_WHILE_IN_RECORDING_MODE).

  4. Press r to call eyevec_start_recording(). Eye-tracker should go from data mode to recording mode. Blink events should be printed.

  5. Press r to call eyevec_stop_recording(). Eye-tracker should go from recording mode to data mode. No more blink events will be printed.

  6. Press q to quit.

Output might look like this (empty lines added for clarity):

eyevec_create_thread(): OK
eyevec_initialize(): OK
Type q to quit, ? for help.

[o]
onModeChange:
    eventtime:                  1750692081949464
    oldmode:                    TRACKER_MODE_OFF
    newmode:                    TRACKER_MODE_IDLE
eyevec_open(): OK

[z]
eyevec_enter_data_mode(): OK
onModeChange:
    eventtime:                  1750692083635057
    oldmode:                    TRACKER_MODE_IDLE
    newmode:                    TRACKER_MODE_DATA

[g]
eyevec_set_gaze_event_enabled(0, 0x1): OK

[r]
onModeChange:
    eventtime:                  1750692108941859
eyevec_start_recording(): OK
    oldmode:                    TRACKER_MODE_DATA
    newmode:                    TRACKER_MODE_RECORDING

onBlinkStart:
    eventtime:                  1750692110496085
    side:                       RIGHT
    starttime:                  1750692110496085
onBlinkStart:
    eventtime:                  1750692110496085
    side:                       MEAN
    starttime:                  1750692110496085
onBlinkStart:
    eventtime:                  1750692110500086
    side:                       LEFT
    starttime:                  1750692110500086
onBlinkEnd:
    eventtime:                  1750692110612106
    side:                       RIGHT
    starttime:                  1750692110496085
    duration:                   116021
onBlinkEnd:
    eventtime:                  1750692110612106
    side:                       LEFT
    starttime:                  1750692110500086
    duration:                   112020
onBlinkEnd:
    eventtime:                  1750692110612106
    side:                       MEAN
    starttime:                  1750692110496085
    duration:                   116021
.
.
.

[q]
eyevec_cleanup(): OK
eyevec_destroy_thread(): OK