def _registerEventMonitors(self): self._iohub_server=self._eyetrackerinterface._iohub_server if self._iohub_server: for dev in self._iohub_server.devices: #ioHub.print2err("dev: ",dev.__class__.__name__) if dev.__class__.__name__ == 'Keyboard': kbDevice=dev elif dev.__class__.__name__ == 'Mouse': mouseDevice=dev if kbDevice: eventIDs=[] for event_class_name in kbDevice.__class__.EVENT_CLASS_NAMES: eventIDs.append(getattr(EventConstants,convertCamelToSnake(event_class_name[:-5],False))) self._ioKeyboard=kbDevice self._ioKeyboard._addEventListener(self,eventIDs) else: ioHub.print2err("Warning: elCG could not connect to Keyboard device for events.") if mouseDevice: eventIDs=[] for event_class_name in mouseDevice.__class__.EVENT_CLASS_NAMES: eventIDs.append(getattr(EventConstants,convertCamelToSnake(event_class_name[:-5],False))) self._ioMouse=mouseDevice self._ioMouse._addEventListener(self,eventIDs) else: ioHub.print2err("Warning: elCG could not connect to Mouse device for events.")
def addDeviceToMonitor(self,device_class_name,device_config): self.log("Handling Device: %s"%(device_class_name,)) # ioHub.print2err("addDeviceToMonitor:\n\tdevice_class: {0}\n\texperiment_device_config:{1}\n".format(device_class_name,device_config)) DeviceClass=None class_name_start=device_class_name.rfind('.') device_module_path='ioHub.devices.' if class_name_start>0: device_module_path=device_module_path+device_class_name[:class_name_start].lower() device_class_name=device_class_name[class_name_start+1:] else: device_module_path=device_module_path+device_class_name.lower() #ioHub.print2err("Processing device, device_class_name: {0}, device_module_path: {1}".format(device_class_name, device_module_path)) dconfigPath=os.path.join(ioHub.IO_HUB_DIRECTORY,device_module_path[6:].replace('.',os.path.sep),"default_%s.yaml"%(device_class_name.lower())) #ioHub.print2err("Loading Device Defaults file:\n\tdevice_class: {0}\n\tdeviceConfigFile:{1}\n".format(device_class_name,dconfigPath)) self.log("Loading Device Defaults file: %s"%(device_class_name,)) _dclass,default_device_config=load(file(dconfigPath,'r'), Loader=Loader).popitem() #ioHub.print2err("Device Defaults:\n\tdevice_class: {0}\n\tdefault_device_config:{1}\n".format(device_class_name,default_device_config)) self.processDeviceConfigDictionary(device_module_path, device_class_name, device_config,default_device_config) if device_module_path in self._all_device_config_errors: # Complete device config verification. ioHub.print2err("**** ERROR: DEVICE CONFIG ERRORS FOUND ! NOT LOADING DEVICE: ",device_module_path) device_config_errors=self._all_device_config_errors[device_module_path] for error_type,errors in device_config_errors.iteritems(): ioHub.print2err("%s count %d:"%(error_type,len(errors))) for error in errors: ioHub.print2err("\t{0}".format(error)) ioHub.print2err("\n") return None DeviceClass=ioHub.devices.import_device(device_module_path,device_class_name) #ioHub.print2err("Updated Experiment Device Config:\n\tdevice_class: {0}\n\tdevice_config:{1}\n".format(device_class_name,default_device_config)) if device_config.get('enable',True): self.log("Searching Device Path: %s"%(device_class_name,)) self.log("Creating Device: %s"%(device_class_name,)) #ioHub.print2err("Creating Device: %s"%(device_class_name,)) if DeviceClass._iohub_server is None: DeviceClass._iohub_server=self if device_class_name != 'Display' and DeviceClass._display_device is None: DeviceClass._display_device=ioServer.deviceDict['Display'] deviceInstance=DeviceClass(dconfig=device_config) self.log("Device Instance Created: %s"%(device_class_name,)) #ioHub.print2err("Device Instance Created: %s"%(device_class_name,)) self.devices.append(deviceInstance) ioServer.deviceDict[device_class_name]=deviceInstance if 'device_timer' in device_config: interval = device_config['device_timer']['interval'] self.log("%s has requested a timer with period %.5f"%(device_class_name, interval)) dPoller=DeviceMonitor(deviceInstance,interval) self.deviceMonitors.append(dPoller) eventIDs=[] monitor_events_list=device_config.get('monitor_event_types',[]) if isinstance(monitor_events_list,(list,tuple)): for event_class_name in monitor_events_list: eventIDs.append(getattr(EventConstants,ioHub.convertCamelToSnake(event_class_name[:-5],False))) self.log("{0} Instance Event IDs To Monitor: {1}".format(device_class_name,eventIDs)) #ioHub.print2err("{0} Instance Event IDs To Monitor: {1}".format(device_class_name,eventIDs)) # add event listeners for streaming events if device_config.get('stream_events') is True: self.log("Online event access is being enabled for: %s"%device_class_name) # add listener for global event queue deviceInstance._addEventListener(self,eventIDs) #ioHub.print2err("ioServer event stream listener added: device=%s eventIDs=%s"%(device_class_name,eventIDs)) self.log("Standard event stream listener added for ioServer for event ids %s"%(str(eventIDs),)) # add listener for device event queue deviceInstance._addEventListener(deviceInstance,eventIDs) # ioHub.print2err("%s event stream listener added: eventIDs=%s"%(device_class_name,eventIDs)) self.log("Standard event stream listener added for class %s for event ids %s"%(device_class_name,str(eventIDs))) return deviceInstance,device_config,eventIDs