def write(self, pin, value): """Write bool value to a pin. Args: pin (int): the pin to write to value (bool): boolean value to write to pin """ with self._gpio_lock: gpio_pin = GPIO(pin, "preserve") if value: gpio_pin.direction = "high" else: gpio_pin.direction = "low" gpio_pin.close() self.logger.debug("Wrote value to GPIO pin {}: {}".format( pin, value))
def interrupt(self, callback, pin, interrupt_trigger=None, timeout=0): """Init interrupt callback function for pin. Args: callback (function): function to call on interrupt pin (int): the pin to monitor for interrupts """ with self._gpio_lock: gpio_pin = GPIO(pin, "preserve") if gpio_pin.supports_interrupts: gpio_pin.direction = "in" gpio_pin.edge = interrupt_trigger if gpio_pin.poll(timeout): # Enter callback function pass gpio_pin.edge = "none" #need to set to none inorder to reuse pin for anything else else: self.logger.error( "GPIO pin {} does not support interrupts".format(pin)) self.logger.debug( "Set interrupt callback of GPIO pin {}".format(pin))