From 925c43c4c0e9360d2fe0032b3c41c2a84e1a4d8b Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Wed, 20 Nov 2019 09:41:42 +0900 Subject: feat: update examples + pairing process --- tmk_core/common/webusb.c | 32 ++++++++++++++++++++++---------- tmk_core/common/webusb.h | 13 +++++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/webusb.c b/tmk_core/common/webusb.c index 5183d77543..82e8fe1c83 100644 --- a/tmk_core/common/webusb.c +++ b/tmk_core/common/webusb.c @@ -6,16 +6,28 @@ webusb_state_t webusb_state = { .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_receive(uint8_t *data, uint8_t length) { + uint8_t command = data[0]; + + if(command == WEBUSB_CMD_PAIR && webusb_state.pairing == true) { + uint8_t event[3]; + webusb_state.pairing = false; + webusb_state.paired = true; + event[0] = WEBUSB_STATUS_OK; + event[1] = WEBUSB_EVT_PAIRED; + event[2] = WEBUSB_STOP_BIT; + webusb_send(event, sizeof(event)); + return; + } + + if(webusb_state.paired == true) { + switch(command) { + //Handle commands in here + } + } else { + webusb_error(WEBUSB_STATUS_NOT_PAIRED); + } +}; void webusb_error(uint8_t code) { uint8_t buffer[1]; diff --git a/tmk_core/common/webusb.h b/tmk_core/common/webusb.h index 35d9610fc9..c49a9f48a8 100644 --- a/tmk_core/common/webusb.h +++ b/tmk_core/common/webusb.h @@ -3,6 +3,10 @@ #include #include +#define WEBUSB_STOP_BIT -2 +#define WEBUSB_BLINK_STEPS 512 +#define WEBUSB_BLINK_END WEBUSB_BLINK_STEPS * 60 + void webusb_receive(uint8_t *data, uint8_t length); void webusb_send(uint8_t *data, uint8_t length); void webusb_error(uint8_t); @@ -21,4 +25,13 @@ enum Webusb_Status_Code { WEBUSB_STATUS_UNKNOWN_COMMAND, }; +enum Webusb_Command_Code { + WEBUSB_CMD_PAIR +}; +enum Webusb_Event_Code { + WEBUSB_EVT_PAIRED, + WEBUSB_EVT_KEYDOWN, + WEBUSB_EVT_KEYUP, + WEBUSB_EVT_LAYER +}; -- cgit v1.2.3