v3 usb breaker

This commit is contained in:
Devaev Maxim 2021-01-14 23:29:52 +03:00
parent 1799e34fd0
commit 8a45ce9146
4 changed files with 45 additions and 7 deletions

View File

@ -43,6 +43,13 @@ kvmd:
device: /dev/hidraw0 device: /dev/hidraw0
scheme: scheme:
__v3_usb_breaker__:
pin: 5
mode: output
initial: true
pulse:
delay: 0
led1: led1:
pin: 19 pin: 19
mode: input mode: input
@ -83,7 +90,7 @@ kvmd:
- ["#Generic GPIO leds"] - ["#Generic GPIO leds"]
- [] - []
- ["#Test 1:", led1, button1] - ["#Test 1:", led1, button1]
- ["#Test 2:", led2, button2|confirm|Click] - ["#Test 2:", led2, button2|confirm|Testing]
- [] - []
- ["#HID Relays /dev/hidraw0"] - ["#HID Relays /dev/hidraw0"]
- [] - []

View File

@ -196,6 +196,18 @@
</table> </table>
</div> </div>
<hr> <hr>
<div class="feature-disabled" id="v3-usb-breaker">
<table class="kv">
<td>Connect main USB to Server:</td>
<td align="right">
<div class="switch-box">
<input class="gpio-switch" disabled type="checkbox" id="gpio-switch-__v3_usb_breaker__" data-channel="__v3_usb_breaker__" data-confirm-off="Turning off this switch will disconnect the main USB&lt;br&gt;from the server. Are you sure you want to continue?">
<label for="gpio-switch-__v3_usb_breaker__"><span class="switch-inner"></span><span class="switch"></span></label>
</div>
</td>
</table>
<hr>
</div>
<div class="buttons buttons-row"> <div class="buttons buttons-row">
<button class="row50" data-force-hide-menu id="show-keyboard-button">&bull; Show keyboard</button> <button class="row50" data-force-hide-menu id="show-keyboard-button">&bull; Show keyboard</button>
<button class="row50" disabled id="hid-reset-button">Reset HID</button> <button class="row50" disabled id="hid-reset-button">Reset HID</button>

View File

@ -49,6 +49,19 @@ li(class="right")
hr hr
+menu_switch("hid-connect-switch", "Connect HID to Server", true, true) +menu_switch("hid-connect-switch", "Connect HID to Server", true, true)
hr hr
div(id="v3-usb-breaker" class="feature-disabled")
table(class="kv")
td Connect main USB to Server:
td(align="right")
div(class="switch-box")
-let msg = "Turning off this switch will disconnect the main USB<br>from the server."
-msg += " Are you sure you want to continue?"
input(disabled type="checkbox" id="gpio-switch-__v3_usb_breaker__" class="gpio-switch"
data-channel="__v3_usb_breaker__" data-confirm-off=msg)
label(for="gpio-switch-__v3_usb_breaker__")
span(class="switch-inner")
span(class="switch")
hr
div(class="buttons buttons-row") div(class="buttons buttons-row")
button(data-force-hide-menu id="show-keyboard-button" class="row50") &bull; Show keyboard button(data-force-hide-menu id="show-keyboard-button" class="row50") &bull; Show keyboard
button(disabled id="hid-reset-button" class="row50") Reset HID button(disabled id="hid-reset-button" class="row50") Reset HID

View File

@ -104,6 +104,8 @@ export function Gpio() {
} }
} }
tools.featureSetEnabled($("v3-usb-breaker"), ("__v3_usb_breaker__" in model.scheme.outputs));
self.setState(__state); self.setState(__state);
}; };
@ -121,11 +123,12 @@ export function Gpio() {
`; `;
} else if (item.type === "output") { } else if (item.type === "output") {
let controls = []; let controls = [];
let confirm = (item.confirm ? "Are you sure to act this control?" : "");
if (item.scheme["switch"]) { if (item.scheme["switch"]) {
controls.push(` controls.push(`
<td><div class="switch-box"> <td><div class="switch-box">
<input disabled type="checkbox" id="gpio-switch-${item.channel}" class="gpio-switch" <input disabled type="checkbox" id="gpio-switch-${item.channel}" class="gpio-switch"
data-channel="${item.channel}" data-confirm="${Number(item.confirm)}" /> data-channel="${item.channel}" data-confirm="${confirm}" />
<label for="gpio-switch-${item.channel}"> <label for="gpio-switch-${item.channel}">
<span class="switch-inner"></span> <span class="switch-inner"></span>
<span class="switch"></span> <span class="switch"></span>
@ -136,7 +139,7 @@ export function Gpio() {
if (item.scheme.pulse.delay) { if (item.scheme.pulse.delay) {
controls.push(` controls.push(`
<td><button disabled id="gpio-button-${item.channel}" class="gpio-button" <td><button disabled id="gpio-button-${item.channel}" class="gpio-button"
data-channel="${item.channel}" data-confirm="${Number(item.confirm)}">${item.text}</button></td> data-channel="${item.channel}" data-confirm="${confirm}">${item.text}</button></td>
`); `);
} }
return `<table><tr>${controls.join("<td>&nbsp;&nbsp;&nbsp;</td>")}</tr></table>`; return `<table><tr>${controls.join("<td>&nbsp;&nbsp;&nbsp;</td>")}</tr></table>`;
@ -158,11 +161,14 @@ export function Gpio() {
var __switchChannel = function(el) { var __switchChannel = function(el) {
let channel = el.getAttribute("data-channel"); let channel = el.getAttribute("data-channel");
let confirm = parseInt(el.getAttribute("data-confirm")); let confirm = el.getAttribute("data-confirm");
let to = ($(`gpio-switch-${channel}`).checked ? "1" : "0"); let to = ($(`gpio-switch-${channel}`).checked ? "1" : "0");
if (to === "0" && el.hasAttribute("data-confirm-off")) {
confirm = el.getAttribute("data-confirm-off");
}
let act = () => __sendPost(`/api/gpio/switch?channel=${channel}&state=${to}`); let act = () => __sendPost(`/api/gpio/switch?channel=${channel}&state=${to}`);
if (confirm) { if (confirm) {
wm.confirm("Are you sure to act this switch?").then(function(ok) { wm.confirm(confirm).then(function(ok) {
if (ok) { if (ok) {
act(); act();
} else { } else {
@ -176,10 +182,10 @@ export function Gpio() {
var __pulseChannel = function(el) { var __pulseChannel = function(el) {
let channel = el.getAttribute("data-channel"); let channel = el.getAttribute("data-channel");
let confirm = parseInt(el.getAttribute("data-confirm")); let confirm = el.getAttribute("data-confirm");
let act = () => __sendPost(`/api/gpio/pulse?channel=${channel}`); let act = () => __sendPost(`/api/gpio/pulse?channel=${channel}`);
if (confirm) { if (confirm) {
wm.confirm("Are you sure to click this button?").then(function(ok) { if (ok) act(); }); wm.confirm(confirm).then(function(ok) { if (ok) act(); });
} else { } else {
act(); act();
} }