From fdc0e3e5fd7a0aa22ef18a19e8a266ce3397f2b6 Mon Sep 17 00:00:00 2001 From: Sadek Baroudi Date: Sun, 23 May 2021 02:18:26 -0700 Subject: [PATCH] adding support for updating LEDs based on incoming data from a client on the computer --- users/sadekbaroudi/hid.c | 38 +++++++++++++++++++++++++++++++++++++ users/sadekbaroudi/hid.h | 2 ++ users/sadekbaroudi/rules.mk | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 users/sadekbaroudi/hid.c create mode 100644 users/sadekbaroudi/hid.h diff --git a/users/sadekbaroudi/hid.c b/users/sadekbaroudi/hid.c new file mode 100644 index 0000000000..20e309ef70 --- /dev/null +++ b/users/sadekbaroudi/hid.c @@ -0,0 +1,38 @@ +#include "hid.h" +#include "raw_hid.h" +#include +#include +#include "rgblight.h" + +#define RAW_EPSIZE 32 + +__attribute__((weak)) bool raw_hid_receive_keymap(uint8_t *data, uint8_t length) { return false; } + +void raw_hid_receive(uint8_t *data, uint8_t length) { + if (raw_hid_receive_keymap(data, length)) { + return; + } + + // Send back the data to debug/validate on the client. This code can be removed once confirmed stable + raw_hid_send(data, length); + + for (int i = 0; i < length; i++) { + if (i < RGBLED_NUM) { + if (data[i] != 0) { + rgblight_sethsv_at(data[i], 255, 255, i); + } + } + } + + // // Example code if you want to send back a response to the client to use for whatever reason + // uint8_t response[RAW_EPSIZE]; + // memset(response, 0, RAW_EPSIZE); + + // if (data[0] == 0x02) { + // response[0] = 'Y'; + // } else { + // response[0] = 'N'; + // } + // raw_hid_send(response, sizeof(response)); + +} \ No newline at end of file diff --git a/users/sadekbaroudi/hid.h b/users/sadekbaroudi/hid.h new file mode 100644 index 0000000000..9390312139 --- /dev/null +++ b/users/sadekbaroudi/hid.h @@ -0,0 +1,2 @@ +void raw_hid_receive(uint8_t *data, uint8_t length); +void raw_hid_send(uint8_t *data, uint8_t length); \ No newline at end of file diff --git a/users/sadekbaroudi/rules.mk b/users/sadekbaroudi/rules.mk index 25d7d9c9a1..d37bb8af5f 100755 --- a/users/sadekbaroudi/rules.mk +++ b/users/sadekbaroudi/rules.mk @@ -9,6 +9,7 @@ SWAP_HANDS_ENABLE= no # Allow swapping hands of keyboard MOUSEKEY_ENABLE = yes BACKLIGHT_ENABLE = no NKRO_ENABLE = no +RAW_ENABLE = yes EXTRAFLAGS += -flto @@ -43,3 +44,6 @@ ifdef CONSOLE_ENABLE endif endif +ifeq ($(strip $(RAW_ENABLE)), yes) + SRC += hid.c +endif