]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/common/action.c
xt_usb: Fix XT soft reset
[max/tmk_keyboard.git] / tmk_core / common / action.c
index 339b3ee67edf6628f30b33fc64cd63ea834b1a96..85a0631ffe3960a14220d0a2a41c4165110e7675 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
+Copyright 2012,2013,2020 Jun Wako <wakojun@gmail.com>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -26,6 +26,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "action_macro.h"
 #include "action_util.h"
 #include "action.h"
+#include "hook.h"
+#include "wait.h"
+#include "bootloader.h"
 
 #ifdef DEBUG_ACTION
 #include "debug.h"
@@ -39,6 +42,7 @@ void action_exec(keyevent_t event)
     if (!IS_NOEVENT(event)) {
         dprint("\n---- action_exec: start -----\n");
         dprint("EVENT: "); debug_event(event); dprintln();
+        hook_matrix_change(event);
     }
 
     keyrecord_t record = { .event = event };
@@ -55,6 +59,8 @@ void action_exec(keyevent_t event)
 
 void process_action(keyrecord_t *record)
 {
+    if (hook_process_action(record)) return;
+
     keyevent_t event = record->event;
 #ifndef NO_ACTION_TAPPING
     uint8_t tap_count = record->tap.count;
@@ -62,7 +68,7 @@ void process_action(keyrecord_t *record)
 
     if (IS_NOEVENT(event)) { return; }
 
-    action_t action = layer_switch_get_action(event.key);
+    action_t action = layer_switch_get_action(event);
     dprint("ACTION: "); debug_action(action);
 #ifndef NO_ACTION_LAYER
     dprint(" layer_state: "); layer_debug();
@@ -98,7 +104,7 @@ void process_action(keyrecord_t *record)
             {
                 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ?  action.key.mods :
                                                                     action.key.mods<<4;
-                switch (action.layer_tap.code) {
+                switch (action.key.code) {
     #ifndef NO_ACTION_ONESHOT
                     case MODS_ONESHOT:
                         // Oneshot modifier
@@ -244,14 +250,18 @@ void process_action(keyrecord_t *record)
         case ACT_LAYER_TAP:
         case ACT_LAYER_TAP_EXT:
             switch (action.layer_tap.code) {
-                case 0xe0 ... 0xef:
-                    /* layer On/Off with modifiers(left only) */
+                case 0xc0 ... 0xdf:
+                    /* layer On/Off with modifiers */
                     if (event.pressed) {
                         layer_on(action.layer_tap.val);
-                        register_mods(action.layer_tap.code & 0x0f);
+                        register_mods((action.layer_tap.code & 0x10) ?
+                                (action.layer_tap.code & 0x0f) << 4 :
+                                (action.layer_tap.code & 0x0f));
                     } else {
                         layer_off(action.layer_tap.val);
-                        unregister_mods(action.layer_tap.code & 0x0f);
+                        unregister_mods((action.layer_tap.code & 0x10) ?
+                                (action.layer_tap.code & 0x0f) << 4 :
+                                (action.layer_tap.code & 0x0f));
                     }
                     break;
                 case OP_TAP_TOGGLE:
@@ -332,6 +342,15 @@ void process_action(keyrecord_t *record)
             break;
 #endif
         case ACT_COMMAND:
+            switch (action.command.id) {
+                case COMMAND_BOOTLOADER:
+                    if (event.pressed) {
+                        clear_keyboard();
+                        wait_ms(50);
+                        bootloader_jump();
+                    }
+                    break;
+            }
             break;
 #ifndef NO_ACTION_FUNCTION
         case ACT_FUNCTION:
@@ -363,6 +382,7 @@ void register_code(uint8_t code)
 #endif
         add_key(KC_CAPSLOCK);
         send_keyboard_report();
+        wait_ms(100);
         del_key(KC_CAPSLOCK);
         send_keyboard_report();
     }
@@ -373,6 +393,7 @@ void register_code(uint8_t code)
 #endif
         add_key(KC_NUMLOCK);
         send_keyboard_report();
+        wait_ms(100);
         del_key(KC_NUMLOCK);
         send_keyboard_report();
     }
@@ -383,6 +404,7 @@ void register_code(uint8_t code)
 #endif
         add_key(KC_SCROLLLOCK);
         send_keyboard_report();
+        wait_ms(100);
         del_key(KC_SCROLLLOCK);
         send_keyboard_report();
     }
@@ -438,6 +460,7 @@ void unregister_code(uint8_t code)
 #endif
         add_key(KC_CAPSLOCK);
         send_keyboard_report();
+        wait_ms(100);
         del_key(KC_CAPSLOCK);
         send_keyboard_report();
     }
@@ -448,6 +471,7 @@ void unregister_code(uint8_t code)
 #endif
         add_key(KC_NUMLOCK);
         send_keyboard_report();
+        wait_ms(100);
         del_key(KC_NUMLOCK);
         send_keyboard_report();
     }
@@ -458,6 +482,7 @@ void unregister_code(uint8_t code)
 #endif
         add_key(KC_SCROLLLOCK);
         send_keyboard_report();
+        wait_ms(100);
         del_key(KC_SCROLLLOCK);
         send_keyboard_report();
     }
@@ -479,6 +504,12 @@ void unregister_code(uint8_t code)
     }
 }
 
+void type_code(uint8_t code)
+{
+    register_code(code);
+    unregister_code(code);
+}
+
 void register_mods(uint8_t mods)
 {
     if (mods) {
@@ -516,17 +547,29 @@ void clear_keyboard_but_mods(void)
 #endif
 }
 
-bool is_tap_key(keypos_t key)
+bool is_tap_key(keyevent_t event)
 {
-    action_t action = layer_switch_get_action(key);
+    if (IS_NOEVENT(event)) { return false; }
+
+    action_t action = layer_switch_get_action(event);
 
     switch (action.kind.id) {
         case ACT_LMODS_TAP:
         case ACT_RMODS_TAP:
+            switch (action.key.code) {
+                case MODS_ONESHOT:
+                case MODS_TAP_TOGGLE:
+                case KC_A ... KC_EXSEL:                 // tap key
+                case KC_LCTRL ... KC_RGUI:              // tap key
+                    return true;
+            }
         case ACT_LAYER_TAP:
         case ACT_LAYER_TAP_EXT:
             switch (action.layer_tap.code) {
-                case 0x00 ... 0xdf:
+                case 0xc0 ... 0xdf:         // with modifiers
+                    return false;
+                case KC_A ... KC_EXSEL:     // tap key
+                case KC_LCTRL ... KC_RGUI:  // tap key
                 case OP_TAP_TOGGLE:
                     return true;
             }