From 55f6956c2bf5057d4069d297ec8887926adacbd8 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Tue, 22 Sep 2020 04:42:22 +0300 Subject: confirmations for gpio --- kvmd/apps/kvmd/ugpio.py | 60 ++++++++++++++++++++++++++------------ testenv/v2-hdmi-rpi4.override.yaml | 4 +-- web/share/js/kvm/gpio.js | 40 ++++++++++++++++++++----- 3 files changed, 75 insertions(+), 29 deletions(-) diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index cb328115..d4e9d0af 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -322,29 +322,51 @@ class UserGpio: items: List[Dict] = [] for item in map(str.strip, row): if item.startswith("#") or len(item) == 0: - items.append({ - "type": "label", - "text": item[1:].strip(), - }) + items.append(self.__make_view_label(item)) else: - parts = list(map(str.strip, item.split("|", 1))) + parts = list(map(str.strip, item.split("|", 2))) if parts: - channel: str = parts[0] - param: Optional[str] = (parts[1] if len(parts) > 1 else None) - if channel in self.__inputs: - items.append({ - "type": UserGpioModes.INPUT, - "channel": channel, - "color": (param if param in ["green", "yellow", "red"] else "green"), - }) - elif channel in self.__outputs: - items.append({ - "type": UserGpioModes.OUTPUT, - "channel": parts[0], - "text": (param if param is not None else "Click"), - }) + if parts[0] in self.__inputs: + items.append(self.__make_view_input(parts)) + elif parts[0] in self.__outputs: + items.append(self.__make_view_output(parts)) table.append(items) + return { "header": self.__view["header"], "table": table, } + + def __make_view_label(self, item: str) -> Dict: + assert item.startswith("#") + return { + "type": "label", + "text": item[1:].strip(), + } + + def __make_view_input(self, parts: List[str]) -> Dict: + assert len(parts) >= 1 + color = (parts[1] if len(parts) > 1 else None) + if color not in ["green", "yellow", "red"]: + color = "green" + return { + "type": UserGpioModes.INPUT, + "channel": parts[0], + "color": color, + } + + def __make_view_output(self, parts: List[str]) -> Dict: + assert len(parts) >= 1 + confirm = False + text = "Click" + if len(parts) == 2: + text = parts[1] + elif len(parts) == 3: + confirm = (parts[1] == "confirm") + text = parts[2] + return { + "type": UserGpioModes.OUTPUT, + "channel": parts[0], + "confirm": confirm, + "text": text, + } diff --git a/testenv/v2-hdmi-rpi4.override.yaml b/testenv/v2-hdmi-rpi4.override.yaml index a8f361b3..2d2bf678 100644 --- a/testenv/v2-hdmi-rpi4.override.yaml +++ b/testenv/v2-hdmi-rpi4.override.yaml @@ -84,11 +84,11 @@ kvmd: - ["#Generic GPIO leds"] - [] - ["#Test 1:", led1, button1] - - ["#Test 2:", led2, button2] + - ["#Test 2:", led2, button2|confirm|Click] - [] - ["#HID Relays /dev/hidraw0"] - [] - - ["#Relay #1:", "relay1|Boop 0.1"] + - ["#Relay #1:", "relay1|confirm|Boop 0.1"] - ["#Relay #2:", "relay2|Boop 2.0"] vnc: diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js index e7b3c9e1..a67224b7 100644 --- a/web/share/js/kvm/gpio.js +++ b/web/share/js/kvm/gpio.js @@ -96,11 +96,11 @@ export function Gpio() { for (let channel in model.scheme.outputs) { let el = $(`gpio-switch-${channel}`); if (el) { - tools.setOnClick(el, () => __switchChannel(channel)); + tools.setOnClick(el, () => __switchChannel(el)); } el = $(`gpio-button-${channel}`); if (el) { - tools.setOnClick(el, () => __pulseChannel(channel)); + tools.setOnClick(el, () => __pulseChannel(el)); } } @@ -120,7 +120,8 @@ export function Gpio() { if (item.scheme["switch"]) { controls.push(`
- +