aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/TobiiGlassesPro2/TobiiData.py135
1 files changed, 70 insertions, 65 deletions
diff --git a/src/argaze/TobiiGlassesPro2/TobiiData.py b/src/argaze/TobiiGlassesPro2/TobiiData.py
index a7364c5..86bdf4c 100644
--- a/src/argaze/TobiiGlassesPro2/TobiiData.py
+++ b/src/argaze/TobiiGlassesPro2/TobiiData.py
@@ -54,6 +54,7 @@ class Gyroscope():
class PupilCenter():
"""Define pupil center data (gidx pc eye)."""
+ validity: int
index: int
value: tuple((float, float, float))
eye: str # 'right' or 'left'
@@ -62,6 +63,7 @@ class PupilCenter():
class PupilDiameter():
"""Define pupil diameter data (gidx pd eye)."""
+ validity: int
index: int
value: float
eye: str # 'right' or 'left'
@@ -70,6 +72,7 @@ class PupilDiameter():
class GazeDirection():
"""Define gaze direction data (gidx gd eye)."""
+ validity: int
index: int
value: tuple((float, float, float))
eye: str # 'right' or 'left'
@@ -78,6 +81,7 @@ class GazeDirection():
class GazePosition():
"""Define gaze position data (gidx l gp)."""
+ validity: int
index: int
l: str # ?
value: tuple((float, float))
@@ -86,6 +90,7 @@ class GazePosition():
class GazePosition3D():
"""Define gaze position 3D data (gidx gp3)."""
+ validity: int
index: int
value: tuple((float, float))
@@ -98,55 +103,55 @@ class MarkerPosition():
class TobiiJsonDataParser():
- def parse_dir_sig(self, json_data):
+ def parse_dir_sig(self, status, json_data):
return DirSig(json_data['dir'], json_data['sig'])
- def parse_pts(self, json_data):
+ def parse_pts(self, status, json_data):
return PresentationTimeStamp(json_data['pts'])
- def parse_event_synch(self, json_data):
+ def parse_event_synch(self, status, json_data):
return EventSynch(json_data['evts'])
- def parse_event(self, json_data):
+ def parse_event(self, status, json_data):
return Event(json_data['ets'], json_data['type'], json_data['tag'])
- def parse_accelerometer(self, json_data):
+ def parse_accelerometer(self, status, json_data):
return Accelerometer(json_data['ac'])
- def parse_gyroscope(self, json_data):
+ def parse_gyroscope(self, status, json_data):
return Gyroscope(json_data['gy'])
- def parse_pupil_center(self, gaze_index, json_data):
+ def parse_pupil_center(self, status, gaze_index, json_data):
- return PupilCenter(gaze_index, json_data['pc'], json_data['eye'])
+ return PupilCenter(status, gaze_index, json_data['pc'], json_data['eye'])
- def parse_pupil_diameter(self, gaze_index, json_data):
+ def parse_pupil_diameter(self, status, gaze_index, json_data):
- return PupilDiameter(gaze_index, json_data['pd'], json_data['eye'])
+ return PupilDiameter(status, gaze_index, json_data['pd'], json_data['eye'])
- def parse_gaze_direction(self, gaze_index, json_data):
+ def parse_gaze_direction(self, status, gaze_index, json_data):
- return GazeDirection(gaze_index, json_data['gd'], json_data['eye'])
+ return GazeDirection(status, gaze_index, json_data['gd'], json_data['eye'])
- def parse_gaze_position(self, gaze_index, json_data):
+ def parse_gaze_position(self, status, gaze_index, json_data):
- return GazePosition(gaze_index, json_data['l'], json_data['gp'])
+ return GazePosition(status, gaze_index, json_data['l'], json_data['gp'])
- def parse_gaze_position_3d(self, gaze_index, json_data):
+ def parse_gaze_position_3d(self, status, gaze_index, json_data):
- return GazePosition3D(gaze_index, json_data['gp3'])
+ return GazePosition3D(status, gaze_index, json_data['gp3'])
- def parse_marker_position(self, json_data):
+ def parse_marker_position(self, status, json_data):
return MarkerPosition(json_data['marker3d'], json_data['marker2d'])
- def parse_pupil_or_gaze(self, json_data):
+ def parse_pupil_or_gaze(self, status, json_data):
gaze_index = json_data.pop('gidx')
@@ -161,9 +166,9 @@ class TobiiJsonDataParser():
'gp3': self.parse_gaze_position_3d
}
- return parse_map[second_key](gaze_index, json_data)
+ return parse_map[second_key](status, gaze_index, json_data)
- def parse_data(self, json_data):
+ def parse_data(self, status, json_data):
# parse data depending first json key
first_key = next(iter(json_data))
@@ -179,7 +184,7 @@ class TobiiJsonDataParser():
'marker3d': self.parse_marker_position
}
- return parse_map[first_key](json_data)
+ return parse_map[first_key](status, json_data)
class TobiiDataSegment():
"""Handle Tobii Glasses Pro 2 segment data file."""
@@ -212,42 +217,42 @@ class TobiiDataSegment():
# define a decoder function
def decode(json_data):
- # accept only valid data (e.g. with status value equal to 0)
- if json_data.pop('s', -1) == 0:
+ # parse data status
+ status = json_data.pop('s', -1)
- # convert timestamp
- ts = json_data.pop('ts')
+ # convert timestamp
+ ts = json_data.pop('ts')
- # watch for vts data to offset timestamps
- try:
- self.__vts_offset = json_data['vts']
- self.__vts_ts = ts
+ # watch for vts data to offset timestamps
+ try:
+ self.__vts_offset = json_data['vts']
+ self.__vts_ts = ts
- return True # continue
+ return True # continue
- except KeyError:
- pass
+ except KeyError:
+ pass
- # ignore data before first vts entry
- if self.__vts_ts == -1:
- return True # continue
+ # ignore data before first vts entry
+ if self.__vts_ts == -1:
+ return True # continue
- ts -= self.__vts_ts
- ts += self.__vts_offset
+ ts -= self.__vts_ts
+ ts += self.__vts_offset
- # ignore timestamps out of the given time range
- if ts < start_timestamp:
- return True # continue
+ # ignore timestamps out of the given time range
+ if ts < start_timestamp:
+ return True # continue
- if ts >= end_timestamp:
- return False # stop
+ if ts >= end_timestamp:
+ return False # stop
- # convert json data into data object
- data_object = self.__json_data_parser.parse_data(json_data)
- data_object_type = type(data_object).__name__
+ # convert json data into data object
+ data_object = self.__json_data_parser.parse_data(status, json_data)
+ data_object_type = type(data_object).__name__
- # store data object into dedicated timestamped buffer
- self.__ts_data_buffer_dict[data_object_type][ts] = data_object
+ # store data object into dedicated timestamped buffer
+ self.__ts_data_buffer_dict[data_object_type][ts] = data_object
return True # continue
@@ -369,28 +374,28 @@ class TobiiDataStream(threading.Thread):
json_data = self.__data_queue.get()
- # accept only valid data (e.g. with status value equal to 0)
- if json_data.pop('s', -1) == 0:
+ # parse data status
+ status = json_data.pop('s', -1)
- # convert timestamp
- ts = json_data.pop('ts')
+ # convert timestamp
+ ts = json_data.pop('ts')
- # keep first timestamp to offset all timestamps
- if self.__first_ts == 0:
- self.__first_ts = ts
-
- ts -= self.__first_ts
-
- # ignore negative timestamp
- if ts < 0:
- break
+ # keep first timestamp to offset all timestamps
+ if self.__first_ts == 0:
+ self.__first_ts = ts
+
+ ts -= self.__first_ts
+
+ # ignore negative timestamp
+ if ts < 0:
+ break
- # convert json data into data object
- data_object = json_data_parser.parse_data(json_data)
- data_object_type = type(data_object).__name__
+ # convert json data into data object
+ data_object = json_data_parser.parse_data( status, json_data)
+ data_object_type = type(data_object).__name__
- # store data object into dedicated timestamped buffer
- ts_data_buffer_dict[data_object_type][ts] = data_object
+ # store data object into dedicated timestamped buffer
+ ts_data_buffer_dict[data_object_type][ts] = data_object
# unlock data queue access
self.__read_lock.release()