summary refs log tree commit diff
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)
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 ecd5a7e94f..f7ae85b941 100644
--- a/common/action.c
+++ b/common/action.c
@@ -100,40 +100,29 @@ void process_action(keyrecord_t *record)
                                                                     action.key.mods<<4;
                 switch (action.layer_tap.code) {
     #ifndef NO_ACTION_ONESHOT
-                    case 0x00:
+                    case MODS_ONESHOT:
                         // Oneshot modifier
                         if (event.pressed) {
                             if (tap_count == 0) {
-                                dprint("MODS_TAP: Oneshot: add_mods\n");
                                 register_mods(mods);
                             }
                             else if (tap_count == 1) {
                                 dprint("MODS_TAP: Oneshot: start\n");
                                 set_oneshot_mods(mods);
                             }
-                            else if (tap_count == TAPPING_TOGGLE) {
-                                dprint("MODS_TAP: Oneshot: toggle\n");
-                                oneshot_toggle();
-                            }
                             else {
-                                dprint("MODS_TAP: Oneshot: cancel&add_mods\n");
-                                // double tap cancels oneshot and works as normal modifier.
-                                clear_oneshot_mods();
                                 register_mods(mods);
                             }
                         } else {
                             if (tap_count == 0) {
-                                dprint("MODS_TAP: Oneshot: cancel/del_mods\n");
-                                // cancel oneshot on hold
                                 clear_oneshot_mods();
                                 unregister_mods(mods);
                             }
                             else if (tap_count == 1) {
-                                // Oneshot
+                                // Retain Oneshot mods
                             }
                             else {
-                                dprint("MODS_TAP: Oneshot: del_mods\n");
-                                // cancel Mods
+                                clear_oneshot_mods();
                                 unregister_mods(mods);
                             }
                         }
diff --git a/common/action_util.c b/common/action_util.c
index 50d686a07d..99a3adaab6 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/>.
 #include "report.h"
 #include "debug.h"
 #include "action_util.h"
+#include "timer.h"
 
 static inline void add_key_byte(uint8_t code);
 static inline void del_key_byte(uint8_t code);
@@ -35,17 +36,28 @@ static uint8_t weak_mods = 0;
 report_keyboard_t *keyboard_report = &(report_keyboard_t){};
 
 #ifndef NO_ACTION_ONESHOT
-static bool oneshot_enabled = true;
 static int8_t oneshot_mods = 0;
+#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+static int16_t oneshot_time = 0;
 #endif
+#endif
+
 
 void send_keyboard_report(void) {
     keyboard_report->mods  = real_mods;
     keyboard_report->mods |= weak_mods;
 #ifndef NO_ACTION_ONESHOT
-    keyboard_report->mods |= oneshot_mods;
-    if (has_anykey()) {
-        clear_oneshot_mods();
+    if (oneshot_mods) {
+#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+        if (TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT) {
+            dprintf("Oneshot: timeout\n");
+            clear_oneshot_mods();
+        }
+#endif
+        keyboard_report->mods |= oneshot_mods;
+        if (has_anykey()) {
+            clear_oneshot_mods();
+        }
     }
 #endif
     host_keyboard_send(keyboard_report);
@@ -99,11 +111,20 @@ void clear_weak_mods(void) { weak_mods = 0; }
 
 /* Oneshot modifier */
 #ifndef NO_ACTION_ONESHOT
-void set_oneshot_mods(uint8_t mods) { oneshot_mods = mods; }
-void clear_oneshot_mods(void) { oneshot_mods = 0; }
-void oneshot_toggle(void) { oneshot_enabled = !oneshot_enabled; }
-void oneshot_enable(void) { oneshot_enabled = true; }
-void oneshot_disable(void) { oneshot_enabled = false; }
+void set_oneshot_mods(uint8_t mods)
+{
+    oneshot_mods = mods;
+#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+    oneshot_time = timer_read();
+#endif
+}
+void clear_oneshot_mods(void)
+{
+    oneshot_mods = 0;
+#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+    oneshot_time = 0;
+#endif
+}
 #endif