From afdba6115a5bdfa87f634bbf6c41402caaefa1b5 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Tue, 5 Nov 2019 19:02:07 +0900 Subject: feat: adds pairing key --- tmk_core/common/webusb.c | 24 ++++++++++++++++++++++++ tmk_core/common/webusb.h | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tmk_core/common/webusb.c create mode 100644 tmk_core/common/webusb.h (limited to 'tmk_core/common') diff --git a/tmk_core/common/webusb.c b/tmk_core/common/webusb.c new file mode 100644 index 0000000000..5183d77543 --- /dev/null +++ b/tmk_core/common/webusb.c @@ -0,0 +1,24 @@ +#include "webusb.h" +#include "wait.h" + +webusb_state_t webusb_state = { + .paired = false, + .pairing = false, +}; + +void webusb_set_pairing_state() { + webusb_state.pairing = true; + uint8_t tick = 0; + do { + tick++; + wait_ms(1000); + //TODO Blink some leds + } while(webusb_state.paired == false && tick <= 30); + webusb_state.pairing = false; +} + +void webusb_error(uint8_t code) { + uint8_t buffer[1]; + buffer[0] = code; + webusb_send(buffer, 1); +} diff --git a/tmk_core/common/webusb.h b/tmk_core/common/webusb.h new file mode 100644 index 0000000000..35d9610fc9 --- /dev/null +++ b/tmk_core/common/webusb.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +void webusb_receive(uint8_t *data, uint8_t length); +void webusb_send(uint8_t *data, uint8_t length); +void webusb_error(uint8_t); +void webusb_set_pairing_state(void); + +typedef struct{ + bool paired; + bool pairing; +} webusb_state_t; + +extern webusb_state_t webusb_state; + +enum Webusb_Status_Code { + WEBUSB_STATUS_NOT_PAIRED = -1, + WEBUSB_STATUS_OK, + WEBUSB_STATUS_UNKNOWN_COMMAND, +}; + + -- cgit v1.2.3