]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Debug/print/print.c
Finished USB for Teensy 3.1 (Now 3.1 compatible!)
[kiibohd-controller.git] / Debug / print / print.c
index 7c4f2ed846121b6fc2dabf5d0bdd9a609b2758c3..5fcb97f27c8989cf9aff96d199ad0e78b9ecb476 100644 (file)
@@ -1,15 +1,15 @@
-/* Copyright (C) 2011-2013 by Jacob Alexander
- * 
+/* Copyright (C) 2011-2014 by Jacob Alexander
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -37,7 +37,7 @@ void usb_debug_putstr( char* s )
 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
        while ( *s != '\0' )
                usb_debug_putchar( *s++ );
-#elif defined(_mk20dx128_) // ARM
+#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
        // Count characters until NULL character, then send the amount counted
        uint32_t count = 0;
        while ( s[count] != '\0' )
@@ -84,7 +84,7 @@ void _print(const char *s)
                        usb_debug_putchar('\r');
                usb_debug_putchar(c);
        }
-#elif defined(_mk20dx128_) // ARM
+#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
        usb_debug_putstr( (char*)s );
 #endif
 }
@@ -116,6 +116,18 @@ void printInt16( uint16_t in )
        dPrintStr( tmpStr );
 }
 
+void printInt32( uint32_t in )
+{
+       // Max number of characters is 10 + 1 for null
+       char tmpStr[11];
+
+       // Convert number
+       int32ToStr( in, tmpStr );
+
+       // Print number
+       dPrintStr( tmpStr );
+}
+
 void printHex_op( uint16_t in, uint8_t op )
 {
        // With an op of 1, the max number of characters is 6 + 1 for null
@@ -175,6 +187,27 @@ void int16ToStr( uint16_t in, char* out )
 }
 
 
+void int32ToStr( uint32_t in, char* out )
+{
+       // Position and sign containers
+       uint32_t pos;
+       pos = 0;
+
+       // Evaluate through digits as decimal
+       do
+       {
+               out[pos++] = in % 10 + '0';
+       }
+       while ( (in /= 10) > 0 );
+
+       // Append null
+       out[pos] = '\0';
+
+       // Reverse the string to the correct order
+       revsStr(out);
+}
+
+
 void hexToStr_op( uint16_t in, char* out, uint8_t op )
 {
        // Position container
@@ -240,3 +273,14 @@ uint16_t lenStr( char* in )
        return (pos - in);
 }
 
+
+int16_t eqStr( char* str1, char* str2 )
+{
+       // Scan each string for NULLs and whether they are the same
+       while( *str1 != '\0' && *str1++ == *str2++ );
+
+       // If the strings are still identical (i.e. both NULL), then return -1, otherwise current *str1
+       // If *str1 is 0, then str1 ended (and str1 is "like" str2), otherwise strings are different
+       return *--str1 == *--str2 ? -1 : *++str1;
+}
+