void cliFunc_lcdCmd( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; print( NL ); // No \r\n by default after the command is entered curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // No args if ( *arg1Ptr == '\0' ) return; // SPI Command uint8_t cmd = (uint8_t)numToInt( arg1Ptr ); curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Single Arg if ( *arg1Ptr == '\0' ) goto cmd; // TODO Deal with a0 cmd: info_msg("Sending - "); printHex( cmd ); print( NL ); LCD_writeControlReg( cmd ); }
void cliFunc_ledSet( char* args ) { print( NL ); // No \r\n by default after the command is entered char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Process speed argument if given curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Reset brightness if ( *arg1Ptr == '\0' ) { LED_setBrightness( ISSI_Global_Brightness_define ); } else { LED_setBrightness( numToInt(arg1Ptr) ); } info_msg("LED Brightness Set"); }
void cliFunc_voteDebug( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); // Set the vote debug flag depending on the argument switch ( arg1Ptr[0] ) { // No argument case 1: case '\0': voteDebugMode = voteDebugMode != 1 ? 1 : 0; break; // Invalid argument default: return; } print( NL ); info_msg("Vote Debug Mode: "); printInt8( voteDebugMode ); }
void cliFunc_keyRelease( char* args ) { // Parse codes from arguments char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Process all args for ( ;; ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; // Ignore non-Scancode numbers switch ( arg1Ptr[0] ) { // Scancode case 'S': Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode break; } } }
void cliFunc_macroShow( char* args ) { // Parse codes from arguments char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Process all args for ( ;; ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; // Ignore invalid codes switch ( arg1Ptr[0] ) { // Indexed Trigger Macro case 'T': macroDebugShowTrigger( numToInt( &arg1Ptr[1] ) ); break; // Indexed Result Macro case 'R': macroDebugShowResult( numToInt( &arg1Ptr[1] ) ); break; } } }
void cliFunc_connectMst( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); print( NL ); // Set override Connect_override = 1; switch ( arg1Ptr[0] ) { // Disable override case 'd': case 'D': Connect_override = 0; case 's': case 'S': info_msg("Setting device as slave."); Connect_master = 0; Connect_id = 0xFF; break; case 'm': case 'M': default: info_msg("Setting device as master."); Connect_master = 1; Connect_id = 0; break; } }
void cliFunc_kbdProtocol( char* args ) { print( NL ); // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); if ( arg1Ptr[0] != '\0' ) { uint8_t mode = (uint8_t)numToInt( arg1Ptr ); // Do nothing if the argument was wrong if ( mode == 0 || mode == 1 ) { USBKeys_Protocol = mode; info_msg("Setting Keyboard Protocol to: "); printInt8( USBKeys_Protocol ); } } else { info_msg("Keyboard Protocol: "); printInt8( USBKeys_Protocol ); } }
void cliFunc_lcdColor( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Colors uint16_t rgb[3]; // Red, Green, Blue // Parse integers from 3 arguments for ( uint8_t color = 0; color < 3; color++ ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Give up if not enough args given if ( *arg1Ptr == '\0' ) return; // Convert argument to integer rgb[ color ] = numToInt( arg1Ptr ); } // Set PWM channels FTM0_C0V = rgb[0]; FTM0_C1V = rgb[1]; FTM0_C2V = rgb[2]; }
void cliFunc_ledWPage( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // First process page and starting address curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) return; uint8_t page[] = { 0xE8, 0xFD, numToInt( arg1Ptr ) }; curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) return; uint8_t data[] = { 0xE8, numToInt( arg1Ptr ), 0 }; // Set the register page while ( I2C_Send( page, sizeof( page ), 0 ) == 0 ) delay(1); // Process all args for ( ;; ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; data[2] = numToInt( arg1Ptr ); // Write register location and data to I2C while ( I2C_Send( data, sizeof( data ), 0 ) == 0 ) delay(1); // Increment address data[1]++; } }
void cliFunc_lcdDisp( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // First process page and starting address curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) return; uint8_t page = numToInt( arg1Ptr ); curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) return; uint8_t address = numToInt( arg1Ptr ); // Set the register page LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); // Set starting address LCD_writeControlReg( 0x10 | ( ( 0xF0 & address ) >> 4 ) ); LCD_writeControlReg( 0x00 | ( 0x0F & address )); // Process all args for ( ;; ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; uint8_t value = numToInt( arg1Ptr ); // Write buffer to SPI SPI_write( &value, 1 ); } }
void cliFunc_connectCmd( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); print( NL ); switch ( numToInt( &arg1Ptr[0] ) ) { case CableCheck: Connect_send_CableCheck( UARTConnectCableCheckLength_define ); break; case IdRequest: Connect_send_IdRequest(); break; case IdEnumeration: Connect_send_IdEnumeration( 5 ); break; case IdReport: Connect_send_IdReport( 8 ); break; case ScanCode: { TriggerEvent scanCodes[] = { { 0x00, 0x01, 0x05 }, { 0x00, 0x03, 0x16 } }; Connect_send_ScanCode( 10, scanCodes, 2 ); break; } case Animation: break; case RemoteCapability: // TODO break; case RemoteOutput: // TODO break; case RemoteInput: // TODO break; case CurrentEvent: dbug_print("Sending current event"); Connect_send_CurrentEvent( 250 ); break; default: break; } }
void cliFunc_setMod( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); USBKeys_ModifiersCLI = numToInt( arg1Ptr ); }
void cliFunc_ledCtrl( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; LedControl control; // First process mode curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) return; control.mode = numToInt( arg1Ptr ); // Next process amount curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) return; control.amount = numToInt( arg1Ptr ); // Finally process led index, if it exists // Default to 0 curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); control.index = *arg1Ptr == '\0' ? 0 : numToInt( arg1Ptr ); // Process request LED_control( &control ); }
void cliFunc_outputDebug( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); // Default to 1 if no argument is given Output_DebugMode = Output_DebugMode ? 0 : 1; if ( arg1Ptr[0] != '\0' ) { Output_DebugMode = (uint16_t)numToInt( arg1Ptr ); } }
void cliFunc_i2cRecv( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Buffer used after interpretting the args, will be sent to I2C functions // NOTE: Limited to 8 bytes currently (can be increased if necessary #define i2cSend_BuffLenMax 8 uint8_t buffer[ i2cSend_BuffLenMax ]; uint8_t bufferLen = 0; // No \r\n by default after the command is entered print( NL ); info_msg("Sending: "); // Parse args until a \0 is found while ( bufferLen < i2cSend_BuffLenMax ) { curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; // If | is found, end sequence and start new one if ( *arg1Ptr == '|' ) { print("| "); I2C_Send( buffer, bufferLen, 0 ); bufferLen = 0; continue; } // Interpret the argument buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr ); // Print out the arg dPrint( arg1Ptr ); print(" "); } print( NL ); I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip }
void cliFunc_layerState( char* args ) { // Parse codes from arguments char* curArgs; char* arg1Ptr; char* arg2Ptr = args; uint8_t arg1 = 0; uint8_t arg2 = 0; // Process first two args for ( uint8_t c = 0; c < 2; c++ ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; switch ( c ) { // First argument (e.g. L1) case 0: if ( arg1Ptr[0] != 'L' ) return; arg1 = (uint8_t)numToInt( &arg1Ptr[1] ); break; // Second argument (e.g. 4) case 1: arg2 = (uint8_t)numToInt( arg1Ptr ); // Display operation (to indicate that it worked) print( NL ); info_msg("Setting Layer L"); printInt8( arg1 ); print(" to - "); printHex( arg2 ); // Set the layer state LayerState[ arg1 ] = arg2; break; } } }
void cliFunc_macroStep( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); // Default to 1, if no argument given var_uint_t count = (var_uint_t)numToInt( arg1Ptr ); if ( count == 0 ) count = 1; // Set the macro step counter, negative int's are cast to uint macroStepCounter = count; }
void cliFunc_connectIdl( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); print( NL ); info_msg("Sending Sync Idles..."); uint8_t count = numToInt( &arg1Ptr[0] ); // Default to 2 idles if ( count == 0 ) count = 2; Connect_send_Idle( count ); }
void cliFunc_ledSet( char* args ) { print( NL ); // No \r\n by default after the command is entered char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Process speed argument if given curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Reset brightness if ( *arg1Ptr == '\0' ) { LED_brightness = ISSI_Global_Brightness_define; } else { LED_brightness = numToInt( arg1Ptr ); } info_msg("LED Brightness Set"); #if ISSI_Chip_31FL3733_define || ISSI_Chip_31FL3732_define // Update brightness for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ ) { uint8_t addr = LED_ChannelMapping[ ch ].addr; uint8_t bus = LED_ChannelMapping[ ch ].bus; #if ISSI_Chip_31FL3733_define == 1 LED_writeReg( bus, addr, 0x01, LED_brightness, ISSI_ConfigPage ); #elif ISSI_Chip_31FL3732_define == 1 LED_writeReg( bus, addr, 0x04, LED_brightness, ISSI_ConfigPage ); #elif ISSI_Chip_31FL3731_define == 1 // XXX (HaaTa) - This is emulated, see LED_scan and LED_linkedSend for implementation #endif } #endif }
void cliFunc_ledPage( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); // Default to 0 if no argument is given uint8_t page = 0; if ( arg1Ptr[0] != '\0' ) { page = (uint8_t)numToInt( arg1Ptr ); } // No \r\n by default after the command is entered print( NL ); LED_readPage( 0xB4, page ); }
void cliFunc_setKeys( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Parse up to USBKeys_MaxSize args (whichever is least) for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USB_BOOT_MAX_KEYS; ++USBKeys_SentCLI ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; // Add the USB code to be sent // TODO //USBKeys_KeysCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); } }
// XXX Just an example command showing how to parse arguments (more complex than generally needed) void cliFunc_echo( char* args ) { char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Parse args until a \0 is found while ( 1 ) { print( NL ); // No \r\n by default after the command is entered curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) break; // Print out the arg dPrint( arg1Ptr ); } }
void cliFunc_ledFPS( char* args ) { print( NL ); // No \r\n by default after the command is entered char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Process speed argument if given curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Just toggling FPS display if ( *arg1Ptr == '\0' ) { info_msg("FPS Toggle"); LED_displayFPS = !LED_displayFPS; return; } // Check if f argument was given switch ( *arg1Ptr ) { case 'r': // Reset framerate case 'R': LED_framerate = ISSI_FrameRate_ms_define; break; default: // Convert to a number LED_framerate = numToInt( arg1Ptr ); break; } // Show result info_msg("Setting framerate to: "); printInt32( LED_framerate ); print("ms"); }
void cliFunc_idle( char* args ) { print( NL ); // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); // Set Idle count if ( arg1Ptr[0] != '\0' ) { uint8_t idle = (uint8_t)numToInt( arg1Ptr ); USBKeys_Idle_Config = idle; } // Show Idle count info_msg("USB Idle Config: "); printInt16( 4 * USBKeys_Idle_Config ); print(" ms - "); printInt8( USBKeys_Idle_Config ); }
void cliFunc_macroDebug( char* args ) { // Parse number from argument // NOTE: Only first argument is used char* arg1Ptr; char* arg2Ptr; CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); // Set the macro debug flag depending on the argument switch ( arg1Ptr[0] ) { // 3 as argument case '3': macroDebugMode = macroDebugMode != 3 ? 3 : 0; break; // 2 as argument case '2': macroDebugMode = macroDebugMode != 2 ? 2 : 0; break; // No argument case '1': case '\0': macroDebugMode = macroDebugMode != 1 ? 1 : 0; break; // Invalid argument default: return; } print( NL ); info_msg("Macro Debug Mode: "); printInt8( macroDebugMode ); }
void cliFunc_capSelect( char* args ) { // Parse code from argument char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Total number of args to scan (must do a lookup if a keyboard capability is selected) var_uint_t totalArgs = 2; // Always at least two args var_uint_t cap = 0; // Arguments used for keyboard capability function var_uint_t argSetCount = 0; uint8_t *argSet = (uint8_t*)args; // Process all args for ( var_uint_t c = 0; argSetCount < totalArgs; c++ ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found // Extra arguments are ignored if ( *arg1Ptr == '\0' ) break; // For the first argument, choose the capability if ( c == 0 ) switch ( arg1Ptr[0] ) { // Keyboard Capability case 'K': // Determine capability index cap = numToInt( &arg1Ptr[1] ); // Lookup the number of args totalArgs += CapabilitiesList[ cap ].argCount; continue; } // 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)numToInt( arg1Ptr ); // Once all the arguments are prepared, call the keyboard capability function if ( argSetCount == totalArgs ) { // Indicate that the capability was called print( NL ); info_msg("K"); printInt8( cap ); print(" - "); printHex( argSet[0] ); print(" - "); printHex( argSet[1] ); print(" - "); printHex( argSet[2] ); print( "..." NL ); // Make sure this isn't the reload capability // If it is, and the remote reflash define is not set, ignore if ( flashModeEnabled_define == 0 ) for ( uint32_t cap = 0; cap < CapabilitiesNum; cap++ ) { if ( CapabilitiesList[ cap ].func == (const void*)Output_flashMode_capability ) { print( NL ); warn_print("flashModeEnabled not set, cancelling firmware reload..."); info_msg("Set flashModeEnabled to 1 in your kll configuration."); return; } } void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func); capability( 0, argSet[0], argSet[1], &argSet[2] ); } } }