summaryrefslogtreecommitdiff
path: root/hid/src/main.cpp
blob: 631925f0d0b71faaf80edd2e45174e8b12713e3c (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
39
40
41
42
43
44
45
46
47
#include <Arduino.h>
#include <HID-Project.h>

#include "inline.h"
#include "keymap.h"

#define CMD_SERIAL Serial1
#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 = 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(CMD_SERIAL_SPEED);
	Keyboard.begin();
}

void loop() {
	if (CMD_SERIAL.available() >= 4) {
		switch ((uint8_t)CMD_SERIAL.read()) {
			case 0: cmdResetHid(); break;
			case 1: cmdKeyEvent(); break;
			default: break;
		}
	}
}