diff options
author | Devaev Maxim <[email protected]> | 2018-07-11 05:29:30 +0000 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-07-11 05:29:30 +0000 |
commit | c6b6e54875158d22bee9cdd82f1342e1fc83724e (patch) | |
tree | 34d6b3890f7ff98a6269b64c6a30de73fdd6a5a0 /hid/src/main.cpp | |
parent | 157828997a9e756e58210804c4f3025dce57f853 (diff) |
using HID-Project library
Diffstat (limited to 'hid/src/main.cpp')
-rw-r--r-- | hid/src/main.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp index 32c14c14..631925f0 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -1,35 +1,44 @@ #include <Arduino.h> -#include <Keyboard.h> +#include <HID-Project.h> + +#include "inline.h" +#include "keymap.h" #define CMD_SERIAL Serial1 -#define SERIAL_SPEED 115200 +#define CMD_SERIAL_SPEED 115200 #define INLINE inline __attribute__((always_inline)) INLINE void cmdResetHid() { + CMD_SERIAL.read(); // unused now + CMD_SERIAL.read(); // unused now + CMD_SERIAL.read(); // unused now Keyboard.releaseAll(); } INLINE void cmdKeyEvent() { - uint8_t state = Serial.read(); - uint8_t key = Serial.read(); - if (state) { - Keyboard.press(key); - } else { - Keyboard.release(key); + uint8_t state = CMD_SERIAL.read(); + uint8_t code = keymap(CMD_SERIAL.read()); + CMD_SERIAL.read(); // unused now + if (code) { + if (state) { + Keyboard.press(code); + } else { + Keyboard.release(code); + } } } void setup() { - CMD_SERIAL.begin(SERIAL_SPEED); + CMD_SERIAL.begin(CMD_SERIAL_SPEED); Keyboard.begin(); } void loop() { - while (true) { // fast - switch (Serial.read()) { + if (CMD_SERIAL.available() >= 4) { + switch ((uint8_t)CMD_SERIAL.read()) { case 0: cmdResetHid(); break; case 1: cmdKeyEvent(); break; default: break; |