display your latest tweet with WiFly RN-XV and AD128160-UART

Dependencies:   AD128160_kazushi_branch HTTPClient mbed PowerControl WiflyInterface

Fork of FontTest3 by Sim mbed

/media/uploads/kazushi2008/_scaled_twittermbed_scene.jpg /media/uploads/kazushi2008/_scaled_twittermbed.jpg

Please see at http://kazushi-lab.c.fun.ac.jp/pukiwiki/index.php?TwitterMbed

Revision:
9:86dd65b94dca
Parent:
8:22eb078985b1
Child:
10:94f45d37174f
--- a/main.cpp	Sun Feb 10 13:07:29 2013 +0000
+++ b/main.cpp	Mon Feb 25 03:26:07 2013 +0000
@@ -35,6 +35,8 @@
 unsigned char kstatus = 0;
 bool estate = false;
 unsigned char unibuf[4];
+unsigned char codes[512];
+bool emergency = false;
 
 unsigned short convert(unsigned short utf){
     unsigned short sjis = NULL; 
@@ -47,45 +49,56 @@
     return sjis;
 }
 
-void drawChar(unsigned char c){
-    if(estate && kstatus==4){ // 1st digit of utf-16
-        unibuf[3] = c;
-        char *endptr;
-        unsigned short code = convert(strtol((char*)unibuf, &endptr, 16));
-        //kanji_init();
-        color(0xffff);
-        k_puts(code);
-        //kanji_end();
-#ifdef _DEBUG
-        pc.printf("%s, %x\r\n", unibuf, code);
-#endif
-        kstatus = 0;
-        estate = false;
-    } else if(estate && kstatus==3){ // 2nd digit of utf-16
-        unibuf[2] = c;
-        kstatus = 4;
-    } else if(estate && kstatus==2){ // 3rd digit of utf-16
-        unibuf[1] = c;
-        kstatus = 3;
-    } else if(estate && kstatus==1){ // 4th digit of utf-16
-        unibuf[0] = c;
-        kstatus = 2;
-    } else if(estate && c=='u'){
-        kstatus = 1;
-    } else if(estate && !c=='u'){
-        drawc(c);
-        kstatus = 0;
-        estate = false;
-    } else if(c=='\\'){ // escape code
-        estate = true;
-    } else { // 4x8font
-        drawc(c);
+void parseCode(const unsigned char* s){
+    unsigned int i = 0;
+    unsigned char c;
+    
+    emergency = false;
+    while((c = *s++) != '\0') {
+        if(estate && kstatus==4){ // 1st digit of utf-16
+            unibuf[3] = c;
+            char *endptr;
+            unsigned short code = convert(strtol((char*)unibuf, &endptr, 16));
+            codes[i] = code>>8 & 0xFF;
+            i++;
+            codes[i] = code & 0xFF;
+            i++;
+            if(code==0x8149) emergency = true;
+    #ifdef _DEBUG
+            pc.printf("%s, %x\r\n", unibuf, code);
+    #endif
+            kstatus = 0;
+            estate = false;
+        } else if(estate && kstatus==3){ // 2nd digit of utf-16
+            unibuf[2] = c;
+            kstatus = 4;
+        } else if(estate && kstatus==2){ // 3rd digit of utf-16
+            unibuf[1] = c;
+            kstatus = 3;
+        } else if(estate && kstatus==1){ // 4th digit of utf-16
+            unibuf[0] = c;
+            kstatus = 2;
+        } else if(estate && c=='u'){
+            kstatus = 1;
+        } else if(estate && !c=='u'){
+            drawc(c);
+            kstatus = 0;
+            estate = false;
+        } else if(c=='\\'){ // escape code
+            estate = true;
+        } else { // 4x8font
+            codes[i] = c;
+            i++;
+            if(c=='!') emergency = true;
+        }
     }
+    
+    codes[i]= '\0';
 }
 
 void drawString(const unsigned char *s){
     unsigned char c;
-    while((c = *s++) != '\0') drawChar(c);
+    while((c = *s++) != '\0') drawc(c);
 }
 
 int connect(){
@@ -146,11 +159,12 @@
 #ifdef _DEBUG
                 pc.printf("%s\r\n", c);
 #endif
-                color(0x001f);
+                //c = strtok(c, "@");
+                parseCode((unsigned char*)c);
+                if(emergency) color(0xf800); else color(0x001f);
                 cls();
                 color(0xffff);
-                //c = strtok(c, "@");
-                drawString((unsigned char*)c); newline();
+                drawString(codes); newline();
                 //c = strtok(NULL, "@");
                 //drawString((unsigned char*)c); newline();
                 break;
@@ -160,7 +174,7 @@
     
     led2 = 0;
     
-    //delete [] buf;
+    delete [] buf;
 }
 
 int main() {