+
+// USB Input buffer available
+inline unsigned int Output_availablechar()
+{
+ return usb_serial_available();
+}
+
+
+// USB Get Character from input buffer
+inline int Output_getchar()
+{
+#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
+ // XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes)
+ return (int)usb_serial_getchar();
+#elif defined(_mk20dx128_) || defined(_mk20dx256_)
+ return usb_serial_getchar();
+#endif
+}
+
+
+// USB Send Character to output buffer
+inline int Output_putchar( char c )
+{
+ return usb_serial_putchar( c );
+}
+
+
+// USB Send String to output buffer, null terminated
+inline int Output_putstr( char* str )
+{
+#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
+ uint16_t count = 0;
+#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
+ uint32_t count = 0;
+#endif
+ // Count characters until NULL character, then send the amount counted
+ while ( str[count] != '\0' )
+ count++;
+
+ return usb_serial_write( str, count );
+}
+
+
+// Soft Chip Reset
+inline void Output_softReset()
+{
+#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
+ usb_debug_software_reset();
+#elif defined(_mk20dx128_) || defined(_mk20dx256_)
+ SOFTWARE_RESET();
+#endif
+}
+
+
+// ----- CLI Command Functions -----
+
+void cliFunc_readLEDs( char* args )
+{
+ print( NL );
+ info_msg("LED State: ");
+ printInt8( USBKeys_LEDs );
+}
+
+
+void cliFunc_sendKeys( char* args )
+{
+ // Copy USBKeys_ArrayCLI to USBKeys_Array
+ for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key )
+ {
+ USBKeys_Array[key] = USBKeys_ArrayCLI[key];
+ }
+ USBKeys_Sent = USBKeys_SentCLI;
+
+ // Set modifier byte
+ USBKeys_Modifiers = USBKeys_ModifiersCLI;
+}
+
+
+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 < USBKeys_MaxSize; ++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
+ USBKeys_ArrayCLI[USBKeys_SentCLI] = decToInt( arg1Ptr );
+ }
+}
+
+
+void cliFunc_setLEDs( char* args )
+{
+ // Parse number from argument
+ // NOTE: Only first argument is used
+ char* arg1Ptr;
+ char* arg2Ptr;
+ CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
+
+ USBKeys_LEDs = decToInt( arg1Ptr );
+}
+
+
+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 = decToInt( arg1Ptr );
+}
+