diff options
author | Devaev Maxim <[email protected]> | 2018-09-29 07:33:27 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-09-29 07:33:27 +0300 |
commit | 76b95ddfa8d60de4d29e270cbc74cfc8b5144538 (patch) | |
tree | 727412cdbab5d3cc87fc6a5d96ab34b7884d1d9c /hid/src | |
parent | f78d45f4a61a9d26f8ed2bbea44145096d80bea1 (diff) |
improved hid protocol
Diffstat (limited to 'hid/src')
-rw-r--r-- | hid/src/inline.h | 1 | ||||
-rw-r--r-- | hid/src/main.cpp | 21 |
2 files changed, 19 insertions, 3 deletions
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; } } |