aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/utils/contexts/TobiiProGlasses2.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze/utils/contexts/TobiiProGlasses2.py')
-rw-r--r--src/argaze/utils/contexts/TobiiProGlasses2.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/argaze/utils/contexts/TobiiProGlasses2.py b/src/argaze/utils/contexts/TobiiProGlasses2.py
index 061813e..80487f4 100644
--- a/src/argaze/utils/contexts/TobiiProGlasses2.py
+++ b/src/argaze/utils/contexts/TobiiProGlasses2.py
@@ -43,6 +43,7 @@ except ImportError:
from urllib2 import urlopen, Request, HTTPError, URLError
from argaze import ArFeatures, DataFeatures
+from argaze.utils import UtilsFeatures
import numpy
import cv2
@@ -360,6 +361,12 @@ class LiveStream(ArFeatures.LiveProcessingContext):
self.__parser = TobiiJsonDataParser()
+ self.__data_thread = None
+ self.__video_thread = None
+ self.__video_buffer_read_thread = None
+ self.__keep_alive_thread = None
+ self.__check_battery_thread = None
+
@property
def address(self) -> str:
"""Network address where to find the device."""
@@ -514,7 +521,12 @@ class LiveStream(ArFeatures.LiveProcessingContext):
@DataFeatures.PipelineStepEnter
def __enter__(self):
- logging.info('Tobii Pro Glasses 2 connexion starts...')
+ logging.info(f'Tobii Pro Glasses 2 connexion starts: trying to reach {self.__address} host...')
+
+ # Check that host exists
+ if not UtilsFeatures.ping(self.__address):
+
+ raise DataFeatures.PipelineStepEnterFailed(f'Tobii Pro Glasses 2 connexion fails: {self.__address} host unreachable.')
# Update current configuration with configuration patch
logging.debug('> updating configuration')
@@ -598,16 +610,25 @@ class LiveStream(ArFeatures.LiveProcessingContext):
self._stop_event.set()
# Stop keeping connection alive
- threading.Thread.join(self.__keep_alive_thread)
+ if self.__keep_alive_thread is not None:
+
+ threading.Thread.join(self.__keep_alive_thread)
# Stop data streaming
- threading.Thread.join(self.__data_thread)
+ if self.__data_thread is not None:
+
+ threading.Thread.join(self.__data_thread)
# Stop video buffer reading
- threading.Thread.join(self.__video_buffer_read_thread)
+ if self.__video_buffer_read_thread is not None:
+
+ threading.Thread.join(self.__video_buffer_read_thread)
# Stop video streaming
- threading.Thread.join(self.__video_thread)
+ if self.__video_thread is not None:
+
+ threading.Thread.join(self.__video_thread)
+
def __make_socket(self):
"""Create a socket to enable network communication."""