aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/action.c17
-rw-r--r--common/action_util.c39
-rw-r--r--doc/keymap.md9
-rw-r--r--keyboard/hhkb/Makefile6
-rw-r--r--keyboard/hhkb/config.h3
5 files changed, 44 insertions, 30 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
diff --git a/doc/keymap.md b/doc/keymap.md
index c509651be..11e80a9c3 100644
--- a/doc/keymap.md
+++ b/doc/keymap.md
@@ -516,13 +516,14 @@ This is a feature to assign both toggle layer and momentary switch layer action
516 ACTION_LAYER_TAP_TOGGLE(1) 516 ACTION_LAYER_TAP_TOGGLE(1)
517 517
518 518
519### 4.3 One Shot Modifier 519### 4.3 Oneshot Modifier
520This adds oneshot feature to modifier key. 'One Shot Modifier' is one time modifier which has effect only on following just one key. 520This runs onetime effect swhich modify only on just one following key. It works as normal modifier key when holding down while oneshot modifier when tapping.
521It works as normal modifier key when holding but oneshot modifier when tapping.
522 521
523 ACTION_MODS_ONESHOT(MOD_LSFT) 522 ACTION_MODS_ONESHOT(MOD_LSFT)
524 523
525Say you want to type 'The', you have to push and hold Shift before type 't' then release Shift before type 'h' and 'e' or you'll get 'THe'. With One Shot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here. 524Say you want to type 'The', you have to push and hold Shift key before type 't' then release it before type 'h' and 'e', otherwise you'll get 'THe' or 'the' unintentionally. With Oneshot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here. This mean you can realease Shift before 't' is pressed down.
525
526Oneshot effect is cancel unless following key is pressed down within `ONESHOT_TIMEOUT` of `config.h`. No timeout when it is `0` or not defined.
526 527
527 528
528 529
diff --git a/keyboard/hhkb/Makefile b/keyboard/hhkb/Makefile
index 34bafc24f..94078702c 100644
--- a/keyboard/hhkb/Makefile
+++ b/keyboard/hhkb/Makefile
@@ -128,6 +128,8 @@ include $(TOP_DIR)/protocol/lufa.mk
128include $(TOP_DIR)/common.mk 128include $(TOP_DIR)/common.mk
129include $(TOP_DIR)/rules.mk 129include $(TOP_DIR)/rules.mk
130 130
131debug-on: EXTRAFLAGS += -DDEBUG 131debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
132#debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
133debug-on: all 132debug-on: all
133
134debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
135debug-off: all
diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h
index 83a911bea..a8f76ae6b 100644
--- a/keyboard/hhkb/config.h
+++ b/keyboard/hhkb/config.h
@@ -40,7 +40,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
40#define TAPPING_TERM 300 40#define TAPPING_TERM 300
41/* tap count needed for toggling a feature */ 41/* tap count needed for toggling a feature */
42#define TAPPING_TOGGLE 5 42#define TAPPING_TOGGLE 5
43 43/* Oneshot timeout(ms) */
44#define ONESHOT_TIMEOUT 300
44 45
45/* Boot Magic salt key: Space */ 46/* Boot Magic salt key: Space */
46#define BOOTMAGIC_KEY_SALT KC_FN6 47#define BOOTMAGIC_KEY_SALT KC_FN6