summaryrefslogtreecommitdiff
path: root/kvmd/plugins
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-16 00:03:44 +0300
committerDevaev Maxim <[email protected]>2020-09-16 00:03:44 +0300
commit00069931c181a672c7f709d9a76892e575a964f7 (patch)
treed77779a938718e2d6e95269adeac5ab581af8ca3 /kvmd/plugins
parent7cdf5976a8c0f0e020847413f4f8d64cb8e797f7 (diff)
debounce for gpiod AioReader
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/atx/gpio.py19
-rw-r--r--kvmd/plugins/ugpio/__init__.py2
-rw-r--r--kvmd/plugins/ugpio/gpio.py13
-rw-r--r--kvmd/plugins/ugpio/hidrelay.py2
4 files changed, 21 insertions, 15 deletions
diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py
index 851e4ab4..b49dd689 100644
--- a/kvmd/plugins/atx/gpio.py
+++ b/kvmd/plugins/atx/gpio.py
@@ -34,6 +34,7 @@ from ... import aiogp
from ...yamlconf import Option
from ...validators.basic import valid_bool
+from ...validators.basic import valid_float_f0
from ...validators.basic import valid_float_f01
from ...validators.hw import valid_gpio_pin
@@ -47,9 +48,12 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
def __init__( # pylint: disable=too-many-arguments,super-init-not-called
self,
power_led_pin: int,
- hdd_led_pin: int,
power_led_inverted: bool,
+ power_led_debounce: float,
+
+ hdd_led_pin: int,
hdd_led_inverted: bool,
+ hdd_led_debounce: float,
power_switch_pin: int,
reset_switch_pin: int,
@@ -72,12 +76,12 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
self.__power_switch_line: Optional[gpiod.Line] = None
self.__reset_switch_line: Optional[gpiod.Line] = None
- self.__reader = aiogp.AioPinsReader(
+ self.__reader = aiogp.AioReader(
path=aiogp.DEVICE_PATH,
consumer="kvmd/atx-gpio/leds",
pins={
- power_led_pin: power_led_inverted,
- hdd_led_pin: hdd_led_inverted,
+ power_led_pin: aiogp.AioReaderPinParams(power_led_inverted, power_led_debounce),
+ hdd_led_pin: aiogp.AioReaderPinParams(hdd_led_inverted, hdd_led_debounce),
},
notifier=self.__notifier,
)
@@ -86,9 +90,12 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
def get_plugin_options(cls) -> Dict:
return {
"power_led_pin": Option(-1, type=valid_gpio_pin),
- "hdd_led_pin": Option(-1, type=valid_gpio_pin),
"power_led_inverted": Option(False, type=valid_bool),
- "hdd_led_inverted": Option(False, type=valid_bool),
+ "power_led_debounce": Option(0.1, type=valid_float_f0),
+
+ "hdd_led_pin": Option(-1, type=valid_gpio_pin),
+ "hdd_led_inverted": Option(False, type=valid_bool),
+ "hdd_led_debounce": Option(0.1, type=valid_float_f0),
"power_switch_pin": Option(-1, type=valid_gpio_pin),
"reset_switch_pin": Option(-1, type=valid_gpio_pin),
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: