Adding interrupt callback for gpio pin P9_24 like this
class Birdemke:
...
def __init__(self):
#initializatioin of variables
...
self.count = 0
def startReadingValue(self):
self.count = 0
Gpio.add_event_detect("P9_24", Gpio.RISING, self.readValueFromSensor, 0)
def pauseReadingValue(self):
Gpio.remove_event_detect("P9_24")
def readValueFromSensor(self):
self.count += 1
#reads value from i2c
...
this Birdemke class is being called from server using bottle. Calls startReadingValue()
to add and calls pauseReadingValue()
to make program unresponsive for rising edge. When removing event detect sometimes program is giving AttributeError at line self.count += 1
that count variable is not defined and segmentation fault error at Gpio.remove_event_detect("P9_24")
line [after changing adding line on top of self.count if hasattr(self,'count')
].