summaryrefslogtreecommitdiff
path: root/keyboards/ergodox_ez/ergodox_ez.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox_ez/ergodox_ez.c')
-rw-r--r--keyboards/ergodox_ez/ergodox_ez.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c
index 3fd4e30833..6f56fd8e12 100644
--- a/keyboards/ergodox_ez/ergodox_ez.c
+++ b/keyboards/ergodox_ez/ergodox_ez.c
@@ -1,5 +1,9 @@
#include QMK_KEYBOARD_H
+#ifdef WEBUSB_ENABLE
+#include "webusb.h"
+#endif
+
extern inline void ergodox_board_led_on(void);
extern inline void ergodox_right_led_1_on(void);
extern inline void ergodox_right_led_2_on(void);
@@ -336,6 +340,17 @@ void keyboard_post_init_kb(void) {
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
+#ifdef WEBUSB_ENABLE
+ if(webusb_state.paired == true) {
+ uint8_t event[5];
+ event[0] = WEBUSB_STATUS_OK;
+ event[1] = record->event.pressed ? WEBUSB_EVT_KEYDOWN : WEBUSB_EVT_KEYUP;
+ event[2] = record->event.key.col;
+ event[3] = record->event.key.row;
+ event[4] = WEBUSB_STOP_BIT;
+ webusb_send(event, sizeof(event));
+ }
+#endif
switch (keycode) {
case LED_LEVEL:
if (record->event.pressed) {
@@ -387,3 +402,53 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset!
eeconfig_update_kb(keyboard_config.raw);
eeconfig_init_user();
}
+
+#ifdef WEBUSB_ENABLE
+static uint16_t loops = 0;
+static bool is_on = false;
+
+void matrix_scan_kb(void) {
+ if(webusb_state.pairing == true) {
+ if(loops == 0) {
+ ergodox_right_led_1_off();
+ ergodox_right_led_2_off();
+ ergodox_right_led_3_off();
+ }
+ if(loops % WEBUSB_BLINK_STEPS == 0) {
+ if(is_on) {
+ ergodox_right_led_2_off();
+ }
+ else {
+ ergodox_right_led_2_on();
+ }
+ is_on ^= 1;
+ }
+ if(loops > WEBUSB_BLINK_END) {
+ webusb_state.pairing = false;
+ layer_state_set_user(layer_state);
+ loops = 0;
+ }
+ loops++;
+ }
+ else if(loops > 0) {
+ loops = 0;
+ layer_state_set_user(layer_state);
+ }
+ matrix_scan_user();
+}
+
+uint32_t layer_state_set_kb(uint32_t state) {
+ state = layer_state_set_user(state);
+ uint8_t layer = biton32(state);
+ if(webusb_state.paired == true) {
+ uint8_t event[4];
+ event[0] = WEBUSB_STATUS_OK;
+ event[1] = WEBUSB_EVT_LAYER;
+ event[2] = layer;
+ event[3] = WEBUSB_STOP_BIT;
+ webusb_send(event, sizeof(event));
+ }
+ return state;
+}
+#endif
+