int record_mode_display(void) { ALLF_DATA evt; UINT16 key; int eye_used = -1; /* which eye to show gaze for */ float x, y; /* gaze position */ float ox=-1, oy=-1; /* old gaze position (to determine change) */ /* create font for position display */ get_new_font( "Arial", SCRWIDTH/50, 0); while(getkey()); /* dump any pending local keys */ /*enable link data reception without changing tracker mode */ eyelink_reset_data(1); initialize_cursor(window, SCRWIDTH/50); eyelink_data_switch(RECORD_LINK_SAMPLES | RECORD_LINK_EVENTS); while(1) /* loop while in record mode */ { if(eyelink_tracker_mode() != EL_RECORD_MODE) break; key = getkey(); /* Local keys/abort test */ if(key==TERMINATE_KEY) /* test ALT-F4 or end of execution */ break; else if(key) /* OTHER: echo to tracker for control */ eyelink_send_keybutton(key,0,KB_PRESS); /* CODE FOR PLOTTING GAZE CURSOR */ if(eyelink_newest_float_sample(NULL)>0) /* new sample? */ { eyelink_newest_float_sample(&evt); /* get the sample data */ if(eye_used == -1) /* set which eye to track by first sample */ { eye_used = eyelink_eye_available(); if(eye_used == BINOCULAR) /* use left eye if both tracked */ eye_used = LEFT_EYE; } else { x = evt.fs.gx[eye_used]; /* get gaze position from sample */ y = evt.fs.gy[eye_used]; if(x!=MISSING_DATA && y!=MISSING_DATA && evt.fs.pa[eye_used]>0) /* plot if not in blink */ { /* plot in local coords */ draw_gaze_cursor(track2local_x(x), track2local_y(y)); /* report gaze position (tracker coords) */ { SDL_Rect r = {(INT16)(SCRWIDTH*0.87), 0, (INT16)(window->w -SCRWIDTH*0.87), 50}; SDL_FillRect(window,&r,SDL_MapRGB(window->format,0, 0, 0)); graphic_printf(window, target_foreground_color, NONE, (int)(SCRWIDTH*0.87), 0, " %4.0f ", x); graphic_printf(window, target_foreground_color, NONE, (int)(SCRWIDTH*0.93), 0, " %4.0f ", y); } ox = x; oy = y; } else { erase_gaze_cursor(); /* hide cursor during blink */ } /* print tracker timestamp of sample */ { SDL_Rect r = {(INT16)(SCRWIDTH*0.75), 0, (INT16)(SCRWIDTH*0.87 -SCRWIDTH*0.75), 50}; SDL_FillRect(window,&r,SDL_MapRGB(window->format,0, 0, 0)); graphic_printf(window,target_foreground_color, NONE, (int)(SCRWIDTH*0.75), 0, " % 8d ", evt.fs.time); } } } } erase_gaze_cursor(); /* erase gaze cursor if visible */ return 0; }
bool Eyelink::initialize(){ boost::mutex::scoped_lock lock(EyelinkDriverLock); if (Eyelink_Initialized) { merror(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink was previously initialized! Trying again, but this is dangerous!!"); } Eyelink_Initialized = false; // Initializes the link //mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Trying to find Eyelink System at %s",tracker_ip); if (set_eyelink_address( &tracker_ip[0] ) ) merror(M_IODEVICE_MESSAGE_DOMAIN,"Failed to set Tracker to address %s", tracker_ip.c_str()); if(open_eyelink_connection(0)) merror(M_IODEVICE_MESSAGE_DOMAIN,"Failed to connect to Tracker at %s", tracker_ip.c_str()); else { ELINKNODE node; // generate data file name time_t now = time(NULL); struct tm* t = gmtime(&now); sprintf(data_file_name, "%02d%06d.edf",(t->tm_year-100),t->tm_yday*1440 + t->tm_hour*60 + t->tm_min); //YYMMMMMM : YY=Years since 2k, MMMMMM=Minutes in current year if ( open_data_file( data_file_name ) ) { mwarning(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink datafile setting failed (%s)",data_file_name); } else { mprintf(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink logs to local file %s",data_file_name); } // Tell the tracker what data to include in samples if (OK_RESULT != eyecmd_printf("link_sample_data = LEFT,RIGHT,GAZE,HREF,PUPIL,AREA")) { mwarning(M_IODEVICE_MESSAGE_DOMAIN, "Eyelink did not respond to link_sample_data command; sample data may be incomplete"); } // tell the tracker who we are eyelink_set_name((char*)("MWorks_over_Socket")); // verify the name if( eyelink_get_node(0,&node) != OK_RESULT ) merror(M_IODEVICE_MESSAGE_DOMAIN,"Error, EyeLink doesn't respond"); else eyemsg_printf((char*)("%s connected"), node.name); // Enable link data reception eyelink_reset_data(1); } // Eyelink should now be in "TCP-Link Open" mode if(eyelink_is_connected()) { tracker_version = eyelink_get_tracker_version(version_info); mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Eyelink %d System Version %s connected via Socket",tracker_version,version_info); Eyelink_Initialized = true; stopped = true; } else { merror(M_IODEVICE_MESSAGE_DOMAIN,"Error, Eyelink Connection could not be established"); } return Eyelink_Initialized; }