def update_psychopy_pupil_clock_offset(self): time_before = Computer.getTime() time_pupil_at_pupil_clock_reading = self.get_pupil_time() time_after = Computer.getTime() time_psychopy_at_pupil_clock_reading = (time_before + time_after) / 2.0 self._psychopy_pupil_clock_offset = ( time_pupil_at_pupil_clock_reading - time_psychopy_at_pupil_clock_reading)
def _poll(self): if not self.isConnected(): return logged_time = Computer.getTime() for topic, payload in self._pupil_remote.fetch(): if topic.startswith("gaze.3d."): self._cache_gaze_datum(topic, payload) if topic == self.surface_topic: for gaze_on_surface in payload["gaze_on_surfaces"]: if gaze_on_surface["on_surf"] is not True: continue if gaze_on_surface[ "confidence"] < self._confidence_threshold: continue gaze_datum = self._lookup_corresponding_gaze_datum( gaze_on_surface) if gaze_datum is None: continue # Skip surface-mapped gaze if no gaze is avalable self._add_gaze_sample( gaze_on_surface_datum=gaze_on_surface, gaze_datum=gaze_datum, logged_time=logged_time, ) if (topic.startswith("pupil") and payload["confidence"] < self._confidence_threshold): self._add_pupil_sample(pupil_datum=payload, logged_time=logged_time)
def trackerTime(self) -> float: """Returns the current time reported by the eye tracker device. Implementation measures the current time in PsychoPy time and applies the estimated clock offset to transform the measurement into tracker time. :return: The eye tracker hardware's reported current time. """ return self._psychopyTimeInTrackerTime(Computer.getTime())
def trackerTime(self): """trackerTime returns the current time reported by the eye tracker device. The time base is implementation dependent. Args: None Return: float: The eye tracker hardware's reported current time. """ return self._psychopyTimeInTrackerTime(Computer.getTime())
def _handleNativeEvent(self, *args, **kwargs): """This method is called every time there is new eye data available from the Tobii system, which will be roughly equal to the sampling rate eye data is being recorded at. The callback needs to return as quickly as possible so there is no chance of overlapping calls being made to the callback. Therefore this method simply puts the event data received from the eye tracker device, and the local ioHub time the callback was called, into a buffer for processing by the ioHub event system. """ if self.isReportingEvents(): try: logged_time = Computer.getTime() tobii_logged_time = self._tobii.getCurrentLocalTobiiTime( ) * self.DEVICE_TIMEBASE_TO_SEC eye_data_event = args[0] data_delay = tobii_logged_time - ( eye_data_event['system_time_stamp'] * self.DEVICE_TIMEBASE_TO_SEC) device_event_time = eye_data_event['device_time_stamp'] iohub_event_time = (logged_time - data_delay) self._addNativeEventToBuffer( (logged_time, device_event_time, iohub_event_time, data_delay, eye_data_event)) return True except Exception: print2err('ERROR IN _handleNativeEvent') printExceptionDetailsToStdErr() else: print2err( 'self._handleNativeEvent called but isReportingEvents == false' )
return False if __name__ == '__main__': psychopy_pid = None initial_offset = 0.0 scriptPathDir = None configFileName = None prog = sys.argv[0] if len(sys.argv) >= 2: initial_offset = float(sys.argv[1]) if len(sys.argv) >= 3: scriptPathDir = sys.argv[2] if len(sys.argv) >= 4: configFileName = sys.argv[3] if len(sys.argv) >= 5: psychopy_pid = int(sys.argv[4]) if len(sys.argv) < 2: psychopy_pid = None configFileName = None scriptPathDir = None initial_offset = Computer.getTime() if psychopy_pid: Computer.psychopy_process = psutil.Process(psychopy_pid) Computer.global_clock = clock.MonotonicClock(initial_offset) run(rootScriptPathDir=scriptPathDir, configFilePath=configFileName)