From eac8fa799909817bfc7cb4043448f85551154c6b Mon Sep 17 00:00:00 2001 From: Ofer Plesser Date: Sat, 10 Dec 2016 00:49:11 +0200 Subject: Implemented basic key combination feature --- quantum/process_keycode/process_combo.c | 66 +++++++++++++++++++++++++++++++++ quantum/process_keycode/process_combo.h | 25 +++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 quantum/process_keycode/process_combo.c create mode 100644 quantum/process_keycode/process_combo.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c new file mode 100644 index 000000000..a6cfed11a --- /dev/null +++ b/quantum/process_keycode/process_combo.c @@ -0,0 +1,66 @@ +#include "process_combo.h" +#include "print.h" + +// __attribute__ ((weak)) +// combo_t key_combos[] = { + +// }; + +#define SEND_KEY(key) \ +do { \ + register_code16(key); \ + send_keyboard_report(); \ + unregister_code16(key); \ +} while(0) + + +#define ALL_COMBO_KEYS_ARE_DOWN (((1<state) +static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) +{ + uint8_t count = 0; + bool is_combo_key = false; + // bool combo_key_released = false; + + // Count the number of combo keys + for (const uint16_t *key = combo->keys; COMBO_END != pgm_read_word(key); ++key, ++count); + + for (uint8_t i = 0; i < count; ++i) { + uint16_t key = pgm_read_word(&combo->keys[i]); + + if (key == keycode) { + is_combo_key = true; + + if (record->event.pressed) { + combo->state |= (1<state) { + // The combo was sent, no need to send released key + return true; + } + + combo->state &= ~(1<action); + combo->state = 0; + } + + return is_combo_key; +} + + +bool process_combo(uint16_t keycode, keyrecord_t *record) +{ + bool is_combo_key = false; + + for (int i = 0; i < NUM_ELEMS(key_combos); ++i) { + combo_t *combo = &key_combos[i]; + is_combo_key |= process_single_combo(combo, keycode, record); + } + + return !is_combo_key; +} \ No newline at end of file diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h new file mode 100644 index 000000000..68786c0f1 --- /dev/null +++ b/quantum/process_keycode/process_combo.h @@ -0,0 +1,25 @@ +#ifndef PROCESS_COMBO_H +#define PROCESS_COMBO_H + +#include +#include "progmem.h" +#include "quantum.h" + + +typedef struct +{ + const uint16_t *keys; + uint16_t action; + uint32_t state; +} combo_t; + + +#define COMBO_END 0 +#define NUM_ELEMS(a) (sizeof(a)/sizeof 0[a]) + + +extern combo_t key_combos[1]; + +bool process_combo(uint16_t keycode, keyrecord_t *record); + +#endif \ No newline at end of file -- cgit v1.2.3-24-g4f1b