diff options
Diffstat (limited to 'src/argaze/TobiiGlassesPro2/TobiiData.py')
-rw-r--r-- | src/argaze/TobiiGlassesPro2/TobiiData.py | 96 |
1 files changed, 71 insertions, 25 deletions
diff --git a/src/argaze/TobiiGlassesPro2/TobiiData.py b/src/argaze/TobiiGlassesPro2/TobiiData.py index 6bfc89e..8e0a8b3 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiData.py +++ b/src/argaze/TobiiGlassesPro2/TobiiData.py @@ -1,12 +1,18 @@ +#!/usr/bin/env python + import threading import time +from argaze.TobiiGlassesPro2 import TobiiController + class TobiiDataThread(threading.Thread): + """Handle data reception in a separate thread.""" - # initialisation - def __init__(self, controller): + def __init__(self, controller: TobiiController.TobiiController): + """Initialise thread super class and prepare data reception.""" threading.Thread.__init__(self) + self.stop_event = threading.Event() self.read_lock = threading.Lock() @@ -15,18 +21,16 @@ class TobiiDataThread(threading.Thread): self.fps = self.controller.get_et_freq() self.sleep = 1./self.fps - self.__ac_buffer = [] # accelerometer - self.__gy_buffer = [] # gyroscope - self.__gp_buffer = [] # gaze point - self.__pts_buffer = [] # presentation timestamp + self.__ac_buffer = [] + self.__gy_buffer = [] + self.__gp_buffer = [] + self.__pts_buffer = [] self.__start_ts = 0 - # destruction def __del__(self): pass - # extract ac data def __get_ac(self, data): ac_value = data['mems']['ac']['ac'] @@ -41,7 +45,6 @@ class TobiiDataThread(threading.Thread): return ac_data - # extract gy data def __get_gy(self, data): gy_value = data['mems']['gy']['gy'] @@ -56,7 +59,6 @@ class TobiiDataThread(threading.Thread): return gy_data - # extract gp data def __get_gp(self, data): gp_value = data['gp']['gp'] @@ -70,7 +72,6 @@ class TobiiDataThread(threading.Thread): return gp_data - # extract pts data def __get_pts(self, data): pts_value = data['pts']['pts'] @@ -83,8 +84,8 @@ class TobiiDataThread(threading.Thread): return pts_data - # thread start def run(self): + """Data reception function.""" while not self.stop_event.isSet(): @@ -148,8 +149,19 @@ class TobiiDataThread(threading.Thread): self.read_lock.release() - # read ac data - def read_accelerometer_data(self, timestamp): + def read_accelerometer_data(self, timestamp: int = -1): + """Get accelerometer data at a given timestamp. + **Returns:** accelerometer dictionary + ``` + { + 'TIMESTAMP': int, + 'TIME': int, + 'X': float, + 'Y': float, + 'Z': float + } + ``` + """ if len(self.__ac_buffer): @@ -166,8 +178,9 @@ class TobiiDataThread(threading.Thread): return {} - # read ac buffer def read_accelerometer_buffer(self): + """Get accelerometer data buffer. + **Returns:** accelerometer dictionary array""" self.read_lock.acquire() @@ -177,8 +190,19 @@ class TobiiDataThread(threading.Thread): return ac_buffer - # read gy data - def read_gyroscope_data(self, timestamp): + def read_gyroscope_data(self, timestamp: int = -1): + """Get gyroscope data at a given timestamp. + **Returns:** gyroscope dictionary + ``` + { + 'TIMESTAMP': int, + 'TIME': int, + 'X': float, + 'Y': float, + 'Z': float + } + ``` + """ if len(self.__gy_buffer): @@ -195,8 +219,9 @@ class TobiiDataThread(threading.Thread): return {} - # read gy buffer def read_gyroscope_buffer(self): + """Get gyroscope data buffer. + **Returns:** gyroscope dictionary array""" self.read_lock.acquire() @@ -206,8 +231,18 @@ class TobiiDataThread(threading.Thread): return gy_buffer - # read gp data - def read_gaze_data(self, timestamp): + def read_gaze_data(self, timestamp: int = -1): + """Get gaze data at a given timestamp. + **Returns:** gaze dictionary + ``` + { + 'TIMESTAMP': int, + 'TIME': int, + 'X': float, + 'Y': float + } + ``` + """ if len(self.__gp_buffer): @@ -224,8 +259,9 @@ class TobiiDataThread(threading.Thread): return {} - # read gp buffer def read_gaze_buffer(self): + """Get gaze data buffer. + **Returns:** gaze dictionary array""" self.read_lock.acquire() @@ -235,8 +271,17 @@ class TobiiDataThread(threading.Thread): return gp_buffer - # read pts data - def read_pts_data(self, timestamp): + def read_pts_data(self, timestamp: int = -1): + """Get Presentation Time Stamp (pts) data at a given timestamp. + **Returns:** pts dictionary + ``` + { + 'TIMESTAMP': int, + 'TIME': int, + 'PTS': int + } + ``` + """ if len(self.__pts_buffer): @@ -253,8 +298,9 @@ class TobiiDataThread(threading.Thread): return {} - # read pts buffer def read_pts_buffer(self): + """Get Presentation Time Stamp (pts) data buffer. + **Returns:** pts dictionary array""" self.read_lock.acquire() @@ -264,8 +310,8 @@ class TobiiDataThread(threading.Thread): return pts_buffer - # thread stop def stop(self): + """Stop data reception definitively.""" self.stop_event.set() threading.Thread.join(self) |