Skip to content

Commit

Permalink
Feat/smart layers (#387)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fdidron authored Mar 28, 2024
1 parent 1bd6b1b commit 9ec74b5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
33 changes: 31 additions & 2 deletions quantum/oryx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -61,16 +75,31 @@ 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();

case ORYX_CMD_PAIRING_VALIDATE:
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;

Expand Down
6 changes: 5 additions & 1 deletion quantum/oryx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
};
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ec74b5

Please sign in to comment.