led colors

This commit is contained in:
Devaev Maxim 2020-09-10 18:26:43 +03:00
parent 92ba157b67
commit bae65c35ee
2 changed files with 14 additions and 7 deletions

View File

@ -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 {

View File

@ -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}`);
}
};