aboutsummaryrefslogtreecommitdiff
path: root/common/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/command.c')
-rw-r--r--common/command.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/common/command.c b/common/command.c
index 2c65f0da7..971ef7f0a 100644
--- a/common/command.c
+++ b/common/command.c
@@ -63,19 +63,22 @@ static uint8_t numkey2num(uint8_t code);
63static void switch_default_layer(uint8_t layer); 63static void switch_default_layer(uint8_t layer);
64 64
65 65
66typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; 66command_state_t command_state = ONESHOT;
67static cmdstate_t state = ONESHOT;
68 67
69 68
70bool command_proc(uint8_t code) 69bool command_proc(uint8_t code)
71{ 70{
72 switch (state) { 71 switch (command_state) {
73 case ONESHOT: 72 case ONESHOT:
74 if (!IS_COMMAND()) 73 if (!IS_COMMAND())
75 return false; 74 return false;
76 return (command_extra(code) || command_common(code)); 75 return (command_extra(code) || command_common(code));
76 break;
77 case CONSOLE: 77 case CONSOLE:
78 command_console(code); 78 if (IS_COMMAND())
79 return (command_extra(code) || command_common(code));
80 else
81 return (command_console_extra(code) || command_console(code));
79 break; 82 break;
80#ifdef MOUSEKEY_ENABLE 83#ifdef MOUSEKEY_ENABLE
81 case MOUSEKEY: 84 case MOUSEKEY:
@@ -83,12 +86,13 @@ bool command_proc(uint8_t code)
83 break; 86 break;
84#endif 87#endif
85 default: 88 default:
86 state = ONESHOT; 89 command_state = ONESHOT;
87 return false; 90 return false;
88 } 91 }
89 return true; 92 return true;
90} 93}
91 94
95/* TODO: Refactoring is needed. */
92/* This allows to define extra commands. return false when not processed. */ 96/* This allows to define extra commands. return false when not processed. */
93bool command_extra(uint8_t code) __attribute__ ((weak)); 97bool command_extra(uint8_t code) __attribute__ ((weak));
94bool command_extra(uint8_t code) 98bool command_extra(uint8_t code)
@@ -96,6 +100,12 @@ bool command_extra(uint8_t code)
96 return false; 100 return false;
97} 101}
98 102
103bool command_console_extra(uint8_t code) __attribute__ ((weak));
104bool command_console_extra(uint8_t code)
105{
106 return false;
107}
108
99 109
100/*********************************************************** 110/***********************************************************
101 * Command common 111 * Command common
@@ -203,7 +213,7 @@ static bool command_common(uint8_t code)
203 command_console_help(); 213 command_console_help();
204 print("\nEnter Console Mode\n"); 214 print("\nEnter Console Mode\n");
205 print("C> "); 215 print("C> ");
206 state = CONSOLE; 216 command_state = CONSOLE;
207 break; 217 break;
208 case KC_PAUSE: 218 case KC_PAUSE:
209 clear_keyboard(); 219 clear_keyboard();
@@ -388,14 +398,14 @@ static bool command_console(uint8_t code)
388 case KC_Q: 398 case KC_Q:
389 case KC_ESC: 399 case KC_ESC:
390 print("\nQuit Console Mode\n"); 400 print("\nQuit Console Mode\n");
391 state = ONESHOT; 401 command_state = ONESHOT;
392 return false; 402 return false;
393#ifdef MOUSEKEY_ENABLE 403#ifdef MOUSEKEY_ENABLE
394 case KC_M: 404 case KC_M:
395 mousekey_console_help(); 405 mousekey_console_help();
396 print("\nEnter Mousekey Console\n"); 406 print("\nEnter Mousekey Console\n");
397 print("M0>"); 407 print("M0>");
398 state = MOUSEKEY; 408 command_state = MOUSEKEY;
399 return true; 409 return true;
400#endif 410#endif
401 default: 411 default:
@@ -555,7 +565,7 @@ static bool mousekey_console(uint8_t code)
555 mousekey_param = 0; 565 mousekey_param = 0;
556 print("\nQuit Mousekey Console\n"); 566 print("\nQuit Mousekey Console\n");
557 print("C> "); 567 print("C> ");
558 state = CONSOLE; 568 command_state = CONSOLE;
559 return false; 569 return false;
560 case KC_P: 570 case KC_P:
561 mousekey_param_print(); 571 mousekey_param_print();