diff options
author | Devaev Maxim <[email protected]> | 2020-09-16 00:03:44 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-09-16 00:03:44 +0300 |
commit | 00069931c181a672c7f709d9a76892e575a964f7 (patch) | |
tree | d77779a938718e2d6e95269adeac5ab581af8ca3 /kvmd/plugins/ugpio | |
parent | 7cdf5976a8c0f0e020847413f4f8d64cb8e797f7 (diff) |
debounce for gpiod AioReader
Diffstat (limited to 'kvmd/plugins/ugpio')
-rw-r--r-- | kvmd/plugins/ugpio/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/plugins/ugpio/gpio.py | 13 | ||||
-rw-r--r-- | kvmd/plugins/ugpio/hidrelay.py | 2 |
3 files changed, 8 insertions, 9 deletions
diff --git a/kvmd/plugins/ugpio/__init__.py b/kvmd/plugins/ugpio/__init__.py index 9ed48a5f..c280b2a8 100644 --- a/kvmd/plugins/ugpio/__init__.py +++ b/kvmd/plugins/ugpio/__init__.py @@ -74,7 +74,7 @@ class BaseUserGpioDriver(BasePlugin): def get_modes(cls) -> Set[str]: return set(UserGpioModes.ALL) - def register_input(self, pin: int) -> None: + def register_input(self, pin: int, debounce: float) -> None: raise NotImplementedError def register_output(self, pin: int, initial: Optional[bool]) -> None: diff --git a/kvmd/plugins/ugpio/gpio.py b/kvmd/plugins/ugpio/gpio.py index 16e0b516..4b951057 100644 --- a/kvmd/plugins/ugpio/gpio.py +++ b/kvmd/plugins/ugpio/gpio.py @@ -21,7 +21,6 @@ from typing import Dict -from typing import Set from typing import Optional import gpiod @@ -42,26 +41,26 @@ class Plugin(BaseUserGpioDriver): super().__init__(instance_name, notifier) - self.__input_pins: Set[int] = set() + self.__input_pins: Dict[int, aiogp.AioReaderPinParams] = {} self.__output_pins: Dict[int, Optional[bool]] = {} - self.__reader: Optional[aiogp.AioPinsReader] = None + self.__reader: Optional[aiogp.AioReader] = None self.__chip: Optional[gpiod.Chip] = None self.__output_lines: Dict[int, gpiod.Line] = {} - def register_input(self, pin: int) -> None: - self.__input_pins.add(pin) + def register_input(self, pin: int, debounce: float) -> None: + self.__input_pins[pin] = aiogp.AioReaderPinParams(False, debounce) def register_output(self, pin: int, initial: Optional[bool]) -> None: self.__output_pins[pin] = initial def prepare(self) -> None: assert self.__reader is None - self.__reader = aiogp.AioPinsReader( + self.__reader = aiogp.AioReader( path=aiogp.DEVICE_PATH, consumer="kvmd/ugpio-gpio/inputs", - pins=dict.fromkeys(self.__input_pins, False), + pins=self.__input_pins, notifier=self._notifier, ) diff --git a/kvmd/plugins/ugpio/hidrelay.py b/kvmd/plugins/ugpio/hidrelay.py index b7f88cb8..32c4a3eb 100644 --- a/kvmd/plugins/ugpio/hidrelay.py +++ b/kvmd/plugins/ugpio/hidrelay.py @@ -79,7 +79,7 @@ class Plugin(BaseUserGpioDriver): def get_modes(cls) -> Set[str]: return set([UserGpioModes.OUTPUT]) - def register_input(self, pin: int) -> None: + def register_input(self, pin: int, debounce: float) -> None: raise RuntimeError(f"Unsupported mode 'input' for pin={pin} on {self}") def register_output(self, pin: int, initial: Optional[bool]) -> None: |