]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - common/command.c
Replace layer_stack with layer_switch
[tmk_firmware.git] / common / command.c
index 85cc05733a4a8dce5b5157ab5e16117ae4e2fbc9..82f647c8f3e5d4de827a6d724f009da5ea0f3d86 100644 (file)
@@ -19,13 +19,16 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <util/delay.h>
 #include "keycode.h"
 #include "host.h"
+#include "keymap.h"
 #include "print.h"
 #include "debug.h"
 #include "util.h"
 #include "timer.h"
 #include "keyboard.h"
 #include "bootloader.h"
+#include "layer_switch.h"
 #include "command.h"
+
 #ifdef MOUSEKEY_ENABLE
 #include "mousekey.h"
 #endif
@@ -52,8 +55,7 @@ static void mousekey_console_help(void);
 #endif
 
 static uint8_t numkey2num(uint8_t code);
-static void switch_layer(uint8_t layer);
-static void clear_keyboard(void);
+static void switch_default_layer(uint8_t layer);
 
 
 typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
@@ -164,9 +166,6 @@ static bool command_common(uint8_t code)
                 debug_enable   = false;
             } else {
                 print("\nDEBUG: enabled.\n");
-                debug_matrix   = true;
-                debug_keyboard = true;
-                debug_mouse    = true;
                 debug_enable   = true;
             }
             break;
@@ -205,7 +204,7 @@ static bool command_common(uint8_t code)
             print("VERSION: " STR(DEVICE_VER) "\n");
             break;
         case KC_T: // print timer
-            pv_hex32(timer_count);
+            print_val_hex32(timer_count);
             break;
         case KC_P: // print toggle
             if (print_enable) {
@@ -218,25 +217,26 @@ static bool command_common(uint8_t code)
             break;
         case KC_S:
             print("\n\n----- Status -----\n");
-            pv_hex8(host_keyboard_leds());
+            print_val_hex8(host_keyboard_leds());
 #ifdef HOST_PJRC
-            pv_hex8(UDCON);
-            pv_hex8(UDIEN);
-            pv_hex8(UDINT);
-            pv_hex8(usb_keyboard_leds);
-            pv_hex8(usb_keyboard_protocol);
-            pv_hex8(usb_keyboard_idle_config);
-            pv_hex8(usb_keyboard_idle_count);
+            print_val_hex8(UDCON);
+            print_val_hex8(UDIEN);
+            print_val_hex8(UDINT);
+            print_val_hex8(usb_keyboard_leds);
+            print_val_hex8(usb_keyboard_protocol);
+            print_val_hex8(usb_keyboard_idle_config);
+            print_val_hex8(usb_keyboard_idle_count);
 #endif
 
 #ifdef HOST_VUSB
 #   if USB_COUNT_SOF
-            pv_hex8(usbSofCount);
+            print_val_hex8(usbSofCount);
 #   endif
 #endif
             break;
 #ifdef NKRO_ENABLE
         case KC_N:
+            clear_keyboard(); //Prevents stuck keys.
             keyboard_nkro = !keyboard_nkro;
             if (keyboard_nkro)
                 print("NKRO: enabled\n");
@@ -263,25 +263,16 @@ static bool command_common(uint8_t code)
 #endif
             break;
 #endif
+        case KC_ESC:
+        case KC_GRV:
         case KC_0:
-        case KC_F10:
-            switch_layer(0);
-            break;
-        case KC_1:
-        case KC_F1:
-            switch_layer(1);
+            switch_default_layer(0);
             break;
-        case KC_2:
-        case KC_F2:
-            switch_layer(2);
-            break;
-        case KC_3:
-        case KC_F3:
-            switch_layer(3);
+        case KC_1 ... KC_9:
+            switch_default_layer((code - KC_1) + 1);
             break;
-        case KC_4:
-        case KC_F4:
-            switch_layer(4);
+        case KC_F1 ... KC_F12:
+            switch_default_layer((code - KC_F1) + 1);
             break;
         default:
             print("?");
@@ -350,7 +341,7 @@ static void mousekey_param_print(void)
     print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
 }
 
-#define PRINT_SET_VAL(v)  print(#v " = "); print_dec8(v); print("\n");
+#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
 static void mousekey_param_inc(uint8_t param, uint8_t inc)
 {
     switch (param) {
@@ -550,26 +541,14 @@ static uint8_t numkey2num(uint8_t code)
     return 0;
 }
 
-static void switch_layer(uint8_t layer)
+static void switch_default_layer(uint8_t layer)
 {
-    pv_hex8(current_layer);
-    pv_hex8(default_layer);
-    current_layer = layer;
-    default_layer = layer;
-    print("switch to "); pv_hex8(layer);
-}
-
-static void clear_keyboard(void)
-{
-    host_clear_keys();
-    host_clear_mods();
-    host_send_keyboard_report();
+    print_val_hex8(current_layer);
+    print_val_hex8(default_layer);
+    print("switch to "); print_val_hex8(layer);
 
-    host_system_send(0);
-    host_consumer_send(0);
-
-#ifdef MOUSEKEY_ENABLE
-    mousekey_clear();
-    mousekey_send();
-#endif
+    default_layer = layer;
+    current_layer = 0;  /* 0 means default_layer */
+    layer_switch_clear();
+    clear_keyboard();
 }