summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hid/Makefile6
-rw-r--r--hid/src/inline.h1
-rw-r--r--hid/src/main.cpp21
-rw-r--r--kvmd/hid.py13
4 files changed, 29 insertions, 12 deletions
diff --git a/hid/Makefile b/hid/Makefile
index 0d94b010..957c3a11 100644
--- a/hid/Makefile
+++ b/hid/Makefile
@@ -1,7 +1,4 @@
all:
- @ cat Makefile
-
-build:
platformio run
update:
@@ -16,3 +13,6 @@ serial:
clean:
rm -rf .pioenvs .piolibdeps
+
+help:
+ @ cat Makefile
diff --git a/hid/src/inline.h b/hid/src/inline.h
index 5b642a83..337aa9b9 100644
--- a/hid/src/inline.h
+++ b/hid/src/inline.h
@@ -1,3 +1,4 @@
#pragma once
+
#define INLINE inline __attribute__((always_inline))
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index 7bfced13..9fad576c 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -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;
}
}
diff --git a/kvmd/hid.py b/kvmd/hid.py
index b1d69ad6..e5d4de78 100644
--- a/kvmd/hid.py
+++ b/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: