- raise NotImplementedError(
- "Internal pullups not supported in libgpiod, "
- "use physical resistor instead!"
- )
- if pull == self.PULL_DOWN:
- raise NotImplementedError(
- "Internal pulldowns not supported in libgpiod, "
- "use physical resistor instead!"
- )
- raise RuntimeError("Invalid pull for pin: %s" % self.id)
+ if hasattr(gpiod, 'line') and hasattr(gpiod.line, 'BIAS_PULL_UP') :
+ config = gpiod.line_request()
+ config.consumer = self._CONSUMER
+ config.request_type = gpiod.line.BIAS_PULL_UP
+ self._line.request(config)
+ else:
+ self._line.request(
+ consumer=self._CONSUMER, type=gpiod.LINE_REQ_DIR_IN, flags=flags
+ )
+ raise NotImplementedError(
+ "Internal pullups not supported in this version of libgpiod, "
+ "use physical resistor instead!"
+ )
+ elif pull == self.PULL_DOWN:
+ if hasattr(gpiod, 'line') and hasattr(gpiod.line, 'BIAS_PULL_DOWN') :
+ config = gpiod.line_request()
+ config.consumer = self._CONSUMER
+ config.request_type = gpiod.line.BIAS_PULL_DOWN
+ self._line.request(config)
+ else:
+ raise NotImplementedError(
+ "Internal pulldowns not supported in this version of libgpiod, "
+ "use physical resistor instead!"
+ )
+ elif pull == self.PULL_NONE:
+ if hasattr(gpiod, 'line') and hasattr(gpiod.line, 'BIAS_DISABLE') :
+ config = gpiod.line_request()
+ config.consumer = self._CONSUMER
+ config.request_type = gpiod.line.BIAS_DISABLE
+ self._line.request(config)
+ else:
+ raise RuntimeError(f"Invalid pull for pin: {self.id}")