def setRecordingState(self, recording): """setRecordingState is used to start or stop the recording of data from the eye tracking device. args: recording (bool): if True, the eye tracker will start recordng available eye data and sending it to the experiment program if data streaming was enabled for the device. If recording == False, then the eye tracker stops recording eye data and streaming it to the experiment. If the eye tracker is already recording, and setRecordingState(True) is called, the eye tracker will simple continue recording and the method call is a no-op. Likewise if the system has already stopped recording and setRecordingState(False) is called again. Args: recording (bool): if True, the eye tracker will start recordng data.; false = stop recording data. Return: bool: the current recording state of the eye tracking device """ if self._tobii and recording is True and not self.isRecordingEnabled(): #ioHub.print2err("Starting Tracking... ") self._tobii.startTracking(self._handleNativeEvent) return EyeTrackerDevice.enableEventReporting(self, True) elif self._tobii and recording is False and self.isRecordingEnabled(): self._tobii.stopTracking() #ioHub.print2err("Stopping Tracking... ") self._latest_sample = None self._latest_gaze_position = None return EyeTrackerDevice.enableEventReporting(self, False) return self.isRecordingEnabled()
def __init__(self, *args, **kwargs): EyeTrackerDevice.__init__(self, *args, **kwargs) config = self.getConfiguration() # Used to hold the last sample processed by iohub. self._latest_sample = None # Calculate the desired ISI for the mouse sample stream. EyeTracker._ISI = 1.0 / config.get('runtime_settings').get( 'sampling_rate') EyeTracker._saccade_threshold = config.get('controls').get( 'saccade_threshold') mb_list = config.get('controls').get('move') if isinstance(mb_list, str): mb_list = (mb_list, ) if "CONTINUOUS" in mb_list: # CONTINUOUS == no buttons required to move == [] mb_list = [] bb_list = config.get('controls').get('blink') if isinstance(bb_list, str): bb_list = (bb_list, ) for mb in mb_list: self._move_eye_buttons[self._button_ix.get(mb)] = True for mb in bb_list: self._blink_eye_buttons[self._button_ix.get(mb)] = True EyeTracker._move_eye_buttons = tuple(self._move_eye_buttons) EyeTracker._blink_eye_buttons = tuple(self._blink_eye_buttons) # Used to hold the last valid gaze position processed by ioHub. # If the last mouse tracker in a blink state, then this is set to None # self._latest_gaze_position = 0.0, 0.0
def __init__(self, *args, **kwargs): EyeTrackerDevice.__init__(self, *args, **kwargs) self._latest_sample = None self._latest_gaze_position = None self._actively_recording = False self._surface_name = self._runtime_settings["surface_name"] self._confidence_threshold = self._runtime_settings[ "confidence_threshold"] pupil_remote_settings = self._runtime_settings["pupil_remote"] self._pupil_remote_ip_address = pupil_remote_settings["ip_address"] self._pupil_remote_port = pupil_remote_settings["port"] self._pupil_remote_timeout_ms = pupil_remote_settings["timeout_ms"] if self._runtime_settings["pupillometry_only"]: self._pupil_remote_subscriptions = ["pupil"] else: self._pupil_remote_subscriptions = ["gaze.3d.", self.surface_topic] # Calibration notifications are only being handled during runSetupProcedure() # and are otherwise ignored. self._pupil_remote_subscriptions.append("notify.calibration") capture_recording_settings = self._runtime_settings[ "pupil_capture_recording"] self._capture_recording_enabled = capture_recording_settings["enabled"] self._capture_recording_location = capture_recording_settings[ "location"] self._gaze_bisectors_by_topic = defaultdict(MutableBisector) self._pupil_remote = None self.setConnectionState(True)
def setRecordingState(self, should_be_recording): """The setRecordingState method is used to start or stop the recording and transmission of eye data from the eye tracking device to the ioHub Process. Args: recording (bool): if True, the eye tracker will start recordng data.; false = stop recording data. Return: bool: the current recording state of the eye tracking device """ if not self.isConnected(): return False if self._capture_recording_enabled: if should_be_recording: self._pupil_remote.start_recording( rec_name=self._capture_recording_location) else: self._pupil_remote.stop_recording() self._actively_recording = self._pupil_remote.is_recording else: self._actively_recording = should_be_recording is_recording_enabled = self.isRecordingEnabled() if not is_recording_enabled: self._latest_sample = None self._latest_gaze_position = None return EyeTrackerDevice.enableEventReporting(self, self._actively_recording)
def __init__(self, *args, **kwargs): EyeTrackerDevice.__init__(self, *args, **kwargs) if self.model_name: self.model_name = self.model_name.strip() if len(self.model_name) == 0: self.model_name = None model_name = self.model_name serial_num = self.getConfiguration().get('serial_number') EyeTracker._tobii = None try: EyeTracker._tobii = TobiiTracker(serial_num, model_name) except Exception: print2err('Error creating Tobii Device class') printExceptionDetailsToStdErr() # Apply license file if needed try: license_file = self.getConfiguration().get('license_file', "") if license_file != "": with open(license_file, "rb") as f: license = f.read() res = self._tobii._eyetracker.apply_licenses(license) if len(res) == 0: print2err( "Successfully applied Tobii license from: {}". format(license_file)) else: print2err( "Error: Failed to apply Tobii license from single key. " "Validation result: %s." % (res[0].validation_result)) else: print2err("No Tobii license_file in config. Skipping.") except Exception: print2err( "Error calling Tobii.apply_licenses with file {}.".format( license_file)) printExceptionDetailsToStdErr() srate = self._runtime_settings['sampling_rate'] if srate and srate in self._tobii.getAvailableSamplingRates(): self._tobii.setSamplingRate(srate) self._latest_sample = None self._latest_gaze_position = None
def enableEventReporting(self, enabled=True): """enableEventReporting is functionally identical to the eye tracker device specific setRecordingState method.""" try: self.setRecordingState(enabled) enabled = EyeTrackerDevice.enableEventReporting(self, enabled) return enabled except Exception as e: print2err('Exception in EyeTracker.enableEventReporting: ', str(e)) printExceptionDetailsToStdErr()
def enableEventReporting(self, enabled=True): """enableEventReporting is functionally identical to the eye tracker device specific enableEventReporting method.""" try: enabled = EyeTrackerDevice.enableEventReporting(self, enabled) self.setRecordingState(enabled) return enabled except Exception as e: print2err('Error during enableEventReporting') printExceptionDetailsToStdErr() return EyeTrackerConstants.EYETRACKER_ERROR
def setRecordingState(self, recording): """ setRecordingState is used to start or stop the recording of data from the eye tracking device. """ current_state = self.isRecordingEnabled() if recording is True and current_state is False: EyeTracker._recording = True if self._ioMouse is None: self._connectMouse() elif recording is False and current_state is True: EyeTracker._recording = False self._latest_sample = None EyeTracker._last_mouse_event_time = 0 return EyeTrackerDevice.enableEventReporting(self, recording)
def setRecordingState(self, should_be_recording: bool) -> bool: """The setRecordingState method is used to start or stop the recording and transmission of eye data from the eye tracking device to the ioHub Process. If the ``pupil_capture_recording.enabled`` runtime setting is set to ``True``, a corresponding raw recording within Pupil Capture will be started or stopped. ``should_be_recording`` will also be passed to :py:func:`.EyeTrackerDevice.enableEventReporting`. Args: recording (bool): if True, the eye tracker will start recordng data.; false = stop recording data. :return: bool: the current recording state of the eye tracking device """ if not self.isConnected(): return False if self._capture_recording_enabled: if should_be_recording: self._pupil_remote.start_recording( rec_name=self._capture_recording_location ) else: self._pupil_remote.stop_recording() self._actively_recording = self._pupil_remote.is_recording else: self._actively_recording = should_be_recording is_recording_enabled = self.isRecordingEnabled() if not is_recording_enabled: self._latest_sample = None self._latest_gaze_position = None return EyeTrackerDevice.enableEventReporting(self, self._actively_recording)
def _close(self): self.setRecordingState(False) self.setConnectionState(False) EyeTrackerDevice._close(self)
def _close(self): if EyeTracker._tobii: EyeTracker._tobii.disconnect() EyeTracker._tobii = None EyeTrackerDevice._close(self)