aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-10-07 23:28:17 +0900
committertmk <nobody@nowhere>2013-10-07 23:28:17 +0900
commit35f9f30074263a2a738cbfc513fca6d812ddf6ff (patch)
treebec1e4e96a58eb14feef42b8b1f2057d07ff476a /common
parentd52d554360d3bf06189bfd4f386fa99348d8a0a8 (diff)
downloadqmk_firmware-35f9f30074263a2a738cbfc513fca6d812ddf6ff.tar.gz
qmk_firmware-35f9f30074263a2a738cbfc513fca6d812ddf6ff.zip
Add timeout option to MODS_ONESHOT #66
Diffstat (limited to 'common')
-rw-r--r--common/action.c17
-rw-r--r--common/action_util.c39
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
22static inline void add_key_byte(uint8_t code); 23static inline void add_key_byte(uint8_t code);
23static inline void del_key_byte(uint8_t code); 24static inline void del_key_byte(uint8_t code);
@@ -35,17 +36,28 @@ static uint8_t weak_mods = 0;
35report_keyboard_t *keyboard_report = &(report_keyboard_t){}; 36report_keyboard_t *keyboard_report = &(report_keyboard_t){};
36 37
37#ifndef NO_ACTION_ONESHOT 38#ifndef NO_ACTION_ONESHOT
38static bool oneshot_enabled = true;
39static int8_t oneshot_mods = 0; 39static int8_t oneshot_mods = 0;
40#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
41static int16_t oneshot_time = 0;
40#endif 42#endif
43#endif
44
41 45
42void send_keyboard_report(void) { 46void 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
102void set_oneshot_mods(uint8_t mods) { oneshot_mods = mods; } 114void set_oneshot_mods(uint8_t mods)
103void clear_oneshot_mods(void) { oneshot_mods = 0; } 115{
104void oneshot_toggle(void) { oneshot_enabled = !oneshot_enabled; } 116 oneshot_mods = mods;
105void oneshot_enable(void) { oneshot_enabled = true; } 117#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
106void oneshot_disable(void) { oneshot_enabled = false; } 118 oneshot_time = timer_read();
119#endif
120}
121void 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