當前位置: 首頁>>代碼示例>>Python>>正文


Python InterfaceKit.setSensorChangeTrigger方法代碼示例

本文整理匯總了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.setSensorChangeTrigger方法的典型用法代碼示例。如果您正苦於以下問題:Python InterfaceKit.setSensorChangeTrigger方法的具體用法?Python InterfaceKit.setSensorChangeTrigger怎麽用?Python InterfaceKit.setSensorChangeTrigger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phidgets.Devices.InterfaceKit.InterfaceKit的用法示例。


在下文中一共展示了InterfaceKit.setSensorChangeTrigger方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: InterfaceSource

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 別名]
class InterfaceSource(Source):
    def __init__(self):
        Source.__init__(self)
        
        try:
            self._device = InterfaceKit()
        except RuntimeError as e:
            print("Runtime Error: %s" % e.message)
            
        try:
            self._device.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.detail))
        
        self._device.setOnSensorChangeHandler(self.sensor_changed)
        
        print("Phidget: Waiting for Connection")
        self._device.waitForAttach(10000)
        
        self._device.setSensorChangeTrigger(0, 0)
        self._device.setDataRate(0, 1)
        
        print("Phidget: Connected")
    
    def sensor_changed(self, e):
        if self.sink is not None:
            self.sink([e.value])
開發者ID:intrinseca,項目名稱:pidaq,代碼行數:29,代碼來源:phidget.py

示例2: PhidgetsEventThread

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 別名]
class PhidgetsEventThread(QtCore.QThread):
    def __init__(self, parent=None):
        super(PhidgetsEventThread, self).__init__(parent)

        try:
            self.interfaceKit = InterfaceKit()
            self.interfaceKit.openPhidget()
            self.interfaceKit.setOnAttachHandler(self.interfaceKitAttachedEvent)
            self.interfaceKit.setOnDetachHandler(self.interfaceKitDetachEvent)
            self.interfaceKit.setOnErrorhandler(self.interfaceKitErrorSlot)
            self.interfaceKit.setOnInputChangeHandler(self.interfaceKitInputChangedEvent)
            self.interfaceKit.setOnOutputChangeHandler(self.interfaceKitOutputChangedEvent)
            self.interfaceKit.setOnSensorChangeHandler(self.interfaceKitSensorChangedEvent)
        except RuntimeError as e:
            print "Runtime Exception: %s" % (e.details)
            print "Exiting..."
            sys.exit(1)
            
        except PhidgetException as e:
            print "Phidget Exception %i: %s" % (e.code, e.details)
            print "Exiting..."
            sys.exit(1) 
    
    
    #===========================================================================
    # On Interfacekit events, emit signals to main thread for updating GUI
    #===========================================================================
    def interfaceKitAttachedEvent(self, event):
        self.emit(QtCore.SIGNAL("interfaceKitAttachedSlot"), event)
    
    def interfaceKitDetachEvent(self, event):
        self.emit(QtCore.SIGNAL("interfaceKitDetachedSlot"), event)
        
    def interfaceKitErrorSlot(self, event):
        self.emit(QtCore.SIGNAL("interfaceKitErrorSlot"), event)
    
    def interfaceKitInputChangedEvent(self, event):
        self.emit(QtCore.SIGNAL("interfaceKitInputChangedSlot"), event)
    
    def interfaceKitOutputChangedEvent(self, event):
        self.emit(QtCore.SIGNAL("interfaceKitOutputChangedSlot"), event)
    
    def interfaceKitSensorChangedEvent(self, event):
        self.emit(QtCore.SIGNAL("interfaceKitSensorChangedSlot"), event)
    
    def setSensorSensitivity(self, value):
        try:
            for i in range(self.interfaceKit.getSensorCount()):
                self.interfaceKit.setSensorChangeTrigger(i, value)
        except PhidgetException as e:
            print "Could not set sensitivity: %s" % e.details
            
    def run(self):
        self.exec_()
開發者ID:rhblind,項目名稱:QInterfaceKit,代碼行數:56,代碼來源:main.py

示例3: Node

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 別名]

