From 83674941765036f303b89a0166436ae6387628e2 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 21 Dec 2023 10:48:50 +0700 Subject: [PATCH] chore: remove pairing code --- keyboards/ergodox_ez/ergodox_ez.c | 32 ------- keyboards/planck/ez/ez.c | 35 -------- quantum/oryx.c | 121 ++++----------------------- quantum/oryx.h | 14 +--- tmk_core/protocol/chibios/usb_main.c | 1 - tmk_core/protocol/lufa/lufa.c | 1 - 6 files changed, 15 insertions(+), 189 deletions(-) diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c index d7c7c35d05fc..a7e2d99e9b4c 100644 --- a/keyboards/ergodox_ez/ergodox_ez.c +++ b/keyboards/ergodox_ez/ergodox_ez.c @@ -389,11 +389,6 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset! eeconfig_init_user(); } -#ifdef ORYX_ENABLE -static uint16_t loops = 0; -static bool is_on = false; -#endif - #ifdef DYNAMIC_MACRO_ENABLE static bool is_dynamic_recording = false; static uint16_t dynamic_loop_timer; @@ -411,33 +406,6 @@ void dynamic_macro_record_end_user(int8_t direction) { #endif void matrix_scan_kb(void) { -#ifdef ORYX_ENABLE - if(rawhid_state.pairing == true) { - if(loops == 0) { - ergodox_right_led_1_off(); - ergodox_right_led_2_off(); - ergodox_right_led_3_off(); - } - if(loops % PAIRING_BLINK_STEPS == 0) { - if(is_on) { - ergodox_right_led_2_off(); - } else { - ergodox_right_led_2_on(); - } - is_on ^= 1; - } - if(loops > PAIRING_BLINK_END) { - rawhid_state.pairing = false; - layer_state_set_user(layer_state); - loops = 0; - } - loops++; - } else if(loops > 0) { - loops = 0; - layer_state_set_user(layer_state); - } -#endif - #ifdef DYNAMIC_MACRO_ENABLE if (is_dynamic_recording) { ergodox_right_led_1_off(); diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c index 5a2d04e9af64..d1bcf4bd2dd9 100644 --- a/keyboards/planck/ez/ez.c +++ b/keyboards/planck/ez/ez.c @@ -308,11 +308,6 @@ bool music_mask_kb(uint16_t keycode) { } #endif -#ifdef ORYX_ENABLE -static uint16_t loops = 0; -static bool is_on = false; -#endif - #ifdef DYNAMIC_MACRO_ENABLE static bool is_dynamic_recording = false; static uint16_t dynamic_loop_timer; @@ -330,36 +325,6 @@ void dynamic_macro_record_end_user(int8_t direction) { #endif void matrix_scan_kb(void) { -#ifdef ORYX_ENABLE - if(rawhid_state.pairing == true) { - if(loops == 0) { - //lights off - } - if(loops % PAIRING_BLINK_STEPS == 0) { - if(is_on) { - planck_ez_left_led_on(); - planck_ez_right_led_off(); - } - else { - planck_ez_left_led_off(); - planck_ez_right_led_on(); - } - is_on ^= 1; - } - if(loops > PAIRING_BLINK_END * 2) { - rawhid_state.pairing = false; - loops = 0; - planck_ez_left_led_off(); - planck_ez_right_led_off(); - } - loops++; - } - else if(loops > 0) { - loops = 0; - planck_ez_left_led_off(); - planck_ez_right_led_off(); - } -#endif #ifdef DYNAMIC_MACRO_ENABLE if (is_dynamic_recording) { if (timer_elapsed(dynamic_loop_timer) > 1) diff --git a/quantum/oryx.c b/quantum/oryx.c index 7e5f4b883b2f..5cc38c20f414 100644 --- a/quantum/oryx.c +++ b/quantum/oryx.c @@ -4,7 +4,7 @@ # include "voyager.h" #endif -rawhid_state_t rawhid_state = {.pairing = false, .paired = false}; +rawhid_state_t rawhid_state = {.paired = false, .rgb_control = false}; uint8_t pairing_input_index = 0; @@ -15,50 +15,6 @@ void oryx_error(uint8_t code) { raw_hid_send(event, RAW_EPSIZE); } -void get_pairing_code(keypos_t positions[], int size) { - const char *version = FIRMWARE_VERSION; - - // Initialize all positions to {1, 1} - for (int i = 0; i < size; ++i) { - positions[i].col = 1; - positions[i].row = 1; - } - - // Find the position of '/' - const char *slash_pos = strchr(version, '/'); - int max_index = (slash_pos != NULL) ? (slash_pos - version) : strlen(version); - max_index = (max_index / 2 < size) ? max_index / 2 : size; - - for (int i = 0; i < max_index; ++i) { - positions[i].col = version[i * 2] % ORYX_PAIRING_MAX_INDEX + 1; - positions[i].row = version[i * 2 + 1] % ORYX_PAIRING_MAX_INDEX + 1; - } -} - -void pairing_init_handler(void) { - uint8_t event[RAW_EPSIZE]; - uint8_t event_index = 0; - - keypos_t positions[PAIRING_SEQUENCE_SIZE]; - get_pairing_code(positions, PAIRING_SEQUENCE_SIZE); - - event[event_index++] = ORYX_EVT_PAIRING_INPUT; - for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) { - event[event_index++] = positions[i].col; - event[event_index++] = positions[i].row; - } - event[event_index++] = ORYX_STOP_BIT; - - rawhid_state.pairing = true; - raw_hid_send(event, RAW_EPSIZE); -} - -void pairing_key_input_event(void) { - uint8_t event[RAW_EPSIZE]; - event[0] = ORYX_EVT_PAIRING_KEY_INPUT; - raw_hid_send(event, sizeof(event)); -} - void oryx_layer_event(void) { uint8_t layer; uint8_t event[RAW_EPSIZE]; @@ -70,6 +26,7 @@ void oryx_layer_event(void) { } void pairing_failed_event(void) { + rawhid_state.paired = false; uint8_t event[RAW_EPSIZE]; event[0] = ORYX_EVT_PAIRING_FAILED; event[1] = ORYX_STOP_BIT; @@ -77,52 +34,13 @@ void pairing_failed_event(void) { } void pairing_success_event(void) { + rawhid_state.paired = true; uint8_t event[RAW_EPSIZE]; event[0] = ORYX_EVT_PAIRING_SUCCESS; event[1] = ORYX_STOP_BIT; raw_hid_send(event, sizeof(event)); } -bool pairing_key_input_handler(keypos_t pos) { - keypos_t positions[PAIRING_SEQUENCE_SIZE]; - get_pairing_code(positions, PAIRING_SEQUENCE_SIZE); - keypos_t key = positions[pairing_input_index]; - - if (pos.col != key.col || pos.row != key.row) { - rawhid_state.pairing = false; - pairing_input_index = 0; - pairing_failed_event(); - return false; - } else { - pairing_input_index++; - pairing_key_input_event(); - return true; - } -} - -void pairing_validate_handler(uint8_t *param) { - bool valid = true; - uint8_t cmd_index = 0; - keypos_t positions[PAIRING_SEQUENCE_SIZE]; - get_pairing_code(positions, PAIRING_SEQUENCE_SIZE); - for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) { - keypos_t pos; - pos.col = param[cmd_index++]; - pos.row = param[cmd_index++]; - if (pos.col != positions[i].col || pos.row != positions[i].row) { - rawhid_state.pairing = false; - pairing_failed_event(); - break; - } - } - if (valid) { - rawhid_state.pairing = false; - rawhid_state.paired = true; - pairing_input_index = 0; - pairing_success_event(); - } -} - void raw_hid_receive(uint8_t *data, uint8_t length) { uint8_t command = data[0]; uint8_t *param = &data[1]; @@ -144,11 +62,17 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { } case ORYX_CMD_PAIRING_INIT: - pairing_init_handler(); + if (rawhid_state.paired == true) + pairing_failed_event(); + else + pairing_success_event(); break; case ORYX_CMD_PAIRING_VALIDATE: - pairing_validate_handler(param); + if (rawhid_state.paired == true) + pairing_failed_event(); + else + pairing_success_event(); break; case ORYX_SET_LAYER: @@ -234,7 +158,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { } break; case ORYX_UPDATE_BRIGHTNESS: -#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow) +#if defined(RGB_MATRIX_ENABLE) && !defined(PROTOCOL_LUFA) if (param[0]) { rgb_matrix_increase_val_noeeprom(); } else { @@ -251,25 +175,6 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { bool process_record_oryx(uint16_t keycode, keyrecord_t *record) { - // In pairing mode, key events are absorbed, and the host pairing sequence is filled. - // Once filled, the keyboard and host sequence are compaired, pairing state set to false - // and the proper pairing validation event is sent to the host - if (rawhid_state.pairing == true) { - // The host pairing sequence is filled on key up only - if (!record->event.pressed) { - if (pairing_input_index < PAIRING_SEQUENCE_SIZE) { - pairing_key_input_handler(record->event.key); - } - wait_ms(1000); - if (pairing_input_index == PAIRING_SEQUENCE_SIZE) { - rawhid_state.pairing = false; - rawhid_state.paired = true; - pairing_input_index = 0; - pairing_success_event(); - } - } - return false; - } // While paired, the keyboard sends keystrokes positions to the host if (rawhid_state.paired == true) { uint8_t event[RAW_EPSIZE]; @@ -284,7 +189,9 @@ bool process_record_oryx(uint16_t keycode, keyrecord_t *record) { void layer_state_set_oryx(layer_state_t state) { if (rawhid_state.paired) { +#ifdef PROTOCOL_LUFA wait_ms(50); +#endif uint8_t event[RAW_EPSIZE]; event[0] = ORYX_EVT_LAYER; event[1] = get_highest_layer(state); diff --git a/quantum/oryx.h b/quantum/oryx.h index 61fa15ab238f..2a035a89fdde 100644 --- a/quantum/oryx.h +++ b/quantum/oryx.h @@ -21,14 +21,8 @@ Once the host has paired, it can freely use the commands define in the Oryx_Comm # define RAW_EPSIZE 32 #endif -#define ORYX_PROTOCOL_VERSION = 0x01 +#define ORYX_PROTOCOL_VERSION = 0x02 #define ORYX_STOP_BIT -2 -#define ORYX_PAIRING_MAX_INDEX 3 -#define PAIRING_BLINK_STEPS 512 -#define PAIRING_BLINK_END PAIRING_BLINK_STEPS * 60 -#define PAIRING_SEQUENCE_SIZE 3 -#define PAIRING_SEQUENCE_NUM_STORED 3 -#define PAIRING_STORAGE_SIZE PAIRING_SEQUENCE_SIZE* PAIRING_SEQUENCE_NUM_STORED * sizeof(uint16_t) enum Oryx_Command_Code { ORYX_CMD_GET_FW_VERSION, @@ -70,7 +64,6 @@ enum Oryx_Error_Code { extern bool oryx_state_live_training_enabled; typedef struct { - bool pairing; bool paired; bool rgb_control; } rawhid_state_t; @@ -78,11 +71,6 @@ typedef struct { extern rawhid_state_t rawhid_state; void oryx_error(uint8_t code); -bool pairing_key_input_handler(keypos_t pos); -void get_pairing_code(keypos_t positions[], int size); -void pairing_init_handler(void); -void pairing_validate_handler(uint8_t *param); -void pairing_key_input_event(void); void pairing_failed_event(void); void pairing_succesful_event(void); diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 0dba0234f3c0..e2b713543b0b 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -1012,7 +1012,6 @@ void raw_hid_send(uint8_t *data, uint8_t length) { # ifdef ORYX_ENABLE if (chnWriteTimeout(&drivers.raw_driver.driver, data, length, TIME_IMMEDIATE) != length) { - rawhid_state.pairing = false; rawhid_state.paired = false; } # else diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index c9558327bf93..a8e24224e94a 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -160,7 +160,6 @@ void raw_hid_send(uint8_t *data, uint8_t length) { if (Endpoint_IsINReady()) { // Write data if (Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL)) { - rawhid_state.pairing = false; rawhid_state.paired = false; } // Finalize the stream transfer to send the last packet