Skip to content

Commit ea46421

Browse files
committed
Added battery info and calibration states
1 parent 9c27140 commit ea46421

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

examples/calibrate_and_record.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
def main():
2525

2626
tobiiglasses = TobiiGlassesController()
27+
print tobiiglasses.get_battery_info()
28+
29+
if tobiiglasses.is_recording():
30+
rec_id = tobiiglasses.get_current_recording_id()
31+
tobiiglasses.stop_recording(rec_id)
32+
2733
project_name = raw_input("Please insert the project's name: ")
2834
project_id = tobiiglasses.create_project(project_name)
2935

@@ -34,7 +40,7 @@ def main():
3440
raw_input("Put the calibration marker in front of the user, then press enter to calibrate")
3541
tobiiglasses.start_calibration(calibration_id)
3642

37-
res = tobiiglasses.wait_until_is_calibrated(calibration_id)
43+
res = tobiiglasses.wait_until_calibration_is_done(calibration_id)
3844

3945
if res is False:
4046
print("Calibration failed!")
@@ -45,9 +51,9 @@ def main():
4551
tobiiglasses.start_recording(recording_id)
4652
tobiiglasses.send_event("start_recording", "Start of the recording ")
4753
raw_input("Press enter to stop recording")
48-
tobiiglasses.stop_recording(recording_id)
4954
tobiiglasses.send_event("stop_recording", "Stop of the recording " + str(recording_id))
50-
res = tobiiglasses.wait_until_recording_is_done(recording_id)
55+
tobiiglasses.stop_recording(recording_id)
56+
5157

5258
if res is False:
5359
print("Recording failed!")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name='tobiiglassesctrl',
16-
version='1.1.2',
16+
version='1.1.3',
1717
description='A Python controller for Tobii Pro Glasses 2',
1818
url='https://github.com/ddetommaso/TobiiProGlasses2_PyCtrl',
1919
download_url='https://github.com/ddetommaso/TobiiProGlasses2_PyCtrl/archive/master.zip',

tobiiglassesctrl.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, if_name = None, address = None):
5050

5151
self.project_id = str(uuid.uuid4())
5252
self.project_name = "TobiiProGlasses PyController"
53-
self.project_creation_date = datetime.datetime.now().strftime("%m/%d/%y %H:%M:%S")
53+
self.project_creation_date = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
5454
self.recn = 0
5555

5656
self.KA_DATA_MSG = "{\"type\": \"live.data.unicast\", \"key\": \""+ str(uuid.uuid4()) +"\", \"op\": \"start\"}"
@@ -306,7 +306,6 @@ def get_project_id(self, project_name):
306306
for project in projects:
307307
if project['pr_info']['Name'] == project_name:
308308
project_id = project['pr_id']
309-
310309
return project_id
311310

312311
def get_participant_id(self, participant_name):
@@ -315,9 +314,35 @@ def get_participant_id(self, participant_name):
315314
for participant in participants:
316315
if participant['pa_info']['Name'] == participant_name:
317316
participant_id = participant['pa_id']
318-
319317
return participant_id
320318

319+
def get_status(self):
320+
return self.__get_request__('/api/system/status')
321+
322+
def get_battery_status(self):
323+
return self.get_status()['sys_battery']
324+
325+
def get_battery_level(self):
326+
return self.get_battery_status()['level']
327+
328+
def get_battery_remaining_time(self):
329+
return self.get_battery_status()['remaining_time']
330+
331+
def get_battery_info(self):
332+
return ( "Battery info = [ Level: %.2f %% - Remaining Time: %.2f s ]" % (float(self.get_battery_level()), float(self.get_battery_remaining_time())) )
333+
334+
def get_recording_status(self):
335+
return self.get_status()['sys_recording']
336+
337+
def is_recording(self):
338+
rec_status = self.get_recording_status()
339+
if rec_status != {}:
340+
if rec_status['rec_state'] == "recording":
341+
return True
342+
return False
343+
344+
def get_current_recording_id(self):
345+
return self.get_recording_status()['rec_id']
321346

322347
def create_project(self, projectname = "DefaultProjectName"):
323348
project_id = self.get_project_id(projectname)
@@ -352,21 +377,18 @@ def create_calibration(self, project_id, participant_id):
352377
return json_data['ca_id']
353378

354379
def wait_until_calibration_is_done(self, calibration_id):
355-
status = self.wait_for_calibration_status(calibration_id, ['calibrated', 'uncalibrated'])
356-
if status == 'calibrated':
357-
log.debug("Calibration %s successful " % calibration_id)
358-
return True
359-
else:
360-
log.debug("Calibration %s failed " % calibration_id)
361-
return False
362-
363-
364-
def wait_for_calibration_status(self, calibration_id, status_array = ['calibrating', 'calibrated', 'stale', 'uncalibrated']):
365-
return self.wait_for_status('/api/calibrations/' + calibration_id + '/status', 'ca_state', status_array)
380+
while True:
381+
status = self.wait_for_status('/api/calibrations/' + calibration_id + '/status', 'ca_state', ['calibrating', 'calibrated', 'stale', 'uncalibrated', 'failed'])
382+
log.debug("Calibration status %s" % status)
383+
if status == 'uncalibrated' or status == 'stale' or status == 'failed':
384+
log.debug("Calibration %s failed " % calibration_id)
385+
return False
386+
elif status == 'calibrated':
387+
log.debug("Calibration %s successful " % calibration_id)
388+
return True
366389

367390
def start_calibration(self, calibration_id):
368391
self.__post_request__('/api/calibrations/' + calibration_id + '/start')
369-
return self.wait_for_calibration_status(calibration_id, ['calibrating'])
370392

371393
def create_recording(self, participant_id, recording_notes = ""):
372394
self.recn = self.recn + 1

0 commit comments

Comments
 (0)