diff options
Diffstat (limited to 'common/command.c')
| -rw-r--r-- | common/command.c | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/common/command.c b/common/command.c index 16c6cfb88..0ad06e65b 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -24,9 +24,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | #include "util.h" | 24 | #include "util.h" |
| 25 | #include "timer.h" | 25 | #include "timer.h" |
| 26 | #include "keyboard.h" | 26 | #include "keyboard.h" |
| 27 | #include "matrix.h" | ||
| 28 | #include "bootloader.h" | 27 | #include "bootloader.h" |
| 29 | #include "command.h" | 28 | #include "command.h" |
| 29 | #ifdef MOUSEKEY_ENABLE | ||
| 30 | #include "mousekey.h" | ||
| 31 | #endif | ||
| 30 | 32 | ||
| 31 | #ifdef HOST_PJRC | 33 | #ifdef HOST_PJRC |
| 32 | # include "usb_keyboard.h" | 34 | # include "usb_keyboard.h" |
| @@ -40,44 +42,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 40 | #endif | 42 | #endif |
| 41 | 43 | ||
| 42 | 44 | ||
| 43 | static uint8_t command_common(void); | 45 | static bool command_common(uint8_t code); |
| 44 | static void help(void); | 46 | static void help(void); |
| 45 | static void switch_layer(uint8_t layer); | 47 | static void switch_layer(uint8_t layer); |
| 48 | static void clear_keyboard(void); | ||
| 46 | 49 | ||
| 47 | static bool last_print_enable; | 50 | static bool last_print_enable; |
| 48 | 51 | ||
| 49 | uint8_t command_proc(void) | ||
| 50 | { | ||
| 51 | uint8_t processed = 0; | ||
| 52 | last_print_enable = print_enable; | ||
| 53 | 52 | ||
| 53 | bool command_proc(uint8_t code) | ||
| 54 | { | ||
| 54 | if (!IS_COMMAND()) | 55 | if (!IS_COMMAND()) |
| 55 | return 0; | 56 | return false; |
| 56 | 57 | ||
| 58 | last_print_enable = print_enable; | ||
| 57 | print_enable = true; | 59 | print_enable = true; |
| 58 | if (command_extra() || command_common()) { | 60 | if (command_extra(code) || command_common(code)) { |
| 59 | processed = 1; | ||
| 60 | _delay_ms(500); | 61 | _delay_ms(500); |
| 62 | return true; | ||
| 61 | } | 63 | } |
| 62 | print_enable = last_print_enable; | 64 | print_enable = last_print_enable; |
| 63 | return processed; | 65 | return false; |
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | /* This allows to define extra commands. return 0 when not processed. */ | 68 | /* This allows to define extra commands. return 0 when not processed. */ |
| 67 | uint8_t command_extra(void) __attribute__ ((weak)); | 69 | bool command_extra(uint8_t code) __attribute__ ((weak)); |
| 68 | uint8_t command_extra(void) | 70 | bool command_extra(uint8_t code) |
| 69 | { | 71 | { |
| 70 | return 0; | 72 | return false; |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | 75 | ||
| 74 | static uint8_t command_common(void) | 76 | static bool command_common(uint8_t code) |
| 75 | { | 77 | { |
| 76 | switch (host_get_first_key()) { | 78 | switch (code) { |
| 77 | case KC_H: | 79 | case KC_H: |
| 78 | help(); | 80 | help(); |
| 79 | break; | 81 | break; |
| 80 | case KC_B: | 82 | case KC_DEL: |
| 83 | clear_keyboard(); | ||
| 81 | print("jump to bootloader... "); | 84 | print("jump to bootloader... "); |
| 82 | _delay_ms(1000); | 85 | _delay_ms(1000); |
| 83 | bootloader_jump(); // not return | 86 | bootloader_jump(); // not return |
| @@ -179,34 +182,34 @@ static uint8_t command_common(void) | |||
| 179 | #endif | 182 | #endif |
| 180 | break; | 183 | break; |
| 181 | #endif | 184 | #endif |
| 182 | case KC_BSPC: | ||
| 183 | matrix_init(); | ||
| 184 | print("clear matrix\n"); | ||
| 185 | break; | ||
| 186 | case KC_0: | 185 | case KC_0: |
| 186 | case KC_F10: | ||
| 187 | switch_layer(0); | 187 | switch_layer(0); |
| 188 | break; | 188 | break; |
| 189 | case KC_1: | 189 | case KC_1: |
| 190 | case KC_F1: | ||
| 190 | switch_layer(1); | 191 | switch_layer(1); |
| 191 | break; | 192 | break; |
| 192 | case KC_2: | 193 | case KC_2: |
| 194 | case KC_F2: | ||
| 193 | switch_layer(2); | 195 | switch_layer(2); |
| 194 | break; | 196 | break; |
| 195 | case KC_3: | 197 | case KC_3: |
| 198 | case KC_F3: | ||
| 196 | switch_layer(3); | 199 | switch_layer(3); |
| 197 | break; | 200 | break; |
| 198 | case KC_4: | 201 | case KC_4: |
| 202 | case KC_F4: | ||
| 199 | switch_layer(4); | 203 | switch_layer(4); |
| 200 | break; | 204 | break; |
| 201 | default: | 205 | default: |
| 202 | return 0; | 206 | return false; |
| 203 | } | 207 | } |
| 204 | return 1; | 208 | return true; |
| 205 | } | 209 | } |
| 206 | 210 | ||
| 207 | static void help(void) | 211 | static void help(void) |
| 208 | { | 212 | { |
| 209 | print("b: jump to bootloader\n"); | ||
| 210 | print("d: toggle debug enable\n"); | 213 | print("d: toggle debug enable\n"); |
| 211 | print("x: toggle matrix debug\n"); | 214 | print("x: toggle matrix debug\n"); |
| 212 | print("k: toggle keyboard debug\n"); | 215 | print("k: toggle keyboard debug\n"); |
| @@ -215,16 +218,16 @@ static void help(void) | |||
| 215 | print("v: print version\n"); | 218 | print("v: print version\n"); |
| 216 | print("t: print timer count\n"); | 219 | print("t: print timer count\n"); |
| 217 | print("s: print status\n"); | 220 | print("s: print status\n"); |
| 221 | print("ESC: power down/wake up\n"); | ||
| 222 | print("0/F10: switch to Layer0 \n"); | ||
| 223 | print("1/F1: switch to Layer1 \n"); | ||
| 224 | print("2/F2: switch to Layer2 \n"); | ||
| 225 | print("3/F3: switch to Layer3 \n"); | ||
| 226 | print("4/F4: switch to Layer4 \n"); | ||
| 218 | #ifdef NKRO_ENABLE | 227 | #ifdef NKRO_ENABLE |
| 219 | print("n: toggle NKRO\n"); | 228 | print("n: toggle NKRO\n"); |
| 220 | #endif | 229 | #endif |
| 221 | print("Backspace: clear matrix\n"); | 230 | print("DEL: jump to bootloader\n"); |
| 222 | print("ESC: power down/wake up\n"); | ||
| 223 | print("0: switch to Layer0 \n"); | ||
| 224 | print("1: switch to Layer1 \n"); | ||
| 225 | print("2: switch to Layer2 \n"); | ||
| 226 | print("3: switch to Layer3 \n"); | ||
| 227 | print("4: switch to Layer4 \n"); | ||
| 228 | } | 231 | } |
| 229 | 232 | ||
| 230 | static void switch_layer(uint8_t layer) | 233 | static void switch_layer(uint8_t layer) |
| @@ -235,3 +238,17 @@ static void switch_layer(uint8_t layer) | |||
| 235 | default_layer = layer; | 238 | default_layer = layer; |
| 236 | print("switch to Layer: "); phex(layer); print("\n"); | 239 | print("switch to Layer: "); phex(layer); print("\n"); |
| 237 | } | 240 | } |
| 241 | |||
| 242 | static void clear_keyboard(void) | ||
| 243 | { | ||
| 244 | host_clear_keys(); | ||
| 245 | host_send_keyboard_report(); | ||
| 246 | |||
| 247 | host_system_send(0); | ||
| 248 | host_consumer_send(0); | ||
| 249 | |||
| 250 | #ifdef MOUSEKEY_ENABLE | ||
| 251 | mousekey_clear(); | ||
| 252 | mousekey_send(); | ||
| 253 | #endif | ||
| 254 | } | ||
