Skip to content

Commit

Permalink
Sample gaze as quickly as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
domstoppable committed Nov 14, 2024
1 parent d180377 commit 7cd4703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self, *args, **kwargs) -> None:
self._screen_surface = None
self._window_size = None

self._cached_scene = None

self._gaze_mapper = None

self.setConnectionState(True)
Expand Down Expand Up @@ -271,24 +273,24 @@ def _poll(self):
return

logged_time = Computer.getTime()
frame_and_gaze = self._device.receive_matched_scene_video_frame_and_gaze(timeout_seconds=0)
scene_data = self._device.receive_scene_video_frame(timeout_seconds=0)
if scene_data is not None:
self._cached_scene, _ = scene_data

if frame_and_gaze is not None:
frame, gaze = frame_and_gaze
surface_map = self._gaze_mapper.process_frame(frame, gaze)
gaze = self._device.receive_gaze_datum(timeout_seconds=0)
if gaze is not None and self._cached_scene is not None:
surface_map = self._gaze_mapper.process_frame(self._cached_scene, gaze)
for surface_gaze in surface_map.mapped_gaze[self._screen_surface.uid]:
gaze_in_pix = [
surface_gaze.x * self._window_size[0],
surface_gaze.y * self._window_size[1],
]

gaze_in_display_units = self._eyeTrackerToDisplayCoords(gaze_in_pix)

self._add_gaze_sample(gaze_in_display_units, gaze, logged_time)

gaze = self._device.receive_gaze_datum(timeout_seconds=0)
if gaze is not None and hasattr(gaze, 'pupil_diameter_left'):
self._add_pupil_sample(gaze, logged_time)
if hasattr(gaze, 'pupil_diameter_left'):
self._add_pupil_sample(gaze, logged_time)

def _add_gaze_sample(self, surface_gaze, gaze_datum, logged_time):
native_time = gaze_datum.timestamp_unix_seconds
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "psychopy-eyetracker-pupil-labs"
version = "0.5.1"
version = "0.6.0"
description = "Extension package for PsychoPy which adds support for Pupil Labs eyetrackers."
readme = "README.md"
requires-python = ">= 3.7"
Expand Down

0 comments on commit 7cd4703

Please sign in to comment.