diff options
| author | tmk <nobody@nowhere> | 2014-07-01 04:02:10 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-07-30 14:38:25 +0900 |
| commit | 47bc3016d36cbfd83904fff5947acb6436dd37c3 (patch) | |
| tree | 11aca2e377b5c6acb70508b471f9c3e0f90c0052 | |
| parent | 4069776c022502f117b83b66c5a71700135acfbc (diff) | |
| download | qmk_firmware-47bc3016d36cbfd83904fff5947acb6436dd37c3.tar.gz qmk_firmware-47bc3016d36cbfd83904fff5947acb6436dd37c3.zip | |
Ad hoc fix of command API
| -rw-r--r-- | common/command.c | 28 | ||||
| -rw-r--r-- | common/command.h | 10 |
2 files changed, 27 insertions, 11 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); | |||
| 63 | static void switch_default_layer(uint8_t layer); | 63 | static void switch_default_layer(uint8_t layer); |
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; | 66 | command_state_t command_state = ONESHOT; |
| 67 | static cmdstate_t state = ONESHOT; | ||
| 68 | 67 | ||
| 69 | 68 | ||
| 70 | bool command_proc(uint8_t code) | 69 | bool 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. */ |
| 93 | bool command_extra(uint8_t code) __attribute__ ((weak)); | 97 | bool command_extra(uint8_t code) __attribute__ ((weak)); |
| 94 | bool command_extra(uint8_t code) | 98 | bool 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 | ||
| 103 | bool command_console_extra(uint8_t code) __attribute__ ((weak)); | ||
| 104 | bool 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(); |
diff --git a/common/command.h b/common/command.h index be739fafe..b57a6c1ce 100644 --- a/common/command.h +++ b/common/command.h | |||
| @@ -18,10 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 18 | #ifndef COMMAND_H | 18 | #ifndef COMMAND_H |
| 19 | #define COMMAND | 19 | #define COMMAND |
| 20 | 20 | ||
| 21 | /* TODO: Refactoring */ | ||
| 22 | typedef enum { ONESHOT, CONSOLE, MOUSEKEY } command_state_t; | ||
| 23 | extern command_state_t command_state; | ||
| 24 | |||
| 25 | /* This allows to extend commands. Return false when command is not processed. */ | ||
| 26 | bool command_extra(uint8_t code); | ||
| 27 | bool command_console_extra(uint8_t code); | ||
| 28 | |||
| 21 | #ifdef COMMAND_ENABLE | 29 | #ifdef COMMAND_ENABLE |
| 22 | bool command_proc(uint8_t code); | 30 | bool command_proc(uint8_t code); |
| 23 | /* This allows to extend commands. Return 0 when command is not processed. */ | ||
| 24 | bool command_extra(uint8_t code); | ||
| 25 | #else | 31 | #else |
| 26 | #define command_proc(code) false | 32 | #define command_proc(code) false |
| 27 | #endif | 33 | #endif |
