def plugin_init(self, enableplugin=None): plugin.PluginProto.plugin_init(self, enableplugin) self.decimals[0] = 0 self.initialized = False if self.enabled: i2cport = -1 try: for i in range(0, 2): if gpios.HWPorts.is_i2c_usable( i) and gpios.HWPorts.is_i2c_enabled(i): i2cport = i break except: i2cport = -1 if i2cport > -1: try: pinnum = int(self.taskdevicepluginconfig[0]) except: pinnum = 0 try: i2ca, self.rpin = lib_pcfrouter.get_pcf_pin_address(pinnum) self.pcf = lib_pcfrouter.request_pcf_device(pinnum) except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "PCF device requesting failed: " + str(e)) self.pcf = None if self.pcf is None or self.pcf.initialized == False: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "PCF can not be initialized! ") else: self.initialized = True intok = False try: self.uservar[0] = self.pcf.readpin(self.rpin) if int(self.taskdevicepin[0]) > 0: self.pcf.setexternalint(int(self.taskdevicepin[0])) self.pcf.setcallback(self.rpin, self.p019_handler) intok = True except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "PCF interrupt configuration failed:" + str(e)) intok = False if intok: self.timer100ms = False misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "PCF 1/10s timer disabled") elif int( self.interval ) == 0: # if no interval setted and not interrupt selected setup a failsafe method self.timer100ms = True misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "PCF 1/10s timer enabled") try: self.ports = str(self.taskdevicepluginconfig[0]) except: self.ports = 0 else: self.ports = 0 self.timer100ms = False self.pcf.setcallback(self.rpin, None)
def p019_timercb(self,stimerid,ioarray): if ioarray[0] > -1: misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFGPIO"+str(ioarray[0])+": LongPulse ended") try: tmcp = lib_pcfrouter.request_pcf_device(int(ioarray[0])) ti2ca, trpin = lib_pcfrouter.get_pcf_pin_address(int(ioarray[0])) tmcp.writepin(trpin, int(ioarray[1])) except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"PCFGPIO"+str(ioarray[0])+": "+str(e))
def plugin_write(self,cmd): # handle incoming commands res = False cmdarr = cmd.split(",") cmdarr[0] = cmdarr[0].strip().lower() if cmdarr[0] == "pcfgpio": pin = -1 val = -1 try: pin = int(cmdarr[1].strip()) ti2ca, trpin = lib_pcfrouter.get_pcf_pin_address(pin) val = int(cmdarr[2].strip()) except: pin = -1 trpin = -1 if pin>-1 and val in [0,1] and trpin >-1: misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFPIO"+str(pin)+" set to "+str(val)) try: tmcp = lib_pcfrouter.request_pcf_device(int(pin)) tmcp.writepin(trpin, val) res = True self.syncvalue(pin,val) except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"PCFGPIO"+str(pin)+": "+str(e)) return res elif cmdarr[0]=="pcfpulse": pin = -1 val = -1 try: pin = int(cmdarr[1].strip()) ti2ca, trpin = lib_pcfrouter.get_pcf_pin_address(pin) val = int(cmdarr[2].strip()) except: pin = -1 trpin = -1 dur = 100 try: dur = float(cmdarr[3].strip()) except: dur = 100 if pin>-1 and val in [0,1] and trpin >-1: misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFGPIO"+str(pin)+": Pulse started") try: self.syncvalue(pin,val) tmcp = lib_pcfrouter.request_pcf_device(int(pin)) tmcp.writepin(trpin, val) s = float(dur/1000) time.sleep(s) tmcp.writepin(trpin, (1-val)) res = True self.syncvalue(pin,(1-val)) except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"PCFGPIO"+str(pin)+": "+str(e)) misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFGPIO"+str(pin)+": Pulse ended") return res elif cmdarr[0]=="pcflongpulse": pin = -1 val = -1 try: pin = int(cmdarr[1].strip()) ti2ca, trpin = lib_pcfrouter.get_pcf_pin_address(pin) val = int(cmdarr[2].strip()) except: pin = -1 trpin = -1 dur = 2 try: dur = float(cmdarr[3].strip()) except: dur = 2 if pin>-1 and val in [0,1] and trpin >-1: misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFGPIO"+str(pin)+": LongPulse started") try: tmcp = lib_pcfrouter.request_pcf_device(int(pin)) tmcp.writepin(trpin, val) res = True except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"PCFGPIO"+str(pin)+": "+str(e)) rarr = [int(pin),(1-val)] rpieTime.addsystemtimer(dur,self.p019_timercb,rarr) return res
def plugin_init(self, enableplugin=None): plugin.PluginProto.plugin_init(self, enableplugin) self.decimals[0] = 0 self.initialized = False if self.enabled: try: i2cport = gpios.HWPorts.geti2clist() except: i2cport = [] if len(i2cport) > 0: try: pinnum = int(self.taskdevicepluginconfig[0]) except: pinnum = 0 try: i2ca, self.rpin = lib_pcfrouter.get_pcf_pin_address(pinnum) self.pcf = lib_pcfrouter.request_pcf_device(pinnum) except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "PCF device requesting failed: " + str(e)) self.pcf = None if self.pcf is None or self.pcf.initialized == False: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "PCF can not be initialized! ") else: self.initialized = True intok = False try: self.uservar[0] = self.pcf.readpin(self.rpin) if int(self.taskdevicepin[0]) > 0 and (int( self.taskdevicepluginconfig[1]) != 2): self.pcf.setexternalint(int(self.taskdevicepin[0])) self.pcf.setcallback(self.rpin, self.p019_handler) intok = True except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "PCF interrupt configuration failed:" + str(e)) intok = False if (int(self.taskdevicepluginconfig[1]) == 2 ): # try to set up as output self.pcf.writepin(self.rpin, 0) if intok: self.timer100ms = False misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "PCF 1/10s timer disabled") elif int( self.interval ) == 0: # if no interval setted and not interrupt selected setup a failsafe method if (int(self.taskdevicepluginconfig[1]) != 2): self.timer100ms = True misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "PCF 1/10s timer enabled") else: self.timer1s = True misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "PCF 1/s timer enabled for sync") try: self.ports = str(self.taskdevicepluginconfig[0]) except: self.ports = 0 else: self.ports = 0 self.timer100ms = False self.timer1s = False self.pcf.setcallback(self.rpin, None)