changeset 110:98d940b60d12

Added more CLI commands. - 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
author Jacob Alexander <haata@kiibohd.com>
date Thu, 23 Jan 2014 02:36:00 -0800
parents 2c1a9e6ae70e
children 59391aa888aa
files Debug/cli/cli.c Debug/cli/cli.h Lib/_buildvars.h
diffstat 3 files changed, 47 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Debug/cli/cli.c	Thu Jan 23 02:01:12 2014 -0800
+++ b/Debug/cli/cli.c	Thu Jan 23 02:36:00 2014 -0800
@@ -40,7 +40,8 @@
 	{ "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 @@
 
 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 @@
 	// 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 @@
 		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 @@
 
 			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 @@
 	*second = argPtr;
 }
 
+// Scans the CLILineBuffer for any valid commands
 void commandLookup_cli()
 {
 	// Ignore command if buffer is 0 length
@@ -244,6 +257,7 @@
 	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 @@
 
 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 )
@@ -304,6 +331,11 @@
 
 void cliFunc_reset( char* args )
 {
+	print("\033c"); // Resets the terminal
+}
+
+void cliFunc_restart( char* args )
+{
 	// Trigger an overall software reset
 	SOFTWARE_RESET();
 }
--- a/Debug/cli/cli.h	Thu Jan 23 02:01:12 2014 -0800
+++ b/Debug/cli/cli.h	Thu Jan 23 02:36:00 2014 -0800
@@ -59,7 +59,7 @@
 uint8_t CLIDictionariesUsed;
 
 uint8_t CLILEDState;
-
+uint8_t CLIHexDebugMode;
 
 
 
@@ -81,6 +81,7 @@
 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 );
 
 
--- a/Lib/_buildvars.h	Thu Jan 23 02:01:12 2014 -0800
+++ b/Lib/_buildvars.h	Thu Jan 23 02:36:00 2014 -0800
@@ -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@"