changeset 195:58cfcb7bac88

Changing decToInt to numToInt (adds support for Hex number interpreter) - CLI now works with hex or decimal numbers - Hex requires 0x (technically just x would work too)
author Jacob Alexander <haata@kiibohd.com>
date Sat, 16 Aug 2014 12:07:25 -0700
parents fc6b5d0867b7
children 8ecfdaa27234
files Debug/print/print.c Debug/print/print.h Macro/PartialMap/generatedKeymap.h Macro/PartialMap/macro.c Output/pjrcUSB/output_com.c Output/uartOut/output_com.c Output/usbMuxUart/output_com.c Scan/ADCTest/scan_loop.c Scan/DPH/scan_loop.c Scan/MatrixARM/matrix_scan.c
diffstat 10 files changed, 54 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Debug/print/print.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Debug/print/print.c	Sat Aug 16 12:07:25 2014 -0700
@@ -313,7 +313,7 @@
 	return *--str1 == *--str2 ? -1 : *++str1;
 }
 
-int decToInt( char* in )
+int numToInt( char* in )
 {
 	// Pointers to the LSD (Least Significant Digit) and MSD
 	char* lsd = in;
@@ -321,6 +321,7 @@
 
 	int total = 0;
 	int sign = 1; // Default to positive
+	uint8_t base = 10; // Use base 10 by default TODO Add support for bases other than 10 and 16
 
 	// Scan the string once to determine the length
 	while ( *lsd != '\0' )
@@ -335,12 +336,32 @@
 		case ' ':
 			msd = lsd;
 			break;
+		case 'x': // Hex Mode
+			base = 0x10;
+			msd = lsd;
+			break;
 		}
 	}
 
-	// Rescan the string from the LSD to MSD to convert it to a decimal number
-	for ( unsigned int digit = 1; lsd > msd ; digit *= 10 )
-		total += ( (*--lsd) - '0' ) * digit;
+	// Process string depending on which base
+	switch ( base )
+	{
+	case 10: // Decimal
+		// Rescan the string from the LSD to MSD to convert it to a decimal number
+		for ( unsigned int digit = 1; lsd > msd ; digit *= 10 )
+			total += ( (*--lsd) - '0' ) * digit;
+		break;
+
+	case 0x10: // Hex
+		// Rescan the string from the LSD to MSD to convert it to a hexadecimal number
+		for ( unsigned int digit = 1; lsd > msd ; digit *= 0x10 )
+		{
+			if    ( *--lsd <= '9' ) total += ( *lsd - '0' ) * digit;
+			else if ( *lsd <= 'F' ) total += ( *lsd - 'A' + 10 ) * digit;
+			else if ( *lsd <= 'f' ) total += ( *lsd - 'a' + 10 ) * digit;
+		}
+		break;
+	}
 
 	// Propagate sign and return
 	return total * sign;
--- a/Debug/print/print.h	Fri Aug 15 11:27:16 2014 -0700
+++ b/Debug/print/print.h	Sat Aug 16 12:07:25 2014 -0700
@@ -114,7 +114,7 @@
 void revsStr      ( char*  in );
 uint16_t lenStr   ( char*  in );
 int16_t eqStr     ( char*  str1, char* str2 ); // Returns -1 if identical, last character of str1 comparison (0 if str1 is like str2)
-int decToInt      ( char* in ); // Returns the int representation of a string
+int numToInt      ( char* in ); // Returns the int representation of a string
 
 #endif
 
--- a/Macro/PartialMap/generatedKeymap.h	Fri Aug 15 11:27:16 2014 -0700
+++ b/Macro/PartialMap/generatedKeymap.h	Sat Aug 16 12:07:25 2014 -0700
@@ -221,6 +221,7 @@
 Guide_TM( 1 ) = { 1, 0x00, 0x01, 0x73, 1, 0x00, 0x01, 0x75, 0 };
 Guide_TM( 2 ) = { 2, 0x00, 0x01, 0x73, 0x00, 0x01, 0x74, 0 };
 Guide_TM( 3 ) = { 1, 0x00, 0x01, 0x76, 0 };
+Guide_TM( 4 ) = { 1, 0x00, 0x01, 0x77, 0 };
 
 
 // -- Trigger Macro List
@@ -235,6 +236,7 @@
 	Define_TM( 1, 1 ),
 	Define_TM( 2, 2 ),
 	Define_TM( 3, 3 ),
