@@ -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