diff options
-rw-r--r-- | kvmd/apps/kvmd/ugpio.py | 11 | ||||
-rw-r--r-- | web/share/js/kvm/gpio.js | 10 |
2 files changed, 14 insertions, 7 deletions
diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index e6723b3e..f2ff2b1b 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -330,16 +330,19 @@ class UserGpio: else: parts = list(map(str.strip, item.split("|", 1))) if parts: - if parts[0] in self.__inputs: + 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": parts[0], + "channel": channel, + "color": (param if param in ["green", "yellow", "red"] else "green"), }) - elif parts[0] in self.__outputs: + elif channel in self.__outputs: items.append({ "type": UserGpioModes.OUTPUT, "channel": parts[0], - "text": (parts[1] if len(parts) > 1 else "Click"), + "text": (param if param is not None else "Click"), }) table.append(items) return { diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js index cbbe219b..a412d579 100644 --- a/web/share/js/kvm/gpio.js +++ b/web/share/js/kvm/gpio.js @@ -109,7 +109,10 @@ export function Gpio() { if (item.type === "label") { return item.text; } else if (item.type === "input") { - return `<img id="gpio-led-${item.channel}" class="gpio-led inline-lamp-big led-gray" src="/share/svg/led-circle.svg" />`; + return ` + <img id="gpio-led-${item.channel}" class="gpio-led inline-lamp-big led-gray" + src="/share/svg/led-circle.svg" data-color="${item.color}" /> + `; } else if (item.type === "output") { let controls = []; if (item.scheme["switch"]) { @@ -135,12 +138,13 @@ export function Gpio() { }; var __setLedState = function(el, state) { + let color = el.getAttribute("data-color"); if (state) { - el.classList.add("led-green"); + el.classList.add(`led-${color}`); el.classList.remove("led-gray"); } else { el.classList.add("led-gray"); - el.classList.remove("led-green"); + el.classList.remove(`led-${color}`); } }; |