PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Revision:
66:6281a40d73e6
Parent:
31:f4b9b85c7b62
--- a/POKITTO_CORE/PokittoItoa.cpp	Sat Mar 23 19:22:35 2019 +0000
+++ b/POKITTO_CORE/PokittoItoa.cpp	Sat Mar 23 20:03:34 2019 +0000
@@ -38,6 +38,21 @@
 #include <string.h>
 #include <stdint.h>
 
+/* A utility function to reverse a string  */
+void reverse(char str[], int length)
+{
+    int start = 0;
+    int end = length -1;
+    while (start < end)
+    {
+        char t = *(str+end);
+        *(str+end) = *(str+start);
+        *(str+start) = t;
+        //std::swap(*(str+start), *(str+end));
+        start++;
+        end--;
+    }
+}
 
 void pokItoa(uint16_t value, char *str, int base)
 {
@@ -134,8 +149,44 @@
     pokItoa(value,str,base);
 }
 
-void pokLtoa(long value, char *str, int base) {
-    pokItoa(value,str,base);
+void pokLtoa(long num, char *str, int base) {
+    int i = 0;
+    bool isNegative = false;
+
+    /* Handle 0 explicitely, otherwise empty string is printed for 0 */
+    if (num == 0)
+    {
+        str[i++] = '0';
+        str[i] = '\0';
+        return;// str;
+    }
+
+    // In standard itoa(), negative numbers are handled only with
+    // base 10. Otherwise numbers are considered unsigned.
+    if (num < 0 && base == 10)
+    {
+        isNegative = true;
+        num = -num;
+    }
+
+    // Process individual digits
+    while (num != 0)
+    {
+        int rem = num % base;
+        str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
+        num = num/base;
+    }
+
+    // If number is negative, append '-'
+    if (isNegative)
+        str[i++] = '-';
+
+    str[i] = '\0'; // Append string terminator
+
+    // Reverse the string
+    reverse(str, i);
+
+    return;// str;
 }