diff options
| author | Drashna Jaelre <drashna@live.com> | 2019-07-16 01:37:19 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-07-16 01:37:19 -0700 |
| commit | c44fc68297029da87233777aff6978d39caebbb1 (patch) | |
| tree | f580b1ae96684577caa899a8180a2f9cb4a81aca /quantum/process_keycode/process_combo.c | |
| parent | 5fa0a274eaf6c3f2b1dbd4e6e23a4c3b884f1d44 (diff) | |
| download | qmk_firmware-c44fc68297029da87233777aff6978d39caebbb1.tar.gz qmk_firmware-c44fc68297029da87233777aff6978d39caebbb1.zip | |
Allow Combo feature to be enabled/disabled live (#6318)
* Add ability to enable/disable combos
* Update documentation for Combo feature
* Change keycodes for appeasement
* Simplify combo_toggle function
* Update names
* Update combo docs to use tables
Diffstat (limited to 'quantum/process_keycode/process_combo.c')
| -rw-r--r-- | quantum/process_keycode/process_combo.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2c6c9d0d5..d3c3b1673 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c | |||
| @@ -28,6 +28,7 @@ static uint16_t timer = 0; | |||
| 28 | static uint8_t current_combo_index = 0; | 28 | static uint8_t current_combo_index = 0; |
| 29 | static bool drop_buffer = false; | 29 | static bool drop_buffer = false; |
| 30 | static bool is_active = false; | 30 | static bool is_active = false; |
| 31 | static bool b_combo_enable = true; // defaults to enabled | ||
| 31 | 32 | ||
| 32 | static uint8_t buffer_size = 0; | 33 | static uint8_t buffer_size = 0; |
| 33 | #ifdef COMBO_ALLOW_ACTION_KEYS | 34 | #ifdef COMBO_ALLOW_ACTION_KEYS |
| @@ -128,6 +129,23 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
| 128 | drop_buffer = false; | 129 | drop_buffer = false; |
| 129 | bool no_combo_keys_pressed = true; | 130 | bool no_combo_keys_pressed = true; |
| 130 | 131 | ||
| 132 | if (keycode == CMB_ON && record->event.pressed) { | ||
| 133 | combo_enable(); | ||
| 134 | return true; | ||
| 135 | } | ||
| 136 | |||
| 137 | if (keycode == CMB_OFF && record->event.pressed) { | ||
| 138 | combo_disable(); | ||
| 139 | return true; | ||
| 140 | } | ||
| 141 | |||
| 142 | if (keycode == CMB_TOG && record->event.pressed) { | ||
| 143 | combo_toggle(); | ||
| 144 | return true; | ||
| 145 | } | ||
| 146 | |||
| 147 | if (!is_combo_enabled()) { return true; } | ||
| 148 | |||
| 131 | for (current_combo_index = 0; current_combo_index < COMBO_COUNT; | 149 | for (current_combo_index = 0; current_combo_index < COMBO_COUNT; |
| 132 | ++current_combo_index) { | 150 | ++current_combo_index) { |
| 133 | combo_t *combo = &key_combos[current_combo_index]; | 151 | combo_t *combo = &key_combos[current_combo_index]; |
| @@ -166,7 +184,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
| 166 | } | 184 | } |
| 167 | 185 | ||
| 168 | void matrix_scan_combo(void) { | 186 | void matrix_scan_combo(void) { |
| 169 | if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) { | 187 | if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { |
| 170 | 188 | ||
| 171 | /* This disables the combo, meaning key events for this | 189 | /* This disables the combo, meaning key events for this |
| 172 | * combo will be handled by the next processors in the chain | 190 | * combo will be handled by the next processors in the chain |
| @@ -175,3 +193,26 @@ void matrix_scan_combo(void) { | |||
| 175 | dump_key_buffer(true); | 193 | dump_key_buffer(true); |
| 176 | } | 194 | } |
| 177 | } | 195 | } |
| 196 | |||
| 197 | void combo_enable(void) { | ||
| 198 | b_combo_enable = true; | ||
| 199 | } | ||
| 200 | |||
| 201 | void combo_disable(void) { | ||
| 202 | b_combo_enable = is_active = false; | ||
| 203 | timer = 0; | ||
| 204 | dump_key_buffer(true); | ||
| 205 | |||
| 206 | } | ||
| 207 | |||
| 208 | void combo_toggle(void) { | ||
| 209 | if (b_combo_enable) { | ||
| 210 | combo_disable(); | ||
| 211 | } else { | ||
| 212 | combo_enable(); | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | bool is_combo_enabled(void) { | ||
| 217 | return b_combo_enable; | ||
| 218 | } | ||
