diff options
author | Devaev Maxim <[email protected]> | 2019-04-16 01:16:37 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-16 01:16:42 +0300 |
commit | 33bf0e03d7bf6a81fc42ebf3416232ab8622a705 (patch) | |
tree | 6c5b1079eeb9e7d26756a5342ad74731881e528e | |
parent | 9f78c7e63782da3391d0196126a4e8a95c1442e6 (diff) |
supported not inverted leds
-rw-r--r-- | kvmd/apps/__init__.py | 8 | ||||
-rw-r--r-- | kvmd/apps/kvmd/atx.py | 18 |
2 files changed, 20 insertions, 6 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index eea8ea71..e95d19b9 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -183,11 +183,13 @@ def _get_config_scheme() -> Dict: "atx": { "enabled": Option(True, type=valid_bool), - "power_led_pin": Option(-1, type=valid_gpio_pin, only_if="enabled"), - "hdd_led_pin": Option(-1, type=valid_gpio_pin, only_if="enabled"), + "power_led_pin": Option(-1, type=valid_gpio_pin, only_if="enabled"), + "hdd_led_pin": Option(-1, type=valid_gpio_pin, only_if="enabled"), + "power_led_inverted": Option(True, type=valid_bool), + "hdd_led_inverted": Option(True, type=valid_bool), + "power_switch_pin": Option(-1, type=valid_gpio_pin, only_if="enabled"), "reset_switch_pin": Option(-1, type=valid_gpio_pin, only_if="enabled"), - "click_delay": Option(0.1, type=valid_float_f01), "long_click_delay": Option(5.5, type=valid_float_f01), diff --git a/kvmd/apps/kvmd/atx.py b/kvmd/apps/kvmd/atx.py index 1380ffce..a255611d 100644 --- a/kvmd/apps/kvmd/atx.py +++ b/kvmd/apps/kvmd/atx.py @@ -21,6 +21,7 @@ import asyncio +import operator from typing import Dict from typing import Callable @@ -60,12 +61,14 @@ def _atx_working(method: Callable) -> Callable: class Atx: # pylint: disable=too-many-instance-attributes - def __init__( + def __init__( # pylint: disable=too-many-arguments self, enabled: bool, power_led_pin: int, hdd_led_pin: int, + power_led_inverted: bool, + hdd_led_inverted: bool, power_switch_pin: int, reset_switch_pin: int, @@ -88,6 +91,9 @@ class Atx: # pylint: disable=too-many-instance-attributes self.__power_switch_pin = -1 self.__reset_switch_pin = -1 + self.__power_led_inverted = power_led_inverted + self.__hdd_led_inverted = hdd_led_inverted + self.__click_delay = click_delay self.__long_click_delay = long_click_delay @@ -96,12 +102,18 @@ class Atx: # pylint: disable=too-many-instance-attributes self.__region = aioregion.AioExclusiveRegion(AtxIsBusyError) def get_state(self) -> Dict: + if self._enabled: + power_led_state = operator.xor(self.__power_led_inverted, gpio.read(self.__power_led_pin)) + hdd_led_state = operator.xor(self.__hdd_led_inverted, gpio.read(self.__hdd_led_pin)) + else: + power_led_state = hdd_led_state = False + return { "enabled": self._enabled, "busy": self.__region.is_busy(), "leds": { - "power": ((not gpio.read(self.__power_led_pin)) if self._enabled else False), - "hdd": ((not gpio.read(self.__hdd_led_pin)) if self._enabled else False), + "power": power_led_state, + "hdd": hdd_led_state, }, } |