def _handleNativeEvent(self, *args, **kwargs): """ _handleEvent is used by devices that signal new events by using an event driven callback approach. One args is required, the device event to be handled, "event" """ loggedTime = int(Computer.currentUsec()) event = None if len(args) > 0: event = args[0] # do any manipulation to the native event object here before putting it in the devices # circular buffer. Remember to keep work done in the callback to a minimum. For example, # the conversion to a native ioHub event is done in the _getIOHubEventObject(event,device_instance_code) # method, so does not need to be done here. # # ...... # if 1: return 'EYETRACKER_ERROR', '_handleNativeEvent', 'Default _handleNativeEvent callback Logic being Used. This must be implemented on a per eye tracker basis.' EyeTracker.lastCallbackTime = loggedTime # append the native event to the deque as a tuple of (loggedTime, event) # This can be unpacked in the _getIOHubEventObject and the current_time # used as the logged_time field of the ioHub DeviceEvent object. # self.I_nativeEventBuffer.append((loggedTime, event))
def _poll(self): """ For use in systems where a polling model is used to check for new events and samples. If your eye tracker supports an event based call-back approach, use _handleEvent(...) instead of _poll and remove the periodic timer from the ioHub_config.yaml file settings. """ loggedTime = int(Computer.currentUsec()) currentHostTime = self.trackerTime() ioHub_time_offset = loggedTime - currentHostTime if 1: return 'EYETRACKER_ERROR', '_poll', 'Default Poll Logic being Used. This must be implemented on a per eye tracker basis.' #get native events queued up noMoreDeviceEvents = True while 1: # get each native device event (this will be eye tracker specific) # # .... # determine the event type and map it to one of the ioHub eye tracker event types # found in ioHub.devices.eyeTrackerInterface.eye_events.py # # ...... if noMoreDeviceEvents: break ioHubEvent = list() # put the ioHub eye tracker event IN ORDERED LIST FORM in devices buffer for pickup by the ioHub. self.I_nativeEventBuffer.append(ioHubEvent) EyeTracker.lastPollTime = loggedTime
def _handleNativeEvent(self, *args, **kwargs): """ _handleEvent is used by devices that signal new events by using an event driven callback approach. One args is required, the device event to be handled, "event" """ loggedTime = int(Computer.currentUsec()) event = None if len(args) > 0: event = args[0] # do any manipulation to the native event object here before putting it in the devices # circular buffer. Remember to keep work done in the callback to a minimum. For example, # the conversion to a native ioHub event is done in the _getIOHubEventObject(event,device_instance_code) # method, so does not need to be done here. # # ...... # if 1: return ( "EYETRACKER_ERROR", "_handleNativeEvent", "Default _handleNativeEvent callback Logic being Used. This must be implemented on a per eye tracker basis.", ) EyeTracker.lastCallbackTime = loggedTime # append the native event to the deque as a tuple of (loggedTime, event) # This can be unpacked in the _getIOHubEventObject and the current_time # used as the logged_time field of the ioHub DeviceEvent object. # self.I_nativeEventBuffer.append((loggedTime, event))
def _poll(self): """ For use in systems where a polling model is used to check for new events and samples. If your eye tracker supports an event based call-back approach, use _handleEvent(...) instead of _poll and remove the periodic timer from the ioHub_config.yaml file settings. """ loggedTime=int(Computer.currentUsec()) currentHostTime = self.trackerTime() ioHub_time_offset= loggedTime-currentHostTime if 1: return 'EYETRACKER_ERROR','_poll','Default Poll Logic being Used. This must be implemented on a per eye tracker basis.' #get native events queued up noMoreDeviceEvents=True while 1: # get each native device event (this will be eye tracker specific) # # .... # determine the event type and map it to one of the ioHub eye tracker event types # found in ioHub.devices.eyeTrackerInterface.eye_events.py # # ...... if noMoreDeviceEvents: break ioHubEvent = list() # put the ioHub eye tracker event IN ORDERED LIST FORM in devices buffer for pickup by the ioHub. self.I_nativeEventBuffer.append(ioHubEvent) EyeTracker.lastPollTime=loggedTime
def _poll(self): sTime=int(currentUsec()) try: ci=0 if self._lastPollTime is not None: ci=sTime-self._lastPollTime self._joystickButtonStates[0]=self._joystickButtonStates[1] self._joystickPositionStates[0]=self._joystickPositionStates[1] self._joystickButtonStates[1]=glfw.GetJoystickButtons(self._jid) self._joystickPositionStates[1]=glfw.GetJoystickPos(self._jid) if not N.array_equal(self._joystickPositionStates[1],self._joystickPositionStates[0]): #ioHub.print2stderr("Joystick Position Event: "+str(self._jid)+' : '+str(self._joystickPositionStates[1]-self._joystickPositionStates[0])) #jpe= [0,0,Computer.getNextEventID(),ioHub.devices.EventConstants.EVENT_TYPES['JOYSTICK_POSITIONAL_EVENT'], # ioHub.DEVICE_TYPES['JOYSTICK_DEVICE'], self.instance_code, currentTime, # currentTime, currentTime, ci,ci/2.0,self.base_address,self.address_offset,currentValue,lrv] #self.I_nativeEventBuffer.append(jbe) pass if not N.array_equal(self._joystickButtonStates[1],self._joystickButtonStates[0]): #ioHub.print2stderr("Joystick Button Event: "+str(self._jid)+' : '+str(self._joystickButtonStates[1]-self._joystickButtonStates[0])) bchanges=self._joystickButtonStates[1]-self._joystickButtonStates[0] multibuttonEventCount=N.count_nonzero(bchanges) devicetype=ioHub.devices.EventConstants.DEVICE_TYPES['JOYSTICK_DEVICE'] for i, bstate in enumerate(bchanges): is_pressed = 0 etype=None button_id=i+1 if bstate < 0: is_pressed = False etype=ioHub.devices.EventConstants.EVENT_TYPES['JOYSTICK_BUTTON_RELEASE'] elif bstate > 0 : is_pressed = True etype=ioHub.devices.EventConstants.EVENT_TYPES['JOYSTICK_BUTTON_PRESS'] if etype: jbe= [0,0,Computer.getNextEventID(),etype, self.instance_code, sTime, sTime, sTime, ci, ci/2.0, self._jid, is_pressed, button_id,multibuttonEventCount] #ioHub.print2stderr("Joystick Button Event: "+str(jbe)) self.I_nativeEventBuffer.append(jbe) except Exception as e: ioHub.printExceptionDetailsToStdErr() raise ioHub.devices.ioDeviceError(self,"An error orricced what polling GAMEPAD_%d"%(self._jid+1),e) finally: self._lastPollTime=sTime
def _poll(self): sTime = int(currentUsec()) try: ci = 0 if self._lastPollTime is not None: ci = sTime - self._lastPollTime self._joystickButtonStates[0] = self._joystickButtonStates[1] self._joystickPositionStates[0] = self._joystickPositionStates[1] self._joystickButtonStates[1] = glfw.GetJoystickButtons(self._jid) self._joystickPositionStates[1] = glfw.GetJoystickPos(self._jid) if not N.array_equal(self._joystickPositionStates[1], self._joystickPositionStates[0]): #ioHub.print2stderr("Joystick Position Event: "+str(self._jid)+' : '+str(self._joystickPositionStates[1]-self._joystickPositionStates[0])) #jpe= [0,0,Computer.getNextEventID(),ioHub.devices.EventConstants.EVENT_TYPES['JOYSTICK_POSITIONAL_EVENT'], # ioHub.DEVICE_TYPES['JOYSTICK_DEVICE'], self.instance_code, currentTime, # currentTime, currentTime, ci,ci/2.0,self.base_address,self.address_offset,currentValue,lrv] #self.I_nativeEventBuffer.append(jbe) pass if not N.array_equal(self._joystickButtonStates[1], self._joystickButtonStates[0]): #ioHub.print2stderr("Joystick Button Event: "+str(self._jid)+' : '+str(self._joystickButtonStates[1]-self._joystickButtonStates[0])) bchanges = self._joystickButtonStates[ 1] - self._joystickButtonStates[0] multibuttonEventCount = N.count_nonzero(bchanges) devicetype = ioHub.devices.EventConstants.DEVICE_TYPES[ 'JOYSTICK_DEVICE'] for i, bstate in enumerate(bchanges): is_pressed = 0 etype = None button_id = i + 1 if bstate < 0: is_pressed = False etype = ioHub.devices.EventConstants.EVENT_TYPES[ 'JOYSTICK_BUTTON_RELEASE'] elif bstate > 0: is_pressed = True etype = ioHub.devices.EventConstants.EVENT_TYPES[ 'JOYSTICK_BUTTON_PRESS'] if etype: jbe = [ 0, 0, Computer.getNextEventID(), etype, self.instance_code, sTime, sTime, sTime, ci, ci / 2.0, self._jid, is_pressed, button_id, multibuttonEventCount ] #ioHub.print2stderr("Joystick Button Event: "+str(jbe)) self.I_nativeEventBuffer.append(jbe) except Exception as e: ioHub.printExceptionDetailsToStdErr() raise ioHub.devices.ioDeviceError( self, "An error orricced what polling GAMEPAD_%d" % (self._jid + 1), e) finally: self._lastPollTime = sTime