Пример #1
0
    def runSetupProcedure(self,starting_state=EyeTrackerConstants.DEFAULT_SETUP_PROCEDURE):
        """
        """                    
        try:
            calibration_properties=self.getConfiguration().get('calibration',None)

            if self._eyegaze_control and self.isRecordingEnabled() is False:                
                # pEyeGaze         
                # when using the external calibrate.exe to 
                # run calibration, need todisconnect from the tracker
                # and reconnect after calibration is done.
                self.setConnectionState(False)
                
                import subprocess,gevent
                #p = subprocess.Popen(('calibrate.exe', ''), env={"PATH": "/usr/bin"})
                p = subprocess.Popen(('calibrate.exe', ''))
                while p.poll() is None:
                    gevent.sleep(0.05)
                self.setConnectionState(True)
          
#            circle_attributes=calibration_properties.get('circle_attributes')
#            targetForegroundColor=circle_attributes.get('outer_color') # [r,g,b] of outer circle of targets
#            targetBackgroundColor=circle_attributes.get('inner_color') # [r,g,b] of inner circle of targets
#            screenColor=calibration_properties.get('screen_background_color')                     # [r,g,b] of screen
#            targetOuterDiameter=circle_attributes.get('outer_diameter')     # diameter of outer target circle (in px)
#            targetInnerDiameter=circle_attributes.get('inner_diameter')     # diameter of inner target circle (in px)
            
        except Exception,e:
            return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                    error_message="An unhandled exception occurred on the ioHub Server Process.",
                    method="EyeTracker.runSetupProcedure", 
                    starting_state=starting_state,
                    error=e)            
Пример #2
0
 def sendCommand(self, key, value=None):
     """
     """
     try:
         if self._eyegaze_control:
             if key == 'get_control_status':
                 rdict=dict()                    
                 for a in self._eyegaze_control.__slots__:
                     v=getattr(self._eyegaze_control,a)
                     rdict[a]=v
                 return rdict
             elif key == 'get_config':
                 egConfig=pEyeGaze._stEgConfig(0,0)
                 
                 r = pEyeGaze.EgGetConfig(byref(self._eyegaze_control),byref(egConfig),sizeof(egConfig))
                 rdict=None
                 if r==0:                    
                     rdict= {'iNVis':egConfig.iNVis, 'bEyefollower': egConfig.bEyefollower}
                 
                 egConfig=None
                 return rdict
             else:
                 ioHub.print2err('WARNING: EyeGaze command not handled: {0} = {1}.'.format())
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.sendCommand", key=key,value=value, error=e)            
Пример #3
0
 def isConnected(self):
     """
     """
     try:
         return self._eyegaze_control != None
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.isConnected", error=e)            
Пример #4
0
 def getLastGazePosition(self):
     """
     """
     try:
         return self._latest_gaze_position
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.getLastGazePosition", error=e)             
Пример #5
0
 def isRecordingEnabled(self,*args,**kwargs):
     """
     """
     try:
         return self._eyegaze_control is not None and self._eyegaze_control.bTrackingActive in [1,True]
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.isRecordingEnabled", error=e)
Пример #6
0
 def _displayToEyeTrackerCoords(self,display_x,display_y):
     """
     """
     try:                        
         gaze_x, gaze_y = self._display_device.pixel2DisplayCoord(display_x,display_y,self._display_device.getIndex())            
         return gaze_x, gaze_y
     except Exception,e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker._displayToEyeTrackerCoords", 
                 error=e)
Пример #7
0
 def enableEventReporting(self,enabled=True):
     """
     """
     try:
         if self._eyegaze_control:
             enabled=self.setRecordingState(self,enabled)
         return self.setRecordingState(enabled)
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.enableEventReporting", error=e)            
Пример #8
0
 def sendMessage(self,message_contents,time_offset=None):
     """
     """
     try:
         if self._eyegaze_control:
             ioHub.print2err("EyeGaze sendMessage not yet implemented")
             return EyeTrackerConstants.FUNCTIONALITY_NOT_SUPPORTED
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.sendMessage", message_contents=message_contents,time_offset=time_offset, error=e)            
Пример #9
0
 def setConnectionState(self,enable):
     """
     """
     try:
         if isinstance(enable,bool):
             if enable is True and not self.isConnected():
                 self._eyegaze_control=pEyeGaze.initializeEyeGazeDevice(self._display_device, self.getConfiguration())           
                 if self._eyegaze_control is None:
                     ioHub.print2err("Could not connect to EyeGaze. Exiting app..")
                     sys.exit(0)                                        
                 if self._eyegaze_control:
                     return True
                 return False
             elif enable is False and self.isConnected():
                 result=pEyeGaze.EgExit(byref(self._eyegaze_control))
                 self._eyegaze_control=None
                 return False
         else:
             return createErrorResult("INVALID_METHOD_ARGUMENT_VALUE",error_message="The enable arguement value provided is not recognized",method="EyeTracker.setConnectionState",arguement='enable', value=enable)            
     except Exception,e:
             return createErrorResult("IOHUB_DEVICE_EXCEPTION",error_message="An unhandled exception occurred on the ioHub Server Process.",method="EyeTracker.setConnectionState",arguement='enable', value=enable, error=e)            
Пример #10
0
 def _eyeTrackerToDisplayCoords(self,eyetracker_point):
     """
     """
     try:
         px,py=eyetracker_point
         display_x, display_y = self._display_device.pixel2DisplayCoord(px,py,self._display_device.getIndex())
         return display_x, display_y
     except Exception,e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker._eyeTrackerToDisplayCoords", 
                 error=e)            
Пример #11
0
 def setRecordingState(self,recording):
     """
     """
     try:
         if not isinstance(recording,bool):
             return createErrorResult("INVALID_METHOD_ARGUMENT_VALUE",
                 error_message="The recording arguement value provided is not a boolean.",
                 method="EyeTracker.setRecordingState",arguement='recording', value=recording)
          
         if self._eyegaze_control and recording is True and not self.isRecordingEnabled():                
             self._last_poll_time=0.0                
             self._eyegaze_control.bTrackingActive=1
             EyeTrackerDevice.enableEventReporting(self,True)            
         elif self._eyegaze_control and recording is False and self.isRecordingEnabled():
             self._eyegaze_control.bTrackingActive=0
             EyeTrackerDevice.enableEventReporting(self,False)
             self._latest_sample=None
             self._latest_gaze_position=None
         return self.isRecordingEnabled()
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.setRecordingState", error=e)            
Пример #12
0
 def enableEventReporting(self,enabled=True):
     """
     enableEventReporting is functionaly identical to the eye tracker 
     device specific setRecordingState method.
     """
     
     try:        
         enabled=EyeTrackerDevice.enableEventReporting(self,enabled)
         self.setRecordingState(enabled)
         return enabled
     except Exception, e:
         return createErrorResult("IOHUB_DEVICE_EXCEPTION",
                 error_message="An unhandled exception occurred on the ioHub Server Process.",
                 method="EyeTracker.enableEventReporting", error=e)