aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.h
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-06-29 17:49:41 -0400
committerGitHub <noreply@github.com>2016-06-29 17:49:41 -0400
commit65faab3b89245f81c50b029ca178aed175d5f330 (patch)
tree49a7199b9e8804f4a212762b7e267c4d4228b900 /quantum/quantum.h
parent215c2119af5281072d5a6efb0308408793cadd08 (diff)
downloadqmk_firmware-65faab3b89245f81c50b029ca178aed175d5f330.tar.gz
qmk_firmware-65faab3b89245f81c50b029ca178aed175d5f330.zip
Moves features to their own files (process_*), adds tap dance feature (#460)
* non-working commit * working * subprojects implemented for planck * pass a subproject variable through to c * consolidates clueboard revisions * thanks for letting me know about conflicts.. * turn off audio for yang's * corrects starting paths for subprojects * messing around with travis * semicolon * travis script * travis script * script for travis * correct directory (probably), amend files to commit * remove origin before adding * git pull, correct syntax * git checkout * git pull origin branch * where are we? * where are we? * merging * force things to happen * adds commit message, adds add * rebase, no commit message * rebase branch * idk! * try just pull * fetch - merge * specify repo branch * checkout * goddammit * merge? idk * pls * after all * don't split up keyboards * syntax * adds quick for all-keyboards * trying out new script * script update * lowercase * all keyboards * stop replacing compiled.hex automatically * adds if statement * skip automated build branches * forces push to automated build branch * throw an add in there * upstream? * adds AUTOGEN * ignore all .hex files again * testing out new repo * global ident * generate script, keyboard_keymap.hex * skip generation for now, print pandoc info, submodule update * try trusty * and sudo * try generate * updates subprojects to keyboards * no idea * updates to keyboards * cleans up clueboard stuff * setup to use local readme * updates cluepad, planck experimental * remove extra led.c [ci skip] * audio and midi moved over to separate files * chording, leader, unicode separated * consolidate each [skip ci] * correct include * quantum: Add a tap dance feature (#451) * quantum: Add a tap dance feature With this feature one can specify keys that behave differently, based on the amount of times they have been tapped, and when interrupted, they get handled before the interrupter. To make it clear how this is different from `ACTION_FUNCTION_TAP`, lets explore a certain setup! We want one key to send `Space` on single tap, but `Enter` on double-tap. With `ACTION_FUNCTION_TAP`, it is quite a rain-dance to set this up, and has the problem that when the sequence is interrupted, the interrupting key will be send first. Thus, `SPC a` will result in `a SPC` being sent, if they are typed within `TAPPING_TERM`. With the tap dance feature, that'll come out as `SPC a`, correctly. The implementation hooks into two parts of the system, to achieve this: into `process_record_quantum()`, and the matrix scan. We need the latter to be able to time out a tap sequence even when a key is not being pressed, so `SPC` alone will time out and register after `TAPPING_TERM` time. But lets start with how to use it, first! First, you will need `TAP_DANCE_ENABLE=yes` in your `Makefile`, because the feature is disabled by default. This adds a little less than 1k to the firmware size. Next, you will want to define some tap-dance keys, which is easiest to do with the `TD()` macro, that - similar to `F()`, takes a number, which will later be used as an index into the `tap_dance_actions` array. This array specifies what actions shall be taken when a tap-dance key is in action. Currently, there are two possible options: * `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise. * `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the current state of the tap-dance action. The first option is enough for a lot of cases, that just want dual roles. For example, `ACTION_TAP_DANCE(KC_SPC, KC_ENT)` will result in `Space` being sent on single-tap, `Enter` otherwise. And that's the bulk of it! Do note, however, that this implementation does have some consequences: keys do not register until either they reach the tapping ceiling, or they time out. This means that if you hold the key, nothing happens, no repeat, no nothing. It is possible to detect held state, and register an action then too, but that's not implemented yet. Keys also unregister immediately after being registered, so you can't even hold the second tap. This is intentional, to be consistent. And now, on to the explanation of how it works! The main entry point is `process_tap_dance()`, called from `process_record_quantum()`, which is run for every keypress, and our handler gets to run early. This function checks whether the key pressed is a tap-dance key. If it is not, and a tap-dance was in action, we handle that first, and enqueue the newly pressed key. If it is a tap-dance key, then we check if it is the same as the already active one (if there's one active, that is). If it is not, we fire off the old one first, then register the new one. If it was the same, we increment the counter and the timer. This means that you have `TAPPING_TERM` time to tap the key again, you do not have to input all the taps within that timeframe. This allows for longer tap counts, with minimal impact on responsiveness. Our next stop is `matrix_scan_tap_dance()`. This handles the timeout of tap-dance keys. For the sake of flexibility, tap-dance actions can be either a pair of keycodes, or a user function. The latter allows one to handle higher tap counts, or do extra things, like blink the LEDs, fiddle with the backlighting, and so on. This is accomplished by using an union, and some clever macros. In the end, lets see a full example! ```c enum { CT_SE = 0, CT_CLN, CT_EGG }; /* Have the above three on the keymap, TD(CT_SE), etc... */ void dance_cln (qk_tap_dance_state_t *state) { if (state->count == 1) { register_code (KC_RSFT); register_code (KC_SCLN); unregister_code (KC_SCLN); unregister_code (KC_RSFT); } else { register_code (KC_SCLN); unregister_code (KC_SCLN); reset_tap_dance (state); } } void dance_egg (qk_tap_dance_state_t *state) { if (state->count >= 100) { SEND_STRING ("Safety dance!"); reset_tap_dance (state); } } const qk_tap_dance_action_t tap_dance_actions[] = { [CT_SE] = ACTION_TAP_DANCE_DOUBLE (KC_SPC, KC_ENT) ,[CT_CLN] = ACTION_TAP_DANCE_FN (dance_cln) ,[CT_EGG] = ACTION_TAP_DANCE_FN (dance_egg) }; ``` This addresses #426. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * hhkb: Fix the build with the new tap-dance feature Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * tap_dance: Move process_tap_dance further down Process the tap dance stuff after midi and audio, because those don't process keycodes, but row/col positions. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * tap_dance: Use conditionals instead of dummy functions To be consistent with how the rest of the quantum features are implemented, use ifdefs instead of dummy functions. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * Merge branch 'master' into quantum-keypress-process # Conflicts: # Makefile # keyboards/planck/rev3/config.h # keyboards/planck/rev4/config.h * update build script
Diffstat (limited to 'quantum/quantum.h')
-rw-r--r--quantum/quantum.h57
1 files changed, 18 insertions, 39 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 7795294d5..ad180c71f 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -10,15 +10,6 @@
10#ifdef RGBLIGHT_ENABLE 10#ifdef RGBLIGHT_ENABLE
11 #include "rgblight.h" 11 #include "rgblight.h"
12#endif 12#endif
13#ifdef AUDIO_ENABLE
14 #include "audio.h"
15#endif
16#ifdef MIDI_ENABLE
17 #include <lufa.h>
18#endif
19#ifdef UNICODE_ENABLE
20 #include "unicode.h"
21#endif
22 13
23#include "action_layer.h" 14#include "action_layer.h"
24#include "eeconfig.h" 15#include "eeconfig.h"
@@ -32,42 +23,38 @@
32#include "led.h" 23#include "led.h"
33#include "action_util.h" 24#include "action_util.h"
34 25
26
35extern uint32_t default_layer_state; 27extern uint32_t default_layer_state;
36 28
37#ifndef NO_ACTION_LAYER 29#ifndef NO_ACTION_LAYER
38 extern uint32_t layer_state; 30 extern uint32_t layer_state;
39#endif 31#endif
40 32
33#ifdef MIDI_ENABLE
34 #include <lufa.h>
35 #include "process_midi.h"
36#endif
37
41#ifdef AUDIO_ENABLE 38#ifdef AUDIO_ENABLE
42 bool music_activated; 39 #include "audio.h"
40 #include "process_music.h"
43#endif 41#endif
44 42
45#ifdef UNICODE_ENABLE 43#ifndef DISABLE_LEADER
46 #define UC_OSX 0 44 #include "process_leader.h"
47 #define UC_LNX 1 45#endif
48 #define UC_WIN 2
49 #define UC_BSD 3
50 46
51 void set_unicode_input_mode(uint8_t os_target); 47#define DISABLE_CHORDING
48#ifndef DISABLE_CHORDING
49 #include "process_chording.h"
52#endif 50#endif
53 51
54#ifndef DISABLE_LEADER 52#ifdef UNICODE_ENABLE
55 void leader_start(void); 53 #include "process_unicode.h"
56 void leader_end(void);
57
58 #ifndef LEADER_TIMEOUT
59 #define LEADER_TIMEOUT 200
60 #endif
61 #define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0)
62 #define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0)
63 #define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == 0 && leader_sequence[4] == 0)
64 #define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0)
65 #define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5))
66
67 #define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[5]; extern uint8_t leader_sequence_size
68 #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
69#endif 54#endif
70 55
56#include "process_tap_dance.h"
57
71#define SEND_STRING(str) send_string(PSTR(str)) 58#define SEND_STRING(str) send_string(PSTR(str))
72void send_string(const char *str); 59void send_string(const char *str);
73 60
@@ -84,16 +71,8 @@ bool process_action_kb(keyrecord_t *record);
84bool process_record_kb(uint16_t keycode, keyrecord_t *record); 71bool process_record_kb(uint16_t keycode, keyrecord_t *record);
85bool process_record_user(uint16_t keycode, keyrecord_t *record); 72bool process_record_user(uint16_t keycode, keyrecord_t *record);
86 73
87bool is_music_on(void);
88void music_toggle(void);
89void music_on(void);
90void music_off(void);
91
92void startup_user(void); 74void startup_user(void);
93void shutdown_user(void); 75void shutdown_user(void);
94void audio_on_user(void);
95void music_on_user(void);
96void music_scale_user(void);
97 76
98#ifdef BACKLIGHT_ENABLE 77#ifdef BACKLIGHT_ENABLE
99void backlight_init_ports(void); 78void backlight_init_ports(void);