+	Define_TM( 4, 0 ),
 };
 
 
@@ -379,7 +381,7 @@
 Define_TL( default, 0x74 ) = { 1, 2 };
 Define_TL( default, 0x75 ) = { 1, 1 };
 Define_TL( default, 0x76 ) = { 1, 3 };
-Define_TL( default, 0x77 ) = { 0 };
+Define_TL( default, 0x77 ) = { 1, 4 };
 Define_TL( default, 0x78 ) = { 0 };
 Define_TL( default, 0x79 ) = { 0 };
 Define_TL( default, 0x7A ) = { 0 };
--- a/Macro/PartialMap/macro.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Macro/PartialMap/macro.c	Sat Aug 16 12:07:25 2014 -0700
@@ -784,7 +784,7 @@
 		// Keyboard Capability
 		case 'K':
 			// Determine capability index
-			cap = decToInt( &arg1Ptr[1] );
+			cap = numToInt( &arg1Ptr[1] );
 
 			// Lookup the number of args
 			totalArgs += CapabilitiesList[ cap ].argCount;
@@ -793,7 +793,7 @@
 
 		// Because allocating memory isn't doable, and the argument count is arbitrary
 		// The argument pointer is repurposed as the argument list (much smaller anyways)
-		argSet[ argSetCount++ ] = (uint8_t)decToInt( arg1Ptr );
+		argSet[ argSetCount++ ] = (uint8_t)numToInt( arg1Ptr );
 
 		// Once all the arguments are prepared, call the keyboard capability function
 		if ( argSetCount == totalArgs )
@@ -838,7 +838,7 @@
 		{
 		// Scancode
 		case 'S':
-			Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x02 ); // Hold scancode
+			Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x02 ); // Hold scancode
 			break;
 		}
 	}
@@ -866,7 +866,7 @@
 		{
 		// Scancode
 		case 'S':
-			Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode
+			Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode
 			break;
 		}
 	}
@@ -894,7 +894,7 @@
 		{
 		// Scancode
 		case 'S':
-			Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode
+			Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode
 			break;
 		}
 	}
@@ -956,11 +956,11 @@
 			if ( arg1Ptr[0] != 'L' )
 				return;
 
-			arg1 = (uint8_t)decToInt( &arg1Ptr[1] );
+			arg1 = (uint8_t)numToInt( &arg1Ptr[1] );
 			break;
 		// Second argument (e.g. 4)
 		case 1:
-			arg2 = (uint8_t)decToInt( arg1Ptr );
+			arg2 = (uint8_t)numToInt( arg1Ptr );
 
 			// Display operation (to indicate that it worked)
 			print( NL );
@@ -1223,11 +1223,11 @@
 		{
 		// Indexed Trigger Macro
 		case 'T':
-			macroDebugShowTrigger( decToInt( &arg1Ptr[1] ) );
+			macroDebugShowTrigger( numToInt( &arg1Ptr[1] ) );
 			break;
 		// Indexed Result Macro
 		case 'R':
-			macroDebugShowResult( decToInt( &arg1Ptr[1] ) );
+			macroDebugShowResult( numToInt( &arg1Ptr[1] ) );
 			break;
 		}
 	}
@@ -1242,7 +1242,7 @@
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
 	// Default to 1, if no argument given
-	unsigned int count = (unsigned int)decToInt( arg1Ptr );
+	unsigned int count = (unsigned int)numToInt( arg1Ptr );
 
 	if ( count == 0 )
 		count = 1;
--- a/Output/pjrcUSB/output_com.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Output/pjrcUSB/output_com.c	Sat Aug 16 12:07:25 2014 -0700
@@ -276,7 +276,7 @@
 			break;
 
 		// Add the USB code to be sent
-		USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+		USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
 	}
 }
 
@@ -289,6 +289,6 @@
 	char* arg2Ptr;
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-	USBKeys_ModifiersCLI = decToInt( arg1Ptr );
+	USBKeys_ModifiersCLI = numToInt( arg1Ptr );
 }
 
--- a/Output/uartOut/output_com.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Output/uartOut/output_com.c	Sat Aug 16 12:07:25 2014 -0700
@@ -214,7 +214,7 @@
 			break;
 
 		// Add the USB code to be sent
-		USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+		USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
 	}
 }
 
@@ -227,6 +227,6 @@
 	char* arg2Ptr;
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-	USBKeys_ModifiersCLI = decToInt( arg1Ptr );
+	USBKeys_ModifiersCLI = numToInt( arg1Ptr );
 }
 
--- a/Output/usbMuxUart/output_com.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Output/usbMuxUart/output_com.c	Sat Aug 16 12:07:25 2014 -0700
@@ -278,7 +278,7 @@
 			break;
 
 		// Add the USB code to be sent
-		USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+		USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
 	}
 }
 
@@ -291,6 +291,6 @@
 	char* arg2Ptr;
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-	USBKeys_ModifiersCLI = decToInt( arg1Ptr );
+	USBKeys_ModifiersCLI = numToInt( arg1Ptr );
 }
 
--- a/Scan/ADCTest/scan_loop.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Scan/ADCTest/scan_loop.c	Sat Aug 16 12:07:25 2014 -0700
@@ -176,7 +176,7 @@
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
 	// Set the ADC Channel
-	uint8_t channel = decToInt( arg1Ptr );
+	uint8_t channel = numToInt( arg1Ptr );
 	__disable_irq();
 	ADC0_SC1A = channel;
 	__enable_irq();
@@ -187,7 +187,7 @@
 	int displayedADC = 1; // Default to 1 read
 	if ( arg1Ptr ) // If there is an argument, use that instead
 	{
-		displayedADC = decToInt( arg1Ptr );
+		displayedADC = numToInt( arg1Ptr );
 	}
 
 	// Poll ADC until it gets a value, making sure to serve interrupts on each attempt
@@ -232,7 +232,7 @@
 	ADC0_SC3 = 0;
 
 	// Select bit resolution
-	int bitResolution = decToInt( arg1Ptr );
+	int bitResolution = numToInt( arg1Ptr );
 	switch ( bitResolution )
 	{
 	case 8: // 8-bit
@@ -260,7 +260,7 @@
 
 	// Select Vref
 	CLI_argumentIsolation( arg2Ptr, &arg1Ptr, &arg2Ptr );
-	int vRef = decToInt( arg1Ptr );
+	int vRef = numToInt( arg1Ptr );
 	switch ( vRef )
 	{
 	case 0: // 1.2V internal Vref
@@ -276,7 +276,7 @@
 
 	// Hardware averaging (and start calibration)
 	CLI_argumentIsolation( arg2Ptr, &arg1Ptr, &arg2Ptr );
-	int hardwareAvg = decToInt( arg1Ptr );
+	int hardwareAvg = numToInt( arg1Ptr );
 	switch ( hardwareAvg )
 	{
 	case 0:  // No hardware averaging
@@ -342,7 +342,7 @@
 	char* arg2Ptr;
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-	int dacOut = decToInt( arg1Ptr );
+	int dacOut = numToInt( arg1Ptr );
 
 	// Make sure the value is between 0 and 4096, otherwise ignore
 	if ( dacOut >= 0 && dacOut <= 4095 )
@@ -361,7 +361,7 @@
 	char* arg2Ptr;
 	CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-	switch ( decToInt( arg1Ptr ) )
+	switch ( numToInt( arg1Ptr ) )
 	{
 	case 0:
 		DAC0_C0 = DAC_C0_DACEN; // 1.2V Vref is DACREF_1
--- a/Scan/DPH/scan_loop.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Scan/DPH/scan_loop.c	Sat Aug 16 12:07:25 2014 -0700
@@ -1027,7 +1027,7 @@
 	// If there was an argument, use that instead
 	if ( *arg1Ptr != '\0' )
 	{
-		senseDebugCount = decToInt( arg1Ptr );
+		senseDebugCount = numToInt( arg1Ptr );
 	}
 }
 
--- a/Scan/MatrixARM/matrix_scan.c	Fri Aug 15 11:27:16 2014 -0700
+++ b/Scan/MatrixARM/matrix_scan.c	Sat Aug 16 12:07:25 2014 -0700
@@ -444,7 +444,7 @@
 
 	if ( arg1Ptr[0] != '\0' )
 	{
-		matrixDebugStateCounter = (uint16_t)decToInt( arg1Ptr );
+		matrixDebugStateCounter = (uint16_t)numToInt( arg1Ptr );
 	}
 }