////////////////////////////////////////////////////////////////////////
//
//  sampler.c: こじ研 TobiiClient API サンプルプログラム
//      version 1.0 (July 27, 2010)
//      xkozima@myu.ac.jp (subject to GPLv2)
//
//  compile:  cc -m32 sampler.c TobiiClient.c -o sampler
//  document: http://www.myu.ac.jp/~xkozima/lab/gaze-tobii2.html

#include <stdio.h>
#include "TobiiClient.h"

int  main (int argc, char **argv)
{
    int  res, i;

    //  TobiiServer に接続（要アドレス設定）
    res = TobiiConnect("127.0.0.1");
    if (res == -1) {
        //  接続失敗
        fprintf(stderr, "** error: cannot connect to the server\n");
        return 1;
    }
    printf("** connected to the server\n");

    //  100ms ごとに視線データを取得・表示（50回繰り返す）
    for (i = 0; i < 50; i++) {
        TobiiGazeData  gaze;

        //  TobiiServer から視線データを取得
        TobiiGetData(&gaze);

        //  画面上の X-Y 座標を表示
        printf("** got gaze %d (%f, %f)\n", i, 
               (gaze.x_gazepos_lefteye + gaze.x_gazepos_righteye) / 2.0, 
               (gaze.y_gazepos_lefteye + gaze.y_gazepos_righteye) / 2.0 );

        //  時間調整（100ms 待つ）
        TobiiSleep(100);
    }

    //  TobiiServer から切断
    TobiiDisconnect();
    printf("** disconnected from the server\n");

    return 0;
}

