X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=common%2Fcommand.c;h=0ad06e65b846586c5a9b4ee0348e922309e6ec1b;hb=e451c059296a4c9af7a476577fee64afb9965bca;hp=e325a5d847e144c3ba1c6d384f1b17fbb04ac2b6;hpb=62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26;p=max%2Ftmk_keyboard.git
diff --git a/common/command.c b/common/command.c
index e325a5d8..0ad06e65 100644
--- a/common/command.c
+++ b/common/command.c
@@ -17,16 +17,18 @@ along with this program. If not, see .
#include
#include
#include
-#include "usb_keycodes.h"
+#include "keycode.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "util.h"
#include "timer.h"
-#include "layer.h"
-#include "matrix.h"
+#include "keyboard.h"
#include "bootloader.h"
#include "command.h"
+#ifdef MOUSEKEY_ENABLE
+#include "mousekey.h"
+#endif
#ifdef HOST_PJRC
# include "usb_keyboard.h"
@@ -40,52 +42,51 @@ along with this program. If not, see .
#endif
-static uint8_t command_common(void);
+static bool command_common(uint8_t code);
static void help(void);
static void switch_layer(uint8_t layer);
+static void clear_keyboard(void);
static bool last_print_enable;
-uint8_t command_proc(void)
-{
- uint8_t processed = 0;
- last_print_enable = print_enable;
+bool command_proc(uint8_t code)
+{
if (!IS_COMMAND())
- return 0;
+ return false;
+ last_print_enable = print_enable;
print_enable = true;
- if (command_extra() || command_common()) {
- processed = 1;
+ if (command_extra(code) || command_common(code)) {
_delay_ms(500);
+ return true;
}
print_enable = last_print_enable;
- return processed;
+ return false;
}
/* This allows to define extra commands. return 0 when not processed. */
-uint8_t command_extra(void) __attribute__ ((weak));
-uint8_t command_extra(void)
+bool command_extra(uint8_t code) __attribute__ ((weak));
+bool command_extra(uint8_t code)
{
- return 0;
+ return false;
}
-static uint8_t command_common(void)
+static bool command_common(uint8_t code)
{
- switch (host_get_first_key()) {
- case KB_H:
+ switch (code) {
+ case KC_H:
help();
break;
- case KB_B:
- host_clear_keyboard_report();
- host_send_keyboard_report();
+ case KC_DEL:
+ clear_keyboard();
print("jump to bootloader... ");
_delay_ms(1000);
bootloader_jump(); // not return
print("not supported.\n");
break;
- case KB_D:
+ case KC_D:
debug_enable = !debug_enable;
if (debug_enable) {
last_print_enable = true;
@@ -101,34 +102,34 @@ static uint8_t command_common(void)
debug_mouse = false;
}
break;
- case KB_X: // debug matrix toggle
+ case KC_X: // debug matrix toggle
debug_matrix = !debug_matrix;
if (debug_matrix)
print("debug matrix enabled.\n");
else
print("debug matrix disabled.\n");
break;
- case KB_K: // debug keyboard toggle
+ case KC_K: // debug keyboard toggle
debug_keyboard = !debug_keyboard;
if (debug_keyboard)
print("debug keyboard enabled.\n");
else
print("debug keyboard disabled.\n");
break;
- case KB_M: // debug mouse toggle
+ case KC_M: // debug mouse toggle
debug_mouse = !debug_mouse;
if (debug_mouse)
print("debug mouse enabled.\n");
else
print("debug mouse disabled.\n");
break;
- case KB_V: // print version & information
+ case KC_V: // print version & information
print(STR(DESCRIPTION) "\n");
break;
- case KB_T: // print timer
+ case KC_T: // print timer
print("timer: "); phex16(timer_count); print("\n");
break;
- case KB_P: // print toggle
+ case KC_P: // print toggle
if (last_print_enable) {
print("print disabled.\n");
last_print_enable = false;
@@ -137,7 +138,8 @@ static uint8_t command_common(void)
print("print enabled.\n");
}
break;
- case KB_S:
+ case KC_S:
+ print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
#ifdef HOST_PJRC
print("UDCON: "); phex(UDCON); print("\n");
print("UDIEN: "); phex(UDIEN); print("\n");
@@ -155,10 +157,7 @@ static uint8_t command_common(void)
#endif
break;
#ifdef NKRO_ENABLE
- case KB_N:
- // send empty report before change
- host_clear_keyboard_report();
- host_send_keyboard_report();
+ case KC_N:
keyboard_nkro = !keyboard_nkro;
if (keyboard_nkro)
print("NKRO: enabled\n");
@@ -167,9 +166,7 @@ static uint8_t command_common(void)
break;
#endif
#ifdef EXTRAKEY_ENABLE
- case KB_ESC:
- host_clear_keyboard_report();
- host_send_keyboard_report();
+ case KC_ESC:
#ifdef HOST_PJRC
if (suspend && remote_wakeup) {
usb_remote_wakeup();
@@ -185,34 +182,34 @@ static uint8_t command_common(void)
#endif
break;
#endif
- case KB_BSPC:
- matrix_init();
- print("clear matrix\n");
- break;
- case KB_0:
+ case KC_0:
+ case KC_F10:
switch_layer(0);
break;
- case KB_1:
+ case KC_1:
+ case KC_F1:
switch_layer(1);
break;
- case KB_2:
+ case KC_2:
+ case KC_F2:
switch_layer(2);
break;
- case KB_3:
+ case KC_3:
+ case KC_F3:
switch_layer(3);
break;
- case KB_4:
+ case KC_4:
+ case KC_F4:
switch_layer(4);
break;
default:
- return 0;
+ return false;
}
- return 1;
+ return true;
}
static void help(void)
{
- print("b: jump to bootloader\n");
print("d: toggle debug enable\n");
print("x: toggle matrix debug\n");
print("k: toggle keyboard debug\n");
@@ -221,16 +218,16 @@ static void help(void)
print("v: print version\n");
print("t: print timer count\n");
print("s: print status\n");
+ print("ESC: power down/wake up\n");
+ print("0/F10: switch to Layer0 \n");
+ print("1/F1: switch to Layer1 \n");
+ print("2/F2: switch to Layer2 \n");
+ print("3/F3: switch to Layer3 \n");
+ print("4/F4: switch to Layer4 \n");
#ifdef NKRO_ENABLE
print("n: toggle NKRO\n");
#endif
- print("Backspace: clear matrix\n");
- print("ESC: power down/wake up\n");
- print("0: switch to Layer0 \n");
- print("1: switch to Layer1 \n");
- print("2: switch to Layer2 \n");
- print("3: switch to Layer3 \n");
- print("4: switch to Layer4 \n");
+ print("DEL: jump to bootloader\n");
}
static void switch_layer(uint8_t layer)
@@ -241,3 +238,17 @@ static void switch_layer(uint8_t layer)
default_layer = layer;
print("switch to Layer: "); phex(layer); print("\n");
}
+
+static void clear_keyboard(void)
+{
+ host_clear_keys();
+ host_send_keyboard_report();
+
+ host_system_send(0);
+ host_consumer_send(0);
+
+#ifdef MOUSEKEY_ENABLE
+ mousekey_clear();
+ mousekey_send();
+#endif
+}