]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Added more CLI commands.
authorJacob Alexander <haata@kiibohd.com>
Thu, 23 Jan 2014 10:36:00 +0000 (02:36 -0800)
committerJacob Alexander <haata@kiibohd.com>
Sat, 22 Mar 2014 21:11:50 +0000 (14:11 -0700)
- Hex debug for debugging VT100 control characters from the keyboard
- Renamed reset to restart (software reset)
- Added reset command (same as bash reset, which resets the VT100 variables)
- Cleaned up the version module field

Debug/cli/cli.c
Debug/cli/cli.h
Lib/_buildvars.h

index 80a8af92bf9231d09e214bbf1314ff6fd4c08107..7b38a436adab88f03d056ad17defa8a69bf5247b 100644 (file)
@@ -40,7 +40,8 @@ CLIDictItem basicCLIDict[] = {
        { "help",     "You're looking at it :P", cliFunc_help },
        { "led",      "Enables/Disables indicator LED. Try a couple times just in case the LED is in an odd state.\r\n\t\t\033[33mWarning\033[0m: May adversely affect some modules...", cliFunc_led },
        { "reload",   "Signals microcontroller to reflash/reload.", cliFunc_reload },
-       { "reset",    "Sends a software reset, should be similar to powering on the device.", cliFunc_reset },
+       { "reset",    "Resets the terminal back to initial settings.", cliFunc_reset },
+       { "restart",  "Sends a software restart, should be similar to powering on the device.", cliFunc_restart },
        { "version",  "Version information about this firmware.", cliFunc_version },
        { 0, 0, 0 } // Null entry for dictionary end
 };
@@ -51,9 +52,11 @@ CLIDictItem basicCLIDict[] = {
 
 inline void prompt()
 {
+       print("\033[2K"); // Erases the current line
        print(": ");
 }
 
+// Initialize the CLI
 inline void init_cli()
 {
        // Reset the Line Buffer
@@ -69,8 +72,12 @@ inline void init_cli()
        // Initialize main LED
        init_errorLED();
        CLILEDState = 0;
+
+       // Hex debug mode is off by default
+       CLIHexDebugMode = 0;
 }
 
+// Query the serial input buffer for any new characters
 void process_cli()
 {
        // Current buffer position
@@ -106,6 +113,22 @@ void process_cli()
                CLILineBuffer[CLILineBufferCurrent++] = cur_char;
        }
 
+       // Display Hex Key Input if enabled
+       if ( CLIHexDebugMode && CLILineBufferCurrent > prev_buf_pos )
+       {
+               print("\033[s\r\n"); // Save cursor position, and move to the next line
+               print("\033[2K");    // Erases the current line
+
+               uint8_t pos = prev_buf_pos;
+               while ( CLILineBufferCurrent > pos )
+               {
+                       printHex( CLILineBuffer[pos++] );
+                       print(" ");
+               }
+
+               print("\033[u"); // Restore cursor position
+       }
+
        // If buffer has changed, output to screen while there are still characters in the buffer not displayed
        while ( CLILineBufferCurrent > prev_buf_pos )
        {
@@ -168,17 +191,6 @@ void process_cli()
 
                        break;
                }
-
-               /* TODO Enable via option
-               uint8_t pos = prev_buf_pos;
-               while ( CLILineBuffer[pos] != 0 )
-               {
-                       printHex( CLILineBuffer[pos++] );
-                       print(" ");
-               }
-
-               print( NL );
-               */
        }
 }
 
@@ -206,6 +218,7 @@ inline void argumentIsolation_cli( char* string, char** first, char** second )
        *second = argPtr;
 }
 
+// Scans the CLILineBuffer for any valid commands
 void commandLookup_cli()
 {
        // Ignore command if buffer is 0 length
@@ -244,6 +257,7 @@ void commandLookup_cli()
        erro_dPrint("\"", CLILineBuffer, "\" is not a valid command...type \033[35mhelp\033[0m");
 }
 
+// Registers a command dictionary with the CLI
 inline void registerDictionary_cli( CLIDictItem *cmdDict )
 {
        // Make sure this max limit of dictionaries hasn't been reached
@@ -263,6 +277,19 @@ inline void registerDictionary_cli( CLIDictItem *cmdDict )
 
 void cliFunc_cliDebug( char* args )
 {
+       // Toggle Hex Debug Mode
+       if ( CLIHexDebugMode )
+       {
+               print( NL );
+               info_print("Hex debug mode disabled...");
+               CLIHexDebugMode = 0;
+       }
+       else
+       {
+               print( NL );
+               info_print("Hex debug mode enabled...");
+               CLIHexDebugMode = 1;
+       }
 }
 
 void cliFunc_help( char* args )
@@ -303,6 +330,11 @@ void cliFunc_reload( char* args )
 }
 
 void cliFunc_reset( char* args )
+{
+       print("\033c"); // Resets the terminal
+}
+
+void cliFunc_restart( char* args )
 {
        // Trigger an overall software reset
        SOFTWARE_RESET();
index 3b3ab3441f2dbfa1d514dafa20d6ae1444f1e2b1..4533e28d0d0349ff3a37987334ce9cfa16cd735c 100644 (file)
@@ -59,7 +59,7 @@ CLIDictItem *CLIDict[CLIMaxDictionaries];
 uint8_t CLIDictionariesUsed;
 
 uint8_t CLILEDState;
-
+uint8_t CLIHexDebugMode;
 
 
 
@@ -81,6 +81,7 @@ void cliFunc_help    ( char* args );
 void cliFunc_led     ( char* args );
 void cliFunc_reload  ( char* args );
 void cliFunc_reset   ( char* args );
+void cliFunc_restart ( char* args );
 void cliFunc_version ( char* args );
 
 
index 29abafe1aaed1679762a5e37b1c4bb2fd67de7a9..6abbeda29cd906a4f8c7df5e348f403508dead9c 100644 (file)
@@ -41,7 +41,7 @@
 #define CLI_RepoOrigin          "@Git_Origin_URL@"
 #define CLI_CommitDate          "@Git_Date_INFO@"
 #define CLI_CommitAuthor        @Git_Commit_Author@
-#define CLI_Modules             "@OutputModule@ @DebugModule@"
+#define CLI_Modules             "Output(@OutputModule@) Debug(@DebugModule@)"
 #define CLI_BuildDate           "@Build_Date@"
 #define CLI_BuildOS             "@CMAKE_SYSTEM@"
 #define CLI_Arch                "@COMPILER_FAMILY@"