- CLI now works with hex or decimal numbers - Hex requires 0x (technically just x would work too)simple
return *--str1 == *--str2 ? -1 : *++str1; | return *--str1 == *--str2 ? -1 : *++str1; | ||||
} | } | ||||
int decToInt( char* in ) | |||||
int numToInt( char* in ) | |||||
{ | { | ||||
// Pointers to the LSD (Least Significant Digit) and MSD | // Pointers to the LSD (Least Significant Digit) and MSD | ||||
char* lsd = in; | char* lsd = in; | ||||
int total = 0; | int total = 0; | ||||
int sign = 1; // Default to positive | 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 | // Scan the string once to determine the length | ||||
while ( *lsd != '\0' ) | while ( *lsd != '\0' ) | ||||
case ' ': | case ' ': | ||||
msd = lsd; | msd = lsd; | ||||
break; | 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 | // Propagate sign and return | ||||
return total * sign; | return total * sign; |
void revsStr ( char* in ); | void revsStr ( char* in ); | ||||
uint16_t lenStr ( 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) | 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 | #endif | ||||
Guide_TM( 1 ) = { 1, 0x00, 0x01, 0x73, 1, 0x00, 0x01, 0x75, 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( 2 ) = { 2, 0x00, 0x01, 0x73, 0x00, 0x01, 0x74, 0 }; | ||||
Guide_TM( 3 ) = { 1, 0x00, 0x01, 0x76, 0 }; | Guide_TM( 3 ) = { 1, 0x00, 0x01, 0x76, 0 }; | ||||
Guide_TM( 4 ) = { 1, 0x00, 0x01, 0x77, 0 }; | |||||
// -- Trigger Macro List | // -- Trigger Macro List | ||||
Define_TM( 1, 1 ), | Define_TM( 1, 1 ), | ||||
Define_TM( 2, 2 ), | Define_TM( 2, 2 ), | ||||
Define_TM( 3, 3 ), | Define_TM( 3, 3 ), | ||||
Define_TM( 4, 0 ), | |||||
}; | }; | ||||
Define_TL( default, 0x74 ) = { 1, 2 }; | Define_TL( default, 0x74 ) = { 1, 2 }; | ||||
Define_TL( default, 0x75 ) = { 1, 1 }; | Define_TL( default, 0x75 ) = { 1, 1 }; | ||||
Define_TL( default, 0x76 ) = { 1, 3 }; | 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, 0x78 ) = { 0 }; | ||||
Define_TL( default, 0x79 ) = { 0 }; | Define_TL( default, 0x79 ) = { 0 }; | ||||
Define_TL( default, 0x7A ) = { 0 }; | Define_TL( default, 0x7A ) = { 0 }; |
// Keyboard Capability | // Keyboard Capability | ||||
case 'K': | case 'K': | ||||
// Determine capability index | // Determine capability index | ||||
cap = decToInt( &arg1Ptr[1] ); | |||||
cap = numToInt( &arg1Ptr[1] ); | |||||
// Lookup the number of args | // Lookup the number of args | ||||
totalArgs += CapabilitiesList[ cap ].argCount; | totalArgs += CapabilitiesList[ cap ].argCount; | ||||
// Because allocating memory isn't doable, and the argument count is arbitrary | // Because allocating memory isn't doable, and the argument count is arbitrary | ||||
// The argument pointer is repurposed as the argument list (much smaller anyways) | // 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 | // Once all the arguments are prepared, call the keyboard capability function | ||||
if ( argSetCount == totalArgs ) | if ( argSetCount == totalArgs ) | ||||
{ | { | ||||
// Scancode | // Scancode | ||||
case 'S': | case 'S': | ||||
Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x02 ); // Hold scancode | |||||
Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x02 ); // Hold scancode | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
{ | { | ||||
// Scancode | // Scancode | ||||
case 'S': | case 'S': | ||||
Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode | |||||
Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
{ | { | ||||
// Scancode | // Scancode | ||||
case 'S': | case 'S': | ||||
Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode | |||||
Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ( arg1Ptr[0] != 'L' ) | if ( arg1Ptr[0] != 'L' ) | ||||
return; | return; | ||||
arg1 = (uint8_t)decToInt( &arg1Ptr[1] ); | |||||
arg1 = (uint8_t)numToInt( &arg1Ptr[1] ); | |||||
break; | break; | ||||
// Second argument (e.g. 4) | // Second argument (e.g. 4) | ||||
case 1: | case 1: | ||||
arg2 = (uint8_t)decToInt( arg1Ptr ); | |||||
arg2 = (uint8_t)numToInt( arg1Ptr ); | |||||
// Display operation (to indicate that it worked) | // Display operation (to indicate that it worked) | ||||
print( NL ); | print( NL ); | ||||
{ | { | ||||
// Indexed Trigger Macro | // Indexed Trigger Macro | ||||
case 'T': | case 'T': | ||||
macroDebugShowTrigger( decToInt( &arg1Ptr[1] ) ); | |||||
macroDebugShowTrigger( numToInt( &arg1Ptr[1] ) ); | |||||
break; | break; | ||||
// Indexed Result Macro | // Indexed Result Macro | ||||
case 'R': | case 'R': | ||||
macroDebugShowResult( decToInt( &arg1Ptr[1] ) ); | |||||
macroDebugShowResult( numToInt( &arg1Ptr[1] ) ); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | ||||
// Default to 1, if no argument given | // Default to 1, if no argument given | ||||
unsigned int count = (unsigned int)decToInt( arg1Ptr ); | |||||
unsigned int count = (unsigned int)numToInt( arg1Ptr ); | |||||
if ( count == 0 ) | if ( count == 0 ) | ||||
count = 1; | count = 1; |
break; | break; | ||||
// Add the USB code to be sent | // Add the USB code to be sent | ||||
USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr ); | |||||
USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |||||
} | } | ||||
} | } | ||||
char* arg2Ptr; | char* arg2Ptr; | ||||
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | ||||
USBKeys_ModifiersCLI = decToInt( arg1Ptr ); | |||||
USBKeys_ModifiersCLI = numToInt( arg1Ptr ); | |||||
} | } | ||||
break; | break; | ||||
// Add the USB code to be sent | // Add the USB code to be sent | ||||
USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr ); | |||||
USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |||||
} | } | ||||
} | } | ||||
char* arg2Ptr; | char* arg2Ptr; | ||||
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | ||||
USBKeys_ModifiersCLI = decToInt( arg1Ptr ); | |||||
USBKeys_ModifiersCLI = numToInt( arg1Ptr ); | |||||
} | } | ||||
break; | break; | ||||
// Add the USB code to be sent | // Add the USB code to be sent | ||||
USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr ); | |||||
USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |||||
} | } | ||||
} | } | ||||
char* arg2Ptr; | char* arg2Ptr; | ||||
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | ||||
USBKeys_ModifiersCLI = decToInt( arg1Ptr ); | |||||
USBKeys_ModifiersCLI = numToInt( arg1Ptr ); | |||||
} | } | ||||
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | ||||
// Set the ADC Channel | // Set the ADC Channel | ||||
uint8_t channel = decToInt( arg1Ptr ); | |||||
uint8_t channel = numToInt( arg1Ptr ); | |||||
__disable_irq(); | __disable_irq(); | ||||
ADC0_SC1A = channel; | ADC0_SC1A = channel; | ||||
__enable_irq(); | __enable_irq(); | ||||
int displayedADC = 1; // Default to 1 read | int displayedADC = 1; // Default to 1 read | ||||
if ( arg1Ptr ) // If there is an argument, use that instead | 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 | // Poll ADC until it gets a value, making sure to serve interrupts on each attempt | ||||
ADC0_SC3 = 0; | ADC0_SC3 = 0; | ||||
// Select bit resolution | // Select bit resolution | ||||
int bitResolution = decToInt( arg1Ptr ); | |||||
int bitResolution = numToInt( arg1Ptr ); | |||||
switch ( bitResolution ) | switch ( bitResolution ) | ||||
{ | { | ||||
case 8: // 8-bit | case 8: // 8-bit | ||||
// Select Vref | // Select Vref | ||||
CLI_argumentIsolation( arg2Ptr, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( arg2Ptr, &arg1Ptr, &arg2Ptr ); | ||||
int vRef = decToInt( arg1Ptr ); | |||||
int vRef = numToInt( arg1Ptr ); | |||||
switch ( vRef ) | switch ( vRef ) | ||||
{ | { | ||||
case 0: // 1.2V internal Vref | case 0: // 1.2V internal Vref | ||||
// Hardware averaging (and start calibration) | // Hardware averaging (and start calibration) | ||||
CLI_argumentIsolation( arg2Ptr, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( arg2Ptr, &arg1Ptr, &arg2Ptr ); | ||||
int hardwareAvg = decToInt( arg1Ptr ); | |||||
int hardwareAvg = numToInt( arg1Ptr ); | |||||
switch ( hardwareAvg ) | switch ( hardwareAvg ) | ||||
{ | { | ||||
case 0: // No hardware averaging | case 0: // No hardware averaging | ||||
char* arg2Ptr; | char* arg2Ptr; | ||||
CLI_argumentIsolation( args, &arg1Ptr, &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 | // Make sure the value is between 0 and 4096, otherwise ignore | ||||
if ( dacOut >= 0 && dacOut <= 4095 ) | if ( dacOut >= 0 && dacOut <= 4095 ) | ||||
char* arg2Ptr; | char* arg2Ptr; | ||||
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | ||||
switch ( decToInt( arg1Ptr ) ) | |||||
switch ( numToInt( arg1Ptr ) ) | |||||
{ | { | ||||
case 0: | case 0: | ||||
DAC0_C0 = DAC_C0_DACEN; // 1.2V Vref is DACREF_1 | DAC0_C0 = DAC_C0_DACEN; // 1.2V Vref is DACREF_1 |
// If there was an argument, use that instead | // If there was an argument, use that instead | ||||
if ( *arg1Ptr != '\0' ) | if ( *arg1Ptr != '\0' ) | ||||
{ | { | ||||
senseDebugCount = decToInt( arg1Ptr ); | |||||
senseDebugCount = numToInt( arg1Ptr ); | |||||
} | } | ||||
} | } | ||||
if ( arg1Ptr[0] != '\0' ) | if ( arg1Ptr[0] != '\0' ) | ||||
{ | { | ||||
matrixDebugStateCounter = (uint16_t)decToInt( arg1Ptr ); | |||||
matrixDebugStateCounter = (uint16_t)numToInt( arg1Ptr ); | |||||
} | } | ||||
} | } | ||||