From d54c6c6b149dbd133669557ee2c5b110e2ee8df9 Mon Sep 17 00:00:00 2001 From: Florian Didron <0x6664@hey.com> Date: Wed, 22 Jun 2022 10:32:32 +0900 Subject: fix: pairing crash on Ergodox --- quantum/oryx.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'quantum/oryx.c') diff --git a/quantum/oryx.c b/quantum/oryx.c index 080846b38f..58b5d5c626 100644 --- a/quantum/oryx.c +++ b/quantum/oryx.c @@ -105,19 +105,26 @@ void pairing_init_handler(void) { raw_hid_send(event, RAW_EPSIZE); } -void pairing_validate_handler() { - bool valid = true; - uint8_t event[RAW_EPSIZE]; +bool compare_sequences(keypos_t a[PAIRING_SEQUENCE_SIZE], keypos_t b[PAIRING_SEQUENCE_SIZE]) { + bool valid = true; for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) { - if (keyboard_pairing_sequence[i].row != host_pairing_sequence[i].row) { + if (a[i].row != b[i].row) { valid = false; break; } - if (keyboard_pairing_sequence[i].col != host_pairing_sequence[i].col) { + if (a[i].col != b[i].col) { valid = false; break; } } + return valid; +} + +void pairing_validate_handler() { + + uint8_t event[RAW_EPSIZE]; + bool valid = compare_sequences(keyboard_pairing_sequence, host_pairing_sequence); + if (valid == true) { event[0] = ORYX_EVT_PAIRING_SUCCESS; rawhid_state.paired = true; @@ -126,6 +133,7 @@ void pairing_validate_handler() { event[0] = ORYX_EVT_PAIRING_FAILED; rawhid_state.paired = false; } + event[1] = ORYX_STOP_BIT; rawhid_state.pairing = false; raw_hid_send(event, sizeof(event)); @@ -177,6 +185,7 @@ bool process_record_oryx(uint16_t keycode, keyrecord_t *record) { host_pairing_sequence[pairing_input_index++] = record->event.key; pairing_key_input_event(); } + wait_ms(1000); if (pairing_input_index == PAIRING_SEQUENCE_SIZE) { rawhid_state.pairing = false; pairing_input_index = 0; -- cgit v1.2.3