#.........這裏部分代碼省略.........
            cls=self.__class__.__name__
        )

    def __conform__(self, protocol):
        return json.dumps(self.json(), cls=ComplexEncoder)

    def displayDeviceInfo(self):pass
        
    #Event Handler Callback Functions
    def inferfaceKitAttached(self, e):
        attached = e.device
        self.logger.info("InterfaceKit %i Attached!" % (attached.getSerialNum()))

    def interfaceKitDetached(self, e):
        detached = e.device
        self.logger.info("InterfaceKit %i Detached!" % (detached.getSerialNum()))

    def interfaceKitError(self, e):
        try:
            if e.eCode not in (36866,):
                source = e.device
                self.logger.info("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
        except PhidgetException as e:
            self.logger.exception(e)

    def interfaceKitInputChanged(self, e):
        input = self.get_input(e.index)
        if not input: return
        val = input.do_conversion(e.value)
        ob = input.json()
        self.publish(ob)
        self.logger.info("%s Input: %s" % (input.display, val))

    def interfaceKitSensorChanged(self, e):
        sensor = self.get_sensor(e.index)
        if not sensor: return
        val = sensor.do_conversion(float(e.value)) if sensor else 0
        ob = sensor.json()
        self.publish(ob)
        self.logger.info("%s Sensor: %s" % (sensor.display, val))

    def interfaceKitOutputChanged(self, e):
        output = self.get_output(e.index)
        if not output: return
        output.current_state = e.state
        ob = output.json()
        self.publish(ob)
        self.logger.info("%s Output: %s" % (output.display, output.current_state))


    def run(self):
        if LIVE: self.init_kit()
        while True: gevent.sleep(.1)

    def init_kit(self):
        try:
            self.interface_kit.setOnAttachHandler(self.inferfaceKitAttached)
            self.interface_kit.setOnDetachHandler(self.interfaceKitDetached)
            self.interface_kit.setOnErrorhandler(self.interfaceKitError)
            self.interface_kit.setOnInputChangeHandler(self.interfaceKitInputChanged)
            self.interface_kit.setOnOutputChangeHandler(self.interfaceKitOutputChanged)
            self.interface_kit.setOnSensorChangeHandler(self.interfaceKitSensorChanged)
        except PhidgetException as e:
            self.logger.exception(e)
            
        self.logger.info("Opening phidget object....")

        try:
            self.interface_kit.openPhidget()
        except PhidgetException as e:
            self.logger.exception(e)
            
        self.logger.info("Waiting for attach....")

        try:
            self.interface_kit.waitForAttach(10000)
        except PhidgetException as e:
            self.logger.exception(e)
            try:
                self.interface_kit.closePhidget()
            except PhidgetException as e:
                self.logger.exception(e)
                self.logger.info("Exiting....")
                exit(1)
            self.logger.info("Exiting....")
        else:
            self.displayDeviceInfo()

        self.logger.info("Initializing Sensors")
        for i in range(self.interface_kit.getSensorCount()):
            try:
                sensor = self.get_sensor(i)
                if sensor:
                    self.logger.info("Setting Up: %s" % sensor.display)
                    self.logger.info("Change: %s" % sensor.change)
                    self.logger.info("Data Rate: %s" % sensor.data_rate)
                    self.interface_kit.setSensorChangeTrigger(i, sensor.change)
                    self.interface_kit.setDataRate(i, sensor.data_rate)
            except PhidgetException as e:
                self.logger.exception(e)
開發者ID:entone,項目名稱:Automaton,代碼行數:104,代碼來源:__init__.py

示例4: SitwPhidgetsKey

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 別名]

#.........這裏部分代碼省略.........
        print("Waiting for attach....")
        
        try:
            self.interfaceKit.waitForAttach(10000)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            self.closePhidgets()
        else:
            self.displayDeviceInfo()
        
        
        #get sensor count
        try:
            self.ChannelCount = self.interfaceKit.getSensorCount()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            self.closePhidgets()
            sitwPara.KeyCount = 0 #no sensor has been detected
            self.prtMsg('   ****** No sensor has been detected !!!\n')
        
        
        print("Setting the data rate for each sensor index to 4ms....")
        for i in range(sitwPara.KeyCount):
            try:
                self.interfaceKit.setDataRate(i, 4)
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
        
        
        ### depends on the low light performance of the sensor
        print("Setting the sensitivity for each sensor index to ???....")
        for i in range(sitwPara.KeyCount):
            try:
                self.interfaceKit.setSensorChangeTrigger(i, 2)              #~~~~*YL*~~~~
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
        
        

    def closePhidgets(self):
        #print("Press Enter to quit....")
        #chr = sys.stdin.read(1)
        #print("Closing...")
        
        try:
            self.interfaceKit.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        
        #print("Done.")
        #exit(1)



    def initKeys(self):
        
        self.KeyPressed = ''

        self.ListValMat = []                
        for i in range(sitwPara.KeyCount):
            self.ListValEnv = []
            for j in range(self.SampleCount):
                self.ListValEnv.append(self.readSensorValue(i))
            self.ListValMat.append(self.ListValEnv)
開發者ID:screensinthewild,項目名稱:Phidgets-Light-Keypad,代碼行數:70,代碼來源:SitwPhidgetsKey.py


注:本文中的Phidgets.Devices.InterfaceKit.InterfaceKit.setSensorChangeTrigger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。