arduino-based hid

This commit is contained in:
Devaev Maxim
2018-07-11 00:06:56 +00:00
parent db56bf90db
commit 008b9ca2f2
14 changed files with 252 additions and 201 deletions

2
hid/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/.pioenvs/
/.piolibdeps/

17
hid/Makefile Normal file
View File

@@ -0,0 +1,17 @@
all:
@ cat Makefile
build:
platformio run
update:
platformio platform update
upload:
platformio run --target upload
serial:
platformio serialports monitor
clean:
rm -rf .pioenvs .piolibdeps

16
hid/platformio.ini Normal file
View File

@@ -0,0 +1,16 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:micro]
platform = atmelavr
board = micro
framework = arduino
upload_port = /dev/ttyACM0
monitor_baud = 115200

38
hid/src/main.cpp Normal file
View File

@@ -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;
}
}
}