4     raise ImportError("libgpiod Python bindings not found, please install and try again! See https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh")
 
   6 # Pins dont exist in CPython so...lets make our own!
 
  15     _CONSUMER = 'adafruit_blinka'
 
  21     def __init__(self, pin_number, gpiod_chipname="gpiochip0"):
 
  22         self.id = int(pin_number)
 
  23         # FIXME: Presumably this might vary by system:
 
  24         self._chip = gpiod.Chip(gpiod_chipname, gpiod.Chip.OPEN_BY_NAME)
 
  30     def __eq__(self, other):
 
  31         return self.id == other
 
  33     def init(self, mode=IN, pull=None):
 
  35             self._line = self._chip.get_line(int(self.id))
 
  36             #print("init line: ", int(self.id), self._line)
 
  42                     if pull == self.PULL_UP:
 
  43                         raise NotImplementedError("Internal pullups not supported in libgpiod, use physical resistor instead!")
 
  44                     elif pull == self.PULL_DOWN:
 
  45                         raise NotImplementedError("Internal pulldowns not supported in libgpiod, use physical resistor instead!")                    
 
  47                         raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  51                 self._line.request(consumer=self._CONSUMER,
 
  52                                    type=gpiod.LINE_REQ_DIR_IN,
 
  55             elif mode == self.OUT:
 
  57                     raise RuntimeError("Cannot set pull resistor on output")
 
  60                 self._line.request(consumer=self._CONSUMER,
 
  61                                    type=gpiod.LINE_REQ_DIR_OUT)
 
  64                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  66     def value(self, val=None):
 
  68             if val in (self.LOW, self.HIGH):
 
  70                 self._line.set_value(val)
 
  72                 raise RuntimeError("Invalid value for pin")
 
  74             return self._line.get_value()