def setinterruptevents(): hardwaremod.removeallinterruptevents() print "load interrupt list " interruptlist = interruptdbmod.sensorlist() print "len interrupt list ", len(interruptlist) for item in interruptlist: print "got into the loop " # get PIN number recordkey = hardwaremod.HW_INFO_NAME recordvalue = item keytosearch = hardwaremod.HW_CTRL_PIN PINstr = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) print "set event for the PIN ", PINstr PIN = hardwaremod.toint(PINstr, -1) if PIN > -1: keytosearch = hardwaremod.HW_CTRL_LOGIC logic = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) # set Sw pull up / down mode if logic == "pos": hardwaremod.GPIO_setup(PIN, "in", "pull_down") evenslopetype = "both" else: hardwaremod.GPIO_setup(PIN, "in", "pull_up") evenslopetype = "both" #GPIO.RISING, GPIO.FALLING or GPIO.BOTH. # ignoring further edges for 200ms for switch bounce handling # link to the callback function hardwaremod.GPIO_add_event_detect(PIN, evenslopetype, eventcallback) return ""
def setinterruptevents(): hardwaremod.removeallinterruptevents() print("load interrupt list ") interruptlist = interruptdbmod.sensorlist() print("len interrupt list ", len(interruptlist)) for item in interruptlist: print("got into the loop ") # get PIN number recordkey = hardwaremod.HW_INFO_NAME recordvalue = item keytosearch = hardwaremod.HW_CTRL_PIN PINstr = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) print("set event for the PIN ", PINstr) if not PINstr == "": keytosearch = hardwaremod.HW_CTRL_LOGIC logic = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) # set Sw pull up / down mode if logic == "pos": hardwaremod.GPIO_setup(PINstr, "in", "pull_down") evenslopetype = "both" else: hardwaremod.GPIO_setup(PINstr, "in", "pull_up") evenslopetype = "both" #GPIO.RISING, GPIO.FALLING or GPIO.BOTH. # link to the callback function # the bouncetime is set by the frequency parameter, if this parameter is empty, the default bouncetime would be 200 keytosearch = hardwaremod.HW_CTRL_FREQ frequency = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) if frequency == "": bouncetimeINT = 200 else: frequencyINT = hardwaremod.toint(frequency, 5) bouncetimeINT = old_div( 1000, frequencyINT ) # in ms. this is ok to be trunk of the int. For frequencies higher than 1000 the bouncetime is exactly zero # RPI.GPIO library does not accept bouncetime=0, it gives runtime error if bouncetimeINT <= 0: bouncetimeINT = 1 #ms hardwaremod.GPIO_add_event_detect(PINstr, evenslopetype, eventcallback, bouncetimeINT) # set fast reference call indexed with the PIN number which is the variable used when interrupt is called: # search now to avoid searching later global PIN_attributes PIN = hardwaremod.toint(PINstr, 0) statusdataDBmod.write_status_data(PIN_attributes, PIN, "logic", logic) recordkey = hardwaremod.HW_CTRL_PIN recordvalue = PINstr keytosearch = hardwaremod.HW_INFO_NAME refsensor = hardwaremod.searchdata( recordkey, recordvalue, keytosearch) # return first occurence statusdataDBmod.write_status_data(PIN_attributes, PIN, "refsensor", refsensor) statusdataDBmod.write_status_data( PIN_attributes, PIN, "bouncetimeSec", 0.4 * float(bouncetimeINT) / 1000) # code below to enable blocking for N sec, it is necessary to trigger the bloccking status in case of levels already present when starting. elementlist = interruptdbmod.getelementlist() #print elementlist for element in elementlist: workmode = checkworkmode(element) if (workmode != "None") and (workmode != ""): sensor = interruptdbmod.searchdata("element", element, "sensor") #saveblockingdiff(sensor) print(" what a sensor ", sensor) if sensor != "": startblockingstate(element, 10, False) t.sleep(0.02) return ""
def setinterruptevents(): hardwaremod.removeallinterruptevents() print "load interrupt list " interruptlist = interruptdbmod.sensorlist() print "len interrupt list ", len(interruptlist) for item in interruptlist: print "got into the loop " # get PIN number recordkey = hardwaremod.HW_INFO_NAME recordvalue = item keytosearch = hardwaremod.HW_CTRL_PIN PINstr = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) print "set event for the PIN ", PINstr if not PINstr == "": keytosearch = hardwaremod.HW_CTRL_LOGIC logic = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) # set Sw pull up / down mode if logic == "pos": hardwaremod.GPIO_setup(PINstr, "in", "pull_down") evenslopetype = "both" else: hardwaremod.GPIO_setup(PINstr, "in", "pull_up") evenslopetype = "both" #GPIO.RISING, GPIO.FALLING or GPIO.BOTH. # link to the callback function # the bouncetime is set by the frequency parameter, if this parameter is empty, the default bouncetime would be 200 keytosearch = hardwaremod.HW_CTRL_FREQ frequency = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) if frequency == "": bouncetimeINT = 200 else: frequencyINT = hardwaremod.toint(frequency, 5) bouncetimeINT = 1000 / frequencyINT # this is ok to be trunk of the int. For frequencies higher than 1000 the bouncetime is exactly zero # RPI.GPIO library does not accept bouncetime=0, it gives runtime error if bouncetimeINT <= 0: bouncetimeINT = 1 hardwaremod.GPIO_add_event_detect(PINstr, evenslopetype, eventcallback, bouncetimeINT) # set fast reference call indexed with the PIN number which is the variable used when interrupt is called: # search now to avoid searching later global PIN_attributes PIN = hardwaremod.toint(PINstr, 0) statusdataDBmod.write_status_data(PIN_attributes, PIN, "logic", logic) recordkey = hardwaremod.HW_CTRL_PIN recordvalue = PINstr keytosearch = hardwaremod.HW_INFO_NAME refsensor = hardwaremod.searchdata( recordkey, recordvalue, keytosearch) # return first occurence statusdataDBmod.write_status_data(PIN_attributes, PIN, "refsensor", refsensor) return ""