diff options
author | tmk <nobody@nowhere> | 2013-10-07 23:28:17 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2013-10-07 23:28:17 +0900 |
commit | 35f9f30074263a2a738cbfc513fca6d812ddf6ff (patch) | |
tree | bec1e4e96a58eb14feef42b8b1f2057d07ff476a /common | |
parent | d52d554360d3bf06189bfd4f386fa99348d8a0a8 (diff) | |
download | qmk_firmware-35f9f30074263a2a738cbfc513fca6d812ddf6ff.tar.gz qmk_firmware-35f9f30074263a2a738cbfc513fca6d812ddf6ff.zip |
Add timeout option to MODS_ONESHOT #66
Diffstat (limited to 'common')
-rw-r--r-- | common/action.c | 17 | ||||
-rw-r--r-- | common/action_util.c | 39 |
2 files changed, 33 insertions, 23 deletions
diff --git a/common/action.c b/common/action.c index ecd5a7e94..f7ae85b94 100644 --- a/common/action.c +++ b/common/action.c | |||
@@ -100,40 +100,29 @@ void process_action(keyrecord_t *record) | |||
100 | action.key.mods<<4; | 100 | action.key.mods<<4; |
101 | switch (action.layer_tap.code) { | 101 | switch (action.layer_tap.code) { |
102 | #ifndef NO_ACTION_ONESHOT | 102 | #ifndef NO_ACTION_ONESHOT |
103 | case 0x00: | 103 | case MODS_ONESHOT: |
104 | // Oneshot modifier | 104 | // Oneshot modifier |
105 | if (event.pressed) { | 105 | if (event.pressed) { |
106 | if (tap_count == 0) { | 106 | if (tap_count == 0) { |
107 | dprint("MODS_TAP: Oneshot: add_mods\n"); | ||
108 | register_mods(mods); | 107 | register_mods(mods); |
109 | } | 108 | } |
110 | else if (tap_count == 1) { | 109 | else if (tap_count == 1) { |
111 | dprint("MODS_TAP: Oneshot: start\n"); | 110 | dprint("MODS_TAP: Oneshot: start\n"); |
112 | set_oneshot_mods(mods); | 111 | set_oneshot_mods(mods); |
113 | } | 112 | } |
114 | else if (tap_count == TAPPING_TOGGLE) { | ||
115 | dprint("MODS_TAP: Oneshot: toggle\n"); | ||
116 | oneshot_toggle(); | ||
117 | } | ||
118 | else { | 113 | else { |
119 | dprint("MODS_TAP: Oneshot: cancel&add_mods\n"); | ||
120 | // double tap cancels oneshot and works as normal modifier. | ||
121 | clear_oneshot_mods(); | ||
122 | register_mods(mods); | 114 | register_mods(mods); |
123 | } | 115 | } |
124 | } else { | 116 | } else { |
125 | if (tap_count == 0) { | 117 | if (tap_count == 0) { |
126 | dprint("MODS_TAP: Oneshot: cancel/del_mods\n"); | ||
127 | // cancel oneshot on hold | ||
128 | clear_oneshot_mods(); | 118 | clear_oneshot_mods(); |
129 | unregister_mods(mods); | 119 | unregister_mods(mods); |
130 | } | 120 | } |
131 | else if (tap_count == 1) { | 121 | else if (tap_count == 1) { |
132 | // Oneshot | 122 | // Retain Oneshot mods |
133 | } | 123 | } |
134 | else { | 124 | else { |
135 | dprint("MODS_TAP: Oneshot: del_mods\n"); | 125 | clear_oneshot_mods(); |
136 | // cancel Mods | ||
137 | unregister_mods(mods); | 126 | unregister_mods(mods); |
138 | } | 127 | } |
139 | } | 128 | } |
diff --git a/common/action_util.c b/common/action_util.c index 50d686a07..99a3adaab 100644 --- a/common/action_util.c +++ b/common/action_util.c | |||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | #include "report.h" | 18 | #include "report.h" |
19 | #include "debug.h" | 19 | #include "debug.h" |
20 | #include "action_util.h" | 20 | #include "action_util.h" |
21 | #include "timer.h" | ||
21 | 22 | ||
22 | static inline void add_key_byte(uint8_t code); | 23 | static inline void add_key_byte(uint8_t code); |
23 | static inline void del_key_byte(uint8_t code); | 24 | static inline void del_key_byte(uint8_t code); |
@@ -35,17 +36,28 @@ static uint8_t weak_mods = 0; | |||
35 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; | 36 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; |
36 | 37 | ||
37 | #ifndef NO_ACTION_ONESHOT | 38 | #ifndef NO_ACTION_ONESHOT |
38 | static bool oneshot_enabled = true; | ||
39 | static int8_t oneshot_mods = 0; | 39 | static int8_t oneshot_mods = 0; |
40 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | ||
41 | static int16_t oneshot_time = 0; | ||
40 | #endif | 42 | #endif |
43 | #endif | ||
44 | |||
41 | 45 | ||
42 | void send_keyboard_report(void) { | 46 | void send_keyboard_report(void) { |
43 | keyboard_report->mods = real_mods; | 47 | keyboard_report->mods = real_mods; |
44 | keyboard_report->mods |= weak_mods; | 48 | keyboard_report->mods |= weak_mods; |
45 | #ifndef NO_ACTION_ONESHOT | 49 | #ifndef NO_ACTION_ONESHOT |
46 | keyboard_report->mods |= oneshot_mods; | 50 | if (oneshot_mods) { |
47 | if (has_anykey()) { | 51 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
48 | clear_oneshot_mods(); | 52 | if (TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT) { |
53 | dprintf("Oneshot: timeout\n"); | ||
54 | clear_oneshot_mods(); | ||
55 | } | ||
56 | #endif | ||
57 | keyboard_report->mods |= oneshot_mods; | ||
58 | if (has_anykey()) { | ||
59 | clear_oneshot_mods(); | ||
60 | } | ||
49 | } | 61 | } |
50 | #endif | 62 | #endif |
51 | host_keyboard_send(keyboard_report); | 63 | host_keyboard_send(keyboard_report); |
@@ -99,11 +111,20 @@ void clear_weak_mods(void) { weak_mods = 0; } | |||
99 | 111 | ||
100 | /* Oneshot modifier */ | 112 | /* Oneshot modifier */ |
101 | #ifndef NO_ACTION_ONESHOT | 113 | #ifndef NO_ACTION_ONESHOT |
102 | void set_oneshot_mods(uint8_t mods) { oneshot_mods = mods; } | 114 | void set_oneshot_mods(uint8_t mods) |
103 | void clear_oneshot_mods(void) { oneshot_mods = 0; } | 115 | { |
104 | void oneshot_toggle(void) { oneshot_enabled = !oneshot_enabled; } | 116 | oneshot_mods = mods; |
105 | void oneshot_enable(void) { oneshot_enabled = true; } | 117 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
106 | void oneshot_disable(void) { oneshot_enabled = false; } | 118 | oneshot_time = timer_read(); |
119 | #endif | ||
120 | } | ||
121 | void clear_oneshot_mods(void) | ||
122 | { | ||
123 | oneshot_mods = 0; | ||
124 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | ||
125 | oneshot_time = 0; | ||
126 | #endif | ||
127 | } | ||
107 | #endif | 128 | #endif |
108 | 129 | ||
109 | 130 | ||