summaryrefslogtreecommitdiff
path: root/hid/src
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-11 00:06:56 +0000
committerDevaev Maxim <[email protected]>2018-07-11 00:06:56 +0000
commit008b9ca2f2d7daf96e975635ddd4c38c35bb4bdb (patch)
tree5f8c9b8921efb1258922c468c5d1bfc3c2bfc9c1 /hid/src
parentdb56bf90db213f994dc3c433638dc497ead94096 (diff)
arduino-based hid
Diffstat (limited to 'hid/src')
-rw-r--r--hid/src/main.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
new file mode 100644
index 00000000..32c14c14
--- /dev/null
+++ b/hid/src/main.cpp
@@ -0,0 +1,38 @@
+#include <Arduino.h>
+#include <Keyboard.h>
+
+#define CMD_SERIAL Serial1
+#define SERIAL_SPEED 115200
+
+#define INLINE inline __attribute__((always_inline))
+
+
+INLINE void cmdResetHid() {
+ Keyboard.releaseAll();
+}
+
+INLINE void cmdKeyEvent() {
+ uint8_t state = Serial.read();
+ uint8_t key = Serial.read();
+ if (state) {
+ Keyboard.press(key);
+ } else {
+ Keyboard.release(key);
+ }
+}
+
+
+void setup() {
+ CMD_SERIAL.begin(SERIAL_SPEED);
+ Keyboard.begin();
+}
+
+void loop() {
+ while (true) { // fast
+ switch (Serial.read()) {
+ case 0: cmdResetHid(); break;
+ case 1: cmdKeyEvent(); break;
+ default: break;
+ }
+ }
+}