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