blob: 32c14c144958c7193b97dc897c963de63dc16366 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}
}
}
|