]> git.donarmstrong.com Git - tmk_firmware.git/commitdiff
Ad hoc fix of command API
authortmk <nobody@nowhere>
Mon, 30 Jun 2014 19:02:10 +0000 (04:02 +0900)
committertmk <nobody@nowhere>
Wed, 30 Jul 2014 05:38:25 +0000 (14:38 +0900)
common/command.c
common/command.h

index 2c65f0da78ca7117a442ad86a215858500255c4d..971ef7f0af4ba9f4ba1cbd5a80c4327818b424f9 100644 (file)
@@ -63,19 +63,22 @@ static uint8_t numkey2num(uint8_t code);
 static void switch_default_layer(uint8_t layer);
 
 
 static void switch_default_layer(uint8_t layer);
 
 
-typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
-static cmdstate_t state = ONESHOT;
+command_state_t command_state = ONESHOT;
 
 
 bool command_proc(uint8_t code)
 {
 
 
 bool command_proc(uint8_t code)
 {
-    switch (state) {
+    switch (command_state) {
         case ONESHOT:
             if (!IS_COMMAND())
                 return false;
             return (command_extra(code) || command_common(code));
         case ONESHOT:
             if (!IS_COMMAND())
                 return false;
             return (command_extra(code) || command_common(code));
+            break;
         case CONSOLE:
         case CONSOLE:
-            command_console(code);
+            if (IS_COMMAND())
+                return (command_extra(code) || command_common(code));
+            else
+                return (command_console_extra(code) || command_console(code));
             break;
 #ifdef MOUSEKEY_ENABLE
         case MOUSEKEY:
             break;
 #ifdef MOUSEKEY_ENABLE
         case MOUSEKEY:
@@ -83,12 +86,13 @@ bool command_proc(uint8_t code)
             break;
 #endif
         default:
             break;
 #endif
         default:
-            state = ONESHOT;
+            command_state = ONESHOT;
             return false;
     }
     return true;
 }
 
             return false;
     }
     return true;
 }
 
+/* TODO: Refactoring is needed. */
 /* This allows to define extra commands. return false when not processed. */
 bool command_extra(uint8_t code) __attribute__ ((weak));
 bool command_extra(uint8_t code)
 /* This allows to define extra commands. return false when not processed. */
 bool command_extra(uint8_t code) __attribute__ ((weak));
 bool command_extra(uint8_t code)
@@ -96,6 +100,12 @@ bool command_extra(uint8_t code)
     return false;
 }
 
     return false;
 }
 
+bool command_console_extra(uint8_t code) __attribute__ ((weak));
+bool command_console_extra(uint8_t code)
+{
+    return false;
+}
+
 
 /***********************************************************
  * Command common
 
 /***********************************************************
  * Command common
@@ -203,7 +213,7 @@ static bool command_common(uint8_t code)
             command_console_help();
             print("\nEnter Console Mode\n");
             print("C> ");
             command_console_help();
             print("\nEnter Console Mode\n");
             print("C> ");
-            state = CONSOLE;
+            command_state = CONSOLE;
             break;
         case KC_PAUSE:
             clear_keyboard();
             break;
         case KC_PAUSE:
             clear_keyboard();
@@ -388,14 +398,14 @@ static bool command_console(uint8_t code)
         case KC_Q:
         case KC_ESC:
             print("\nQuit Console Mode\n");
         case KC_Q:
         case KC_ESC:
             print("\nQuit Console Mode\n");
-            state = ONESHOT;
+            command_state = ONESHOT;
             return false;
 #ifdef MOUSEKEY_ENABLE
         case KC_M:
             mousekey_console_help();
             print("\nEnter Mousekey Console\n");
             print("M0>");
             return false;
 #ifdef MOUSEKEY_ENABLE
         case KC_M:
             mousekey_console_help();
             print("\nEnter Mousekey Console\n");
             print("M0>");
-            state = MOUSEKEY;
+            command_state = MOUSEKEY;
             return true;
 #endif
         default:
             return true;
 #endif
         default:
@@ -555,7 +565,7 @@ static bool mousekey_console(uint8_t code)
             mousekey_param = 0;
             print("\nQuit Mousekey Console\n");
             print("C> ");
             mousekey_param = 0;
             print("\nQuit Mousekey Console\n");
             print("C> ");
-            state = CONSOLE;
+            command_state = CONSOLE;
             return false;
         case KC_P:
             mousekey_param_print();
             return false;
         case KC_P:
             mousekey_param_print();
index be739fafe822d17b3ceda61048df010f6cfd44d1..b57a6c1cedc504ae77862f5d1f12a9914ee8be22 100644 (file)
@@ -18,10 +18,16 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef COMMAND_H
 #define COMMAND
 
 #ifndef COMMAND_H
 #define COMMAND
 
+/* TODO: Refactoring */
+typedef enum { ONESHOT, CONSOLE, MOUSEKEY } command_state_t;
+extern command_state_t command_state;
+
+/* This allows to extend commands. Return false when command is not processed. */
+bool command_extra(uint8_t code);
+bool command_console_extra(uint8_t code);
+
 #ifdef COMMAND_ENABLE
 bool command_proc(uint8_t code);
 #ifdef COMMAND_ENABLE
 bool command_proc(uint8_t code);
-/* This allows to extend commands. Return 0 when command is not processed. */
-bool command_extra(uint8_t code);
 #else
 #define command_proc(code)      false
 #endif
 #else
 #define command_proc(code)      false
 #endif