I'm trying to manually poll data by calling gtl::GazeApi's get_frame() method. The code below shows details. The output on the console shows that the eye tracker was successfully connect. However, the retrieved data is garbage. What did I miss?
- Code: Select all
// GazeDataCollector.h
#pragma once
#include "../include/gazeapi_interfaces.h"
#include "../include/gazeapi.h"
class GazeDataCollector : public gtl::IGazeListener
{
public:
GazeDataCollector(void);
~GazeDataCollector(void);
bool Connect();
void Disconnect();
bool GetFrame();
private:
void on_gaze_data(gtl::GazeData const &gaze_data);
gtl::GazeApi m_gApi;
bool connected;
gtl::GazeData data_;
};
- Code: Select all
//GazeDataCollector.cpp
#include "GazeDataCollector.h"
#include <iostream>
GazeDataCollector::GazeDataCollector(void) : connected(false)
{
std::cout << "constructor" << std::endl;
}
GazeDataCollector::~GazeDataCollector(void)
{
if(connected)
Disconnect();
std::cout << "destructor" << std::endl;
}
bool GazeDataCollector::Connect()
{
if(m_gApi.connect() )
{
m_gApi.add_listener(*this);
m_gApi.set_push(false);
connected = true;
return true;
}
return false;
}
bool GazeDataCollector::GetFrame()
{
m_gApi.get_frame(data_);
if(data_.state & gtl::GazeData::GD_STATE_TRACKING_GAZE)
{
gtl::Point2D const & smoothedCoordinates = data_.avg;
std::cout << "data received. " << smoothedCoordinates.x << ", " << smoothedCoordinates.y << std::endl;
}
return false;
}
void GazeDataCollector::Disconnect()
{
m_gApi.remove_listener(*this);
m_gApi.disconnect();
}
void GazeDataCollector::on_gaze_data(gtl::GazeData const &gaze_data)
{
if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinates = gaze_data.avg;
// Move GUI point, do hit-testing, log coordinates, etc.
std::cout << "data received. " << smoothedCoordinates.x << ", " << smoothedCoordinates.y << std::endl;
}
}
- Code: Select all
#include "GazeDataCollector.h"
#include <iostream>
#include "stdlib.h"
int main()
{
GazeDataCollector gaze;
if(gaze.Connect())
{
std::cout << "Connected." << std::endl;
std::cout << "start loop" << std::endl;
for(int i=0; i<50; i++)
{
gaze.GetFrame();
_sleep(30); // pause for 30 ms
}
std::cout << "end loop" << std::endl;
}
return 0;
}