From 9ec74b5bad2c379bf107ce73a1f0977ddc11e087 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Thu, 28 Mar 2024 10:36:32 +0700 Subject: [PATCH] Feat/smart layers (#387) * feat: allows to switch layers via hid * feat: oryx protocol version hid command * chore: refactor set layer over hid code * feat: adds smart layer trigger key * fix: send oryx keypress events before preprocessing keys --- quantum/oryx.c | 33 +++++++++++++++++++++++++++++++-- quantum/oryx.h | 6 +++++- quantum/quantum.c | 7 ++++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/quantum/oryx.c b/quantum/oryx.c index e9b0e237d714..c6fed402af08 100644 --- a/quantum/oryx.c +++ b/quantum/oryx.c @@ -41,6 +41,20 @@ void pairing_success_event(void) { raw_hid_send(event, sizeof(event)); } +void toggle_smart_layer(void) { + uint8_t event[RAW_EPSIZE]; + event[0] = ORYX_EVT_TOGGLE_SMART_LAYER; + event[1] = ORYX_STOP_BIT; + raw_hid_send(event, sizeof(event)); +} + +void trigger_smart_layer(void) { + uint8_t event[RAW_EPSIZE]; + event[0] = ORYX_EVT_TRIGGER_SMART_LAYER; + event[1] = ORYX_STOP_BIT; + raw_hid_send(event, sizeof(event)); +} + void raw_hid_receive(uint8_t *data, uint8_t length) { uint8_t command = data[0]; uint8_t *param = &data[1]; @@ -61,6 +75,16 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { break; } + case ORYX_GET_PROTOCOL_VERSION: { + uint8_t event[RAW_EPSIZE]; + event[0] = ORYX_EVT_GET_PROTOCOL_VERSION; + event[1] = ORYX_PROTOCOL_VERSION; + event[2] = ORYX_STOP_BIT; + + raw_hid_send(event, RAW_EPSIZE); + break; + } + case ORYX_CMD_PAIRING_INIT: pairing_success_event(); @@ -68,9 +92,14 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { break; // Keeping this for backwards compatibility with older versions of Wally / Keymapp case ORYX_SET_LAYER: + // The first param's byte is on / off + // The second param's byte is the layer number if (rawhid_state.paired == true) { - layer_clear(); - layer_on(param[0]); + if (param[0] == 0) { + layer_off(param[1]); + } else { + layer_on(param[1]); + } } break; diff --git a/quantum/oryx.h b/quantum/oryx.h index 2a035a89fdde..314bbc35ecc2 100644 --- a/quantum/oryx.h +++ b/quantum/oryx.h @@ -21,7 +21,7 @@ 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 = 0x02 +#define ORYX_PROTOCOL_VERSION 0x03 #define ORYX_STOP_BIT -2 enum Oryx_Command_Code { @@ -47,6 +47,8 @@ enum Oryx_Event_Code { ORYX_EVT_KEYDOWN, ORYX_EVT_KEYUP, ORYX_EVT_RGB_CONTROL, + ORYX_EVT_TOGGLE_SMART_LAYER, + ORYX_EVT_TRIGGER_SMART_LAYER, ORYX_EVT_GET_PROTOCOL_VERSION = 0XFE, ORYX_EVT_ERROR = 0xFF, }; @@ -73,6 +75,8 @@ extern rawhid_state_t rawhid_state; void oryx_error(uint8_t code); void pairing_failed_event(void); void pairing_succesful_event(void); +void toggle_smart_layer(void); +void trigger_smart_layer(void); void oryx_layer_event(void); bool process_record_oryx(uint16_t keycode, keyrecord_t* record); diff --git a/quantum/quantum.c b/quantum/quantum.c index 973fe57045d8..b5f1dfef0096 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -251,6 +251,9 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) { /* Get keycode, and then process pre tapping functionality */ bool pre_process_record_quantum(keyrecord_t *record) { uint16_t keycode = get_record_keycode(record, true); +#ifdef ORYX_ENABLE + process_record_oryx(keycode, record); +#endif return pre_process_record_kb(keycode, record) && #ifdef COMBO_ENABLE process_combo(keycode, record) && @@ -284,6 +287,7 @@ bool process_record_quantum(keyrecord_t *record) { } #endif + #ifdef TAP_DANCE_ENABLE if (preprocess_tap_dance(keycode, record)) { // The tap dance might have updated the layer state, therefore the @@ -322,9 +326,6 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef HAPTIC_ENABLE process_haptic(keycode, record) && #endif // HAPTIC_ENABLE -#ifdef ORYX_ENABLE - process_record_oryx(keycode, record) && -#endif #if defined(VIA_ENABLE) process_record_via(keycode, record) && #endif