record atx actions

This commit is contained in:
Maxim Devaev 2021-09-20 07:15:56 +03:00
parent 701df3c76f
commit 8ab9c8f07b
5 changed files with 29 additions and 4 deletions

View File

@ -437,7 +437,7 @@
</li>
<li class="right"><a class="menu-button" href="#"><img class="led-gray" data-dont-hide-menu id="hid-recorder-led" src="/share/svg/led-gear.svg">Macro</a>
<div class="menu" data-dont-hide-menu>
<div class="text"><b>Record and play HID/GPIO actions<br></b><sub>For security reasons, the record will not be saved on the PiKVM</sub></div>
<div class="text"><b>Record and play HID/ATX/GPIO actions<br></b><sub>For security reasons, the record will not be saved on the PiKVM</sub></div>
<hr>
<div class="buttons buttons-row">
<button class="row25" disabled data-force-hide-menu id="hid-recorder-record">&bull; Rec</button>

View File

@ -4,7 +4,7 @@ li(class="right")
| Macro
div(data-dont-hide-menu class="menu")
div(class="text")
b Record and play HID/GPIO actions#[br]
b Record and play HID/ATX/GPIO actions#[br]
sub For security reasons, the record will not be saved on the PiKVM
hr
div(class="buttons buttons-row")

View File

@ -27,7 +27,7 @@ import {tools, $} from "../tools.js";
import {wm} from "../wm.js";
export function Atx() {
export function Atx(__recorder) {
var self = this;
/************************************************************************/
@ -82,6 +82,7 @@ export function Atx() {
}
}
});
__recorder.recordAtxButtonEvent(button);
};
if ($("atx-ask-switch").checked) {

View File

@ -71,6 +71,10 @@ export function Recorder() {
__recordEvent({"event_type": "print", "event": {"text": text}});
};
self.recordAtxButtonEvent = function(button) {
__recordEvent({"event_type": "atx_button", "event": {"button": button}});
};
self.recordGpioSwitchEvent = function(channel, to) {
__recordEvent({"event_type": "gpio_switch", "event": {"channel": channel, "state": to}});
};
@ -171,6 +175,8 @@ export function Recorder() {
__checkType(event.event.delta, "object", "Non-object mouse wheel delta");
__checkInt(event.event.delta.x, "Non-int mouse delta X");
__checkInt(event.event.delta.y, "Non-int mouse delta Y");
} else if (event.event_type === "atx_button") {
__checkType(event.event.button, "string", "Non-string ATX button");
} else if (event.event_type === "gpio_switch") {
__checkType(event.event.channel, "string", "Non-string GPIO channel");
__checkType(event.event.state, "boolean", "Non-bool GPIO state");
@ -212,9 +218,11 @@ export function Recorder() {
while (index < __events.length) {
__setCounters(__events.length - index + 1, __events_time - time);
let event = __events[index];
if (event.event_type === "delay") {
__play_timer = setTimeout(() => __runEvents(index + 1, time + event.event.millis), event.event.millis);
return;
} else if (event.event_type === "print") {
let http = tools.makeRequest("POST", "/api/hid/print?limit=0", function() {
if (http.readyState === 4) {
@ -230,6 +238,20 @@ export function Recorder() {
}
}, event.event.text, "text/plain");
return;
} else if (event.event_type === "atx_button") {
let http = tools.makeRequest("POST", `/api/atx/click?button=${event.event.button}`, function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("ATX error:<br>", http.responseText);
__stopProcess();
} else if (http.status === 200) {
__play_timer = setTimeout(() => __runEvents(index + 1, time), 0);
}
}
});
return;
} else if (["gpio_switch", "gpio_pulse"].includes(event.event_type)) {
let path = "/api/gpio";
if (event.event_type === "gpio_switch") {
@ -248,9 +270,11 @@ export function Recorder() {
}
});
return;
} else if (["key", "mouse_button", "mouse_move", "mouse_wheel"].includes(event.event_type)) {
__ws.send(JSON.stringify(event));
}
index += 1;
}
if ($("hid-recorder-loop-switch").checked) {

View File

@ -47,7 +47,7 @@ export function Session() {
var __streamer = new Streamer();
var __recorder = new Recorder();
var __hid = new Hid(__streamer.getResolution, __recorder);
var __atx = new Atx();
var __atx = new Atx(__recorder);
var __msd = new Msd();
var __gpio = new Gpio(__recorder);