From a06a1e40f49787fc9f7c5e498f668e148ec35642 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 5 Sep 2020 12:23:39 +0300 Subject: using BatchReader for ATX --- kvmd/plugins/atx/gpio.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py index baea61be..d23c008c 100644 --- a/kvmd/plugins/atx/gpio.py +++ b/kvmd/plugins/atx/gpio.py @@ -71,9 +71,14 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes self.__click_delay = click_delay self.__long_click_delay = long_click_delay - self.__state_poll = state_poll + self.__state_notifier = aiotools.AioNotifier() + self.__region = aiotools.AioExclusiveRegion(AtxIsBusyError, self.__state_notifier) - self.__region = aiotools.AioExclusiveRegion(AtxIsBusyError) + self.__reader = gpio.BatchReader( + pins=[self.__power_led_pin, self.__hdd_led_pin], + interval=state_poll, + notifier=self.__state_notifier, + ) @classmethod def get_plugin_options(cls) -> Dict: @@ -96,8 +101,8 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes "enabled": True, "busy": self.__region.is_busy(), "leds": { - "power": (gpio.read(self.__power_led_pin) ^ self.__power_led_inverted), - "hdd": (gpio.read(self.__hdd_led_pin) ^ self.__hdd_led_inverted), + "power": (self.__reader.get(self.__power_led_pin) ^ self.__power_led_inverted), + "hdd": (self.__reader.get(self.__hdd_led_pin) ^ self.__hdd_led_inverted), }, } @@ -108,7 +113,10 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes if state != prev_state: yield state prev_state = state - await asyncio.sleep(self.__state_poll) + await self.__state_notifier.wait() + + async def systask(self) -> None: + await self.__reader.poll() async def cleanup(self) -> None: for (name, pin) in [ -- cgit v1.2.3