power: change gpiod line request based on version
For gpiod versions 1.3 or greater use the "default_val" keyword argument to set the default, otherwise use "default_vals". Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
9789b3d999
commit
ca27c2cf10
|
@ -462,6 +462,8 @@ class HTTPDevice(PowerDevice):
|
||||||
class GpioChipFactory:
|
class GpioChipFactory:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.chips: Dict[str, gpiod.Chip] = {}
|
self.chips: Dict[str, gpiod.Chip] = {}
|
||||||
|
version: str = gpiod.version_string()
|
||||||
|
self.gpiod_version = tuple(int(v) for v in version.split('.'))
|
||||||
|
|
||||||
def get_gpio_chip(self, chip_name) -> gpiod.Chip:
|
def get_gpio_chip(self, chip_name) -> gpiod.Chip:
|
||||||
if chip_name in self.chips:
|
if chip_name in self.chips:
|
||||||
|
@ -470,6 +472,9 @@ class GpioChipFactory:
|
||||||
self.chips[chip_name] = chip
|
self.chips[chip_name] = chip
|
||||||
return chip
|
return chip
|
||||||
|
|
||||||
|
def get_gpiod_version(self):
|
||||||
|
return self.gpiod_version
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
for chip in self.chips.values():
|
for chip in self.chips.values():
|
||||||
chip.close()
|
chip.close()
|
||||||
|
@ -493,15 +498,17 @@ class GpioDevice(PowerDevice):
|
||||||
try:
|
try:
|
||||||
chip = chip_factory.get_gpio_chip(chip_id)
|
chip = chip_factory.get_gpio_chip(chip_id)
|
||||||
self.line = chip.get_line(pin)
|
self.line = chip.get_line(pin)
|
||||||
|
args: Dict[str, Any] = {
|
||||||
|
'consumer': "moonraker",
|
||||||
|
'type': gpiod.LINE_REQ_DIR_OUT
|
||||||
|
}
|
||||||
if invert:
|
if invert:
|
||||||
self.line.request(
|
args['flags'] = gpiod.LINE_REQ_FLAG_ACTIVE_LOW
|
||||||
consumer="moonraker", type=gpiod.LINE_REQ_DIR_OUT,
|
if chip_factory.get_gpiod_version() < (1, 3):
|
||||||
flags=gpiod.LINE_REQ_FLAG_ACTIVE_LOW,
|
args['default_vals'] = [int(self.initial_state)]
|
||||||
default_vals=[int(self.initial_state)])
|
|
||||||
else:
|
else:
|
||||||
self.line.request(
|
args['default_val'] = int(self.initial_state)
|
||||||
consumer="moonraker", type=gpiod.LINE_REQ_DIR_OUT,
|
self.line.request(**args)
|
||||||
default_vals=[int(self.initial_state)])
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.state = "error"
|
self.state = "error"
|
||||||
logging.exception(
|
logging.exception(
|
||||||
|
@ -509,7 +516,6 @@ class GpioDevice(PowerDevice):
|
||||||
"use by another program or exported by sysfs.")
|
"use by another program or exported by sysfs.")
|
||||||
raise config.error("Power GPIO Config Error")
|
raise config.error("Power GPIO Config Error")
|
||||||
|
|
||||||
|
|
||||||
def _parse_pin(self, config: ConfigHelper) -> Tuple[int, str, bool]:
|
def _parse_pin(self, config: ConfigHelper) -> Tuple[int, str, bool]:
|
||||||
pin = cfg_pin = config.get("pin")
|
pin = cfg_pin = config.get("pin")
|
||||||
invert = False
|
invert = False
|
||||||
|
@ -578,10 +584,6 @@ class RFDevice(GpioDevice):
|
||||||
self.on = config.get("on_code").zfill(24)
|
self.on = config.get("on_code").zfill(24)
|
||||||
self.off = config.get("off_code").zfill(24)
|
self.off = config.get("off_code").zfill(24)
|
||||||
|
|
||||||
def initialize(self) -> None:
|
|
||||||
super().initialize()
|
|
||||||
self.set_power("on" if self.initial_state else "off")
|
|
||||||
|
|
||||||
def _transmit_digit(self, waveform) -> None:
|
def _transmit_digit(self, waveform) -> None:
|
||||||
self.line.set_value(1)
|
self.line.set_value(1)
|
||||||
time.sleep(waveform[0]*RFDevice.PULSE_LEN)
|
time.sleep(waveform[0]*RFDevice.PULSE_LEN)
|
||||||
|
|
Loading…
Reference in New Issue