This program opens a socket and wait connection through Wi-Fi. When the socket is connected, print out received characters to LCD.
Diff: LcdScreen.h
- Revision:
- 0:ac3682c7c208
- Child:
- 1:e87727c8979d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LcdScreen.h Mon Apr 23 08:56:58 2012 +0000 @@ -0,0 +1,78 @@ +#include "TextLCD.h" + +#define SCREEN_WIDTH 16 +#define SCREEN_HEIGHT 2 +#define CR 13 +#define LF 10 + +TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 + +class LcdScreen { +protected: + unsigned char cram[SCREEN_HEIGHT][SCREEN_WIDTH]; + int cursor_x; + int cursor_y; +public: + LcdScreen() + { + cursor_x = 0; + cursor_y = 0; + + int x, y; + for ( y = 0; y < SCREEN_HEIGHT; y++ ) { + for ( x = 0; x < SCREEN_WIDTH; x++ ) { + cram[y][x] = ' '; + } + } + + syncScreen(); + } + + void syncScreen() + { + int x, y; + + for ( y = 0; y < SCREEN_HEIGHT; y++ ) { + lcd.locate(0,y); + for ( x = 0; x < SCREEN_WIDTH; x++ ) { + lcd.putc(cram[y][x]); + } + } + } + + void scroll() + { + int x; + for ( x = 0; x < SCREEN_WIDTH; x++ ) { + cram[0][x] = cram[1][x]; + cram[1][x] = ' '; + } + } + + void print(const unsigned char *data) + { + const unsigned char *p; + for ( p = data; *p != '\0'; p++ ) { + if ( *p == CR ) { + cursor_x = 0; + } else if ( *p == LF ) { + cursor_y++; + } else if ( 0x20 <= *p && *p <= 0x7f ) { + if ( cursor_x >= SCREEN_WIDTH ) { + cursor_x = 0; + cursor_y++; + } + if ( cursor_y >= SCREEN_HEIGHT ) { + scroll(); + cursor_y = SCREEN_HEIGHT - 1; + } + cram[cursor_y][cursor_x++] = *p; + } + } + if ( cursor_x >= SCREEN_WIDTH ) { + cursor_x = 0; + ++cursor_y; + } + syncScreen(); + } +}; \ No newline at end of file