]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Changing decToInt to numToInt (adds support for Hex number interpreter)
authorJacob Alexander <haata@kiibohd.com>
Sat, 16 Aug 2014 19:07:25 +0000 (12:07 -0700)
committerJacob Alexander <haata@kiibohd.com>
Sat, 16 Aug 2014 19:07:25 +0000 (12:07 -0700)
- CLI now works with hex or decimal numbers
- Hex requires 0x (technically just x would work too)

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

index e5d196804d0221c946732480ea572f293221a2f1..522f6f4062127c6e593d2ff4bb08a2aeff3d22f9 100644 (file)
@@ -313,7 +313,7 @@ int16_t eqStr( char* str1, char* str2 )
        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 decToInt( char* in )
 
        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 @@ int decToInt( char* in )
                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;
index 14628f6dfacf78c16308ef1903da9bc791d49396..c3494328b6dc97dea09cb7d723ad75ba05f63302 100644 (file)
@@ -114,7 +114,7 @@ void hex32ToStr_op( uint32_t in, char*  out, uint8_t op );
 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
 
index 20eee0280da51d1fa1b36bb8fe0f61e81681f96e..d8e2de4f29fe353c21efa85c5b3b7facf2110e61 100644 (file)
@@ -221,6 +221,7 @@ Guide_TM( 0 ) = { 1, 0x00, 0x01, 0x73, 0 };
 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 @@ TriggerMacro TriggerMacroList[] = {
        Define_TM( 1, 1 ),
        Define_TM( 2, 2 ),
        Define_TM( 3, 3 ),
+       Define_TM( 4, 0 ),
 };
 
 
@@ -379,7 +381,7 @@ Define_TL( default, 0x73 ) = { 3, 0, 1, 2 };
 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 };
index 49d94953a58f7197c1da21c95351f6898bbc18ad..e6c82ecae2a9257af9f56d9c8b03f88f560be7c2 100644 (file)
@@ -784,7 +784,7 @@ void cliFunc_capSelect( char* args )
                // 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 @@ void cliFunc_capSelect( char* args )
 
                // 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 @@ void cliFunc_keyHold( char* args )
                {
                // 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 @@ void cliFunc_keyPress( char* args )
                {
                // 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 @@ void cliFunc_keyRelease( char* args )
                {
                // 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 @@ void cliFunc_layerState( char* args )
                        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 @@ void cliFunc_macroShow( char* args )
                {
                // 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 @@ void cliFunc_macroStep( char* args )
        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;
index 020ada1b2a0afa23ac7095421b1384b159159637..6336a408655d23f1d3c7793d69d9879bac16ced0 100644 (file)
@@ -276,7 +276,7 @@ void cliFunc_setKeys( char* args )
                        break;
 
                // Add the USB code to be sent
-               USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+               USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
        }
 }
 
@@ -289,6 +289,6 @@ void cliFunc_setMod( char* args )
        char* arg2Ptr;
        CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-       USBKeys_ModifiersCLI = decToInt( arg1Ptr );
+       USBKeys_ModifiersCLI = numToInt( arg1Ptr );
 }
 
index 796af63e294faad71357d5d1c991d07c4aa9978e..7f01a4bd140a21c01b69128cc2779e53220c7f23 100644 (file)
@@ -214,7 +214,7 @@ void cliFunc_setKeys( char* args )
                        break;
 
                // Add the USB code to be sent
-               USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+               USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
        }
 }
 
@@ -227,6 +227,6 @@ void cliFunc_setMod( char* args )
        char* arg2Ptr;
        CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-       USBKeys_ModifiersCLI = decToInt( arg1Ptr );
+       USBKeys_ModifiersCLI = numToInt( arg1Ptr );
 }
 
index 5e664e1403f60c52be1d71d9215bb75851c1ee10..15bd2771e470540585927215b6d5efa7cbe25842 100644 (file)
@@ -278,7 +278,7 @@ void cliFunc_setKeys( char* args )
                        break;
 
                // Add the USB code to be sent
-               USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+               USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
        }
 }
 
@@ -291,6 +291,6 @@ void cliFunc_setMod( char* args )
        char* arg2Ptr;
        CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
-       USBKeys_ModifiersCLI = decToInt( arg1Ptr );
+       USBKeys_ModifiersCLI = numToInt( arg1Ptr );
 }
 
index 6bc41a6edd041549b4df443968c14a57e72a87d6..5de423b09b89739917d8b3e08446233c48e53958 100644 (file)
@@ -176,7 +176,7 @@ void cliFunc_adc( char* args )
        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 @@ void cliFunc_adc( char* args )
        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 @@ void cliFunc_adcInit( char* args )
        ADC0_SC3 = 0;
 
        // Select bit resolution
-       int bitResolution = decToInt( arg1Ptr );
+       int bitResolution = numToInt( arg1Ptr );
        switch ( bitResolution )
        {
        case 8: // 8-bit
@@ -260,7 +260,7 @@ void cliFunc_adcInit( char* args )
 
        // 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 @@ void cliFunc_adcInit( char* args )
 
        // 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 @@ void cliFunc_dac( char* args )
        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 @@ void cliFunc_dacVref( char* args )
        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
index 324c4c92b311bb2c653e3d7bf93e7a049e4f640b..da6d1517305c9027514029cd39061555abd43894 100644 (file)
@@ -1027,7 +1027,7 @@ void cliFunc_senseDebug( char* args )
        // If there was an argument, use that instead
        if ( *arg1Ptr != '\0' )
        {
-               senseDebugCount = decToInt( arg1Ptr );
+               senseDebugCount = numToInt( arg1Ptr );
        }
 }
 
index 11ecba3511cac7d24dea9469c6d6612f09442904..136270756ecbf3f6ea4d2d41a17aab10ea3a2693 100644 (file)
@@ -444,7 +444,7 @@ void cliFunc_matrixState ( char* args )
 
        if ( arg1Ptr[0] != '\0' )
        {
-               matrixDebugStateCounter = (uint16_t)decToInt( arg1Ptr );
+               matrixDebugStateCounter = (uint16_t)numToInt( arg1Ptr );
        }
 }