This program opens a socket and wait connection through Wi-Fi. When the socket is connected, print out received characters to LCD.

Dependencies:   TextLCD mbed

Revision:
1:e87727c8979d
Parent:
0:ac3682c7c208
--- a/LcdScreen.h	Mon Apr 23 08:56:58 2012 +0000
+++ b/LcdScreen.h	Sun Jun 03 12:24:13 2012 +0000
@@ -10,34 +10,48 @@
 class LcdScreen {
 protected:
     unsigned char cram[SCREEN_HEIGHT][SCREEN_WIDTH];
-    int cursor_x;
-    int cursor_y;
+    unsigned char lastWritten[SCREEN_HEIGHT][SCREEN_WIDTH];
+    int cursorX;
+    int cursorY;
 public:
     LcdScreen()
     {
-        cursor_x = 0;
-        cursor_y = 0;
+        cursorX = 0;
+        cursorY = 0;
         
         int x, y;
         for ( y = 0; y < SCREEN_HEIGHT; y++ ) {
             for ( x = 0; x < SCREEN_WIDTH; x++ ) {
                 cram[y][x] = ' ';
+                lastWritten[y][x] = ' ';
             }
         }
         
-        syncScreen();
+        lcd.cls();
     }
     
     void syncScreen()
     {
-        int x, y;
+        int x, y, xLimit;
         
         for ( y = 0; y < SCREEN_HEIGHT; y++ ) {
-            lcd.locate(0,y);
             for ( x = 0; x < SCREEN_WIDTH; x++ ) {
+                if ( cram[y][x] != lastWritten[y][x] )
+                    break;
+            }
+            if ( x >= SCREEN_WIDTH ) {
+                continue;
+            }
+            for ( xLimit = SCREEN_WIDTH - 1; cram[y][xLimit] == lastWritten[y][xLimit]; xLimit-- )
+                ;   // empty loop body
+            lcd.locate(x,y);
+            for ( ;x <= xLimit; x++ ) {
                 lcd.putc(cram[y][x]);
             }
         }
+        for ( y = 0; y < SCREEN_HEIGHT; y++ ) {
+            memcpy(&(lastWritten[y][0]), &(cram[y][0]), SCREEN_WIDTH);
+        }
     }
     
     void scroll()
@@ -54,24 +68,24 @@
         const unsigned char *p;
         for ( p = data; *p != '\0'; p++ ) {
             if ( *p == CR ) {
-                cursor_x = 0;
+                cursorX = 0;
             } else if ( *p == LF ) {
-                cursor_y++;
+                cursorY++;
             } else if ( 0x20 <= *p && *p <= 0x7f ) {
-                if ( cursor_x >= SCREEN_WIDTH ) {
-                    cursor_x = 0;
-                    cursor_y++;
+                if ( cursorX >= SCREEN_WIDTH ) {
+                    cursorX = 0;
+                    cursorY++;
                 }
-                if ( cursor_y >= SCREEN_HEIGHT ) {
+                if ( cursorY >= SCREEN_HEIGHT ) {
                     scroll();
-                    cursor_y = SCREEN_HEIGHT - 1;
+                    cursorY = SCREEN_HEIGHT - 1;
                 }
-                cram[cursor_y][cursor_x++] = *p;
+                cram[cursorY][cursorX++] = *p;
             }
         }
-        if ( cursor_x >= SCREEN_WIDTH ) {
-            cursor_x = 0;
-            ++cursor_y;
+        if ( cursorX >= SCREEN_WIDTH ) {
+            cursorX = 0;
+            ++cursorY;
         }
         syncScreen();
     }