mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
improved hid protocol
This commit is contained in:
parent
f78d45f4a6
commit
76b95ddfa8
@ -1,7 +1,4 @@
|
||||
all:
|
||||
@ cat Makefile
|
||||
|
||||
build:
|
||||
platformio run
|
||||
|
||||
update:
|
||||
@ -16,3 +13,6 @@ serial:
|
||||
|
||||
clean:
|
||||
rm -rf .pioenvs .piolibdeps
|
||||
|
||||
help:
|
||||
@ cat Makefile
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#define INLINE inline __attribute__((always_inline))
|
||||
|
||||
@ -4,14 +4,17 @@
|
||||
#include "inline.h"
|
||||
#include "keymap.h"
|
||||
|
||||
#define CMD_SERIAL Serial1
|
||||
#define CMD_SERIAL_SPEED 115200
|
||||
|
||||
#define CMD_SERIAL Serial1
|
||||
#define CMD_SERIAL_SPEED 115200
|
||||
|
||||
#define CMD_MOUSE_LEFT 0b10000000
|
||||
#define CMD_MOUSE_LEFT_STATE 0b00001000
|
||||
#define CMD_MOUSE_RIGHT 0b01000000
|
||||
#define CMD_MOUSE_RIGHT_STATE 0b00000100
|
||||
|
||||
#define REPORT_INTERVAL 100
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
INLINE void cmdResetHid() { // 0 bytes
|
||||
@ -80,10 +83,12 @@ void setup() {
|
||||
CMD_SERIAL.begin(CMD_SERIAL_SPEED);
|
||||
BootKeyboard.begin();
|
||||
SingleAbsoluteMouse.begin();
|
||||
CMD_SERIAL.write(0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static unsigned long last_report = 0;
|
||||
bool cmd_processed = false;
|
||||
|
||||
if (CMD_SERIAL.available() >= 5) {
|
||||
switch ((uint8_t)CMD_SERIAL.read()) {
|
||||
case 0: cmdResetHid(); break;
|
||||
@ -93,6 +98,16 @@ void loop() {
|
||||
case 4: cmdMouseWheelEvent(); break;
|
||||
default: break;
|
||||
}
|
||||
cmd_processed = true;
|
||||
}
|
||||
|
||||
unsigned long now = millis();
|
||||
if (
|
||||
cmd_processed
|
||||
|| (now >= last_report && now - last_report >= REPORT_INTERVAL)
|
||||
|| (now < last_report && ((unsigned long) -1) - last_report + now >= REPORT_INTERVAL)
|
||||
) {
|
||||
CMD_SERIAL.write(0);
|
||||
last_report = now;
|
||||
}
|
||||
}
|
||||
|
||||
13
kvmd/hid.py
13
kvmd/hid.py
@ -153,13 +153,14 @@ class Hid(multiprocessing.Process):
|
||||
else:
|
||||
raise RuntimeError("Unknown HID event")
|
||||
hid_ready = False
|
||||
|
||||
if tty.in_waiting:
|
||||
while tty.in_waiting:
|
||||
tty.read(tty.in_waiting)
|
||||
hid_ready = True
|
||||
else:
|
||||
if tty.in_waiting:
|
||||
while tty.in_waiting:
|
||||
tty.read(tty.in_waiting)
|
||||
hid_ready = True
|
||||
else:
|
||||
time.sleep(0.05)
|
||||
time.sleep(0.05)
|
||||
|
||||
if self.__stop_event.is_set() and self.__queue.qsize() == 0:
|
||||
break
|
||||
except Exception:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user