From fa5e6735edababe8f1d429ec98162fb7d508e1e0 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 12 Sep 2020 20:03:51 +0300 Subject: using libgpiod for the serial hid --- kvmd/apps/cleanup/__init__.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py index 5b6f2860..ce321f42 100644 --- a/kvmd/apps/cleanup/__init__.py +++ b/kvmd/apps/cleanup/__init__.py @@ -44,10 +44,6 @@ def _clear_gpio(config: Section) -> None: with gpio.bcm(): for (name, pin) in [ - *([ - ("hid_serial/reset", config.hid.reset_pin), - ] if config.hid.type == "serial" else []), - *([ ("atx_gpio/power_switch", config.atx.power_switch_pin), ("atx_gpio/reset_switch", config.atx.reset_switch_pin), -- cgit v1.2.3 From bddabc4742ebd130020efc14c53675bf5c96e134 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 12 Sep 2020 22:16:14 +0300 Subject: using libgpiod for the relay msd --- kvmd/apps/cleanup/__init__.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py index ce321f42..795841c5 100644 --- a/kvmd/apps/cleanup/__init__.py +++ b/kvmd/apps/cleanup/__init__.py @@ -48,11 +48,6 @@ def _clear_gpio(config: Section) -> None: ("atx_gpio/power_switch", config.atx.power_switch_pin), ("atx_gpio/reset_switch", config.atx.reset_switch_pin), ] if config.atx.type == "gpio" else []), - - *([ - ("msd_relay/target", config.msd.target_pin), - ("msd_relay/reset", config.msd.reset_pin), - ] if config.msd.type == "relay" else []), ]: if pin >= 0: logger.info("Writing 0 to GPIO pin=%d (%s)", pin, name) -- cgit v1.2.3 From 002823b6e1ae6a261e77ee83b358307c682ce65a Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sun, 13 Sep 2020 10:47:53 +0300 Subject: using libgpiod for the gpio atx --- kvmd/apps/cleanup/__init__.py | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py index 795841c5..ec6a43c6 100644 --- a/kvmd/apps/cleanup/__init__.py +++ b/kvmd/apps/cleanup/__init__.py @@ -33,30 +33,10 @@ from ...logging import get_logger from ...yamlconf import Section -from ... import gpio - from .. import init # ===== -def _clear_gpio(config: Section) -> None: - logger = get_logger(0) - - with gpio.bcm(): - for (name, pin) in [ - *([ - ("atx_gpio/power_switch", config.atx.power_switch_pin), - ("atx_gpio/reset_switch", config.atx.reset_switch_pin), - ] if config.atx.type == "gpio" else []), - ]: - if pin >= 0: - logger.info("Writing 0 to GPIO pin=%d (%s)", pin, name) - try: - gpio.set_output(pin, False) - except Exception: - logger.exception("Can't clear GPIO pin=%d (%s)", pin, name) - - def _kill_streamer(config: Section) -> None: logger = get_logger(0) @@ -99,17 +79,12 @@ def main(argv: Optional[List[str]]=None) -> None: prog="kvmd-cleanup", description="Kill KVMD and clear resources", argv=argv, - load_hid=True, - load_atx=True, - load_msd=True, - load_gpio=True, )[2].kvmd logger = get_logger(0) logger.info("Cleaning up ...") for method in [ - _clear_gpio, _kill_streamer, _remove_sockets, ]: -- cgit v1.2.3 From 5ed0c27f1f7201783d60e035ba26f35f62539a08 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sun, 13 Sep 2020 21:43:52 +0300 Subject: removed rpi.gpio --- kvmd/apps/kvmd/__init__.py | 79 ++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index e257145d..bd08e157 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -25,8 +25,6 @@ from typing import Optional from ...logging import get_logger -from ... import gpio - from ...plugins.hid import get_hid_class from ...plugins.atx import get_atx_class from ...plugins.msd import get_msd_class @@ -45,6 +43,8 @@ from .server import KvmdServer # ===== def main(argv: Optional[List[str]]=None) -> None: + # pylint: disable=protected-access + config = init( prog="kvmd", description="The main Pi-KVM daemon", @@ -56,48 +56,45 @@ def main(argv: Optional[List[str]]=None) -> None: load_gpio=True, )[2] - with gpio.bcm(): - # pylint: disable=protected-access - - msd_kwargs = config.kvmd.msd._unpack(ignore=["type"]) - if config.kvmd.msd.type == "otg": - msd_kwargs["gadget"] = config.otg.gadget # XXX: Small crutch to pass gadget name to plugin - - global_config = config - config = config.kvmd - - hid = get_hid_class(config.hid.type)(**config.hid._unpack(ignore=["type", "keymap"])) - streamer = Streamer(**config.streamer._unpack()) - - KvmdServer( - auth_manager=AuthManager( - internal_type=config.auth.internal.type, - internal_kwargs=config.auth.internal._unpack(ignore=["type", "force_users"]), - external_type=config.auth.external.type, - external_kwargs=(config.auth.external._unpack(ignore=["type"]) if config.auth.external.type else {}), - force_internal_users=config.auth.internal.force_users, - enabled=config.auth.enabled, - ), - info_manager=InfoManager(global_config), - log_reader=LogReader(), - wol=WakeOnLan(**config.wol._unpack()), - user_gpio=UserGpio(config.gpio), - + msd_kwargs = config.kvmd.msd._unpack(ignore=["type"]) + if config.kvmd.msd.type == "otg": + msd_kwargs["gadget"] = config.otg.gadget # XXX: Small crutch to pass gadget name to plugin + + global_config = config + config = config.kvmd + + hid = get_hid_class(config.hid.type)(**config.hid._unpack(ignore=["type", "keymap"])) + streamer = Streamer(**config.streamer._unpack()) + + KvmdServer( + auth_manager=AuthManager( + internal_type=config.auth.internal.type, + internal_kwargs=config.auth.internal._unpack(ignore=["type", "force_users"]), + external_type=config.auth.external.type, + external_kwargs=(config.auth.external._unpack(ignore=["type"]) if config.auth.external.type else {}), + force_internal_users=config.auth.internal.force_users, + enabled=config.auth.enabled, + ), + info_manager=InfoManager(global_config), + log_reader=LogReader(), + wol=WakeOnLan(**config.wol._unpack()), + user_gpio=UserGpio(config.gpio), + + hid=hid, + atx=get_atx_class(config.atx.type)(**config.atx._unpack(ignore=["type"])), + msd=get_msd_class(config.msd.type)(**msd_kwargs), + streamer=streamer, + + snapshoter=Snapshoter( hid=hid, - atx=get_atx_class(config.atx.type)(**config.atx._unpack(ignore=["type"])), - msd=get_msd_class(config.msd.type)(**msd_kwargs), streamer=streamer, + **config.snapshot._unpack(), + ), - snapshoter=Snapshoter( - hid=hid, - streamer=streamer, - **config.snapshot._unpack(), - ), - - heartbeat=config.server.heartbeat, - sync_chunk_size=config.server.sync_chunk_size, + heartbeat=config.server.heartbeat, + sync_chunk_size=config.server.sync_chunk_size, - keymap_path=config.hid.keymap, - ).run(**config.server._unpack(ignore=["heartbeat", "sync_chunk_size"])) + keymap_path=config.hid.keymap, + ).run(**config.server._unpack(ignore=["heartbeat", "sync_chunk_size"])) get_logger(0).info("Bye-bye") -- cgit v1.2.3 From 91eb257f3df32487d00ca457f9d78eabd354ce54 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sun, 13 Sep 2020 21:59:09 +0300 Subject: non-cas operation --- kvmd/apps/kvmd/ugpio.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index f2ff2b1b..66fa5c70 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -201,10 +201,9 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes @aiotools.atomic async def __inner_switch(self, state: bool) -> None: - if state != self.__read(): - self.__write(state) - get_logger(0).info("Switched %s to state=%d", self, state) - await asyncio.sleep(self.__busy_delay) + self.__write(state) + get_logger(0).info("Ensured switch %s to state=%d", self, state) + await asyncio.sleep(self.__busy_delay) @aiotools.atomic async def __inner_pulse(self, delay: float) -> None: -- cgit v1.2.3 From 00069931c181a672c7f709d9a76892e575a964f7 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Wed, 16 Sep 2020 00:03:44 +0300 Subject: debounce for gpiod AioReader --- kvmd/apps/__init__.py | 4 +++- kvmd/apps/kvmd/ugpio.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index ac140466..ccede372 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -227,7 +227,9 @@ def _patch_dynamic( # pylint: disable=too-many-locals "min_delay": Option(0.1, type=valid_float_f01), "max_delay": Option(0.1, type=valid_float_f01), }, - } if mode == UserGpioModes.OUTPUT else {}) + } if mode == UserGpioModes.OUTPUT else { # input + "debounce": Option(0.1, type=valid_float_f0), + }) } rebuild = True diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index 66fa5c70..cb328115 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -81,7 +81,7 @@ class _GpioInput: self.__inverted: bool = config.inverted self.__driver = driver - self.__driver.register_input(self.__pin) + self.__driver.register_input(self.__pin, config.debounce) def get_scheme(self) -> Dict: return { -- cgit v1.2.3