summaryrefslogtreecommitdiff
path: root/tmk_core/common/webusb.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/webusb.c')
-rw-r--r--tmk_core/common/webusb.c32
1 files changed, 22 insertions, 10 deletions
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];