This program opens a socket and wait connection through Wi-Fi. When the socket is connected, print out received characters to LCD.
LcdScreen.h@2:f5754fb90f07, 2012-10-24 (annotated)
- Committer:
- nakata
- Date:
- Wed Oct 24 10:16:52 2012 +0000
- Revision:
- 2:f5754fb90f07
- Parent:
- 1:e87727c8979d
Interface public version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nakata | 0:ac3682c7c208 | 1 | #include "TextLCD.h" |
nakata | 0:ac3682c7c208 | 2 | |
nakata | 0:ac3682c7c208 | 3 | #define SCREEN_WIDTH 16 |
nakata | 0:ac3682c7c208 | 4 | #define SCREEN_HEIGHT 2 |
nakata | 0:ac3682c7c208 | 5 | #define CR 13 |
nakata | 0:ac3682c7c208 | 6 | #define LF 10 |
nakata | 0:ac3682c7c208 | 7 | |
nakata | 0:ac3682c7c208 | 8 | TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 |
nakata | 0:ac3682c7c208 | 9 | |
nakata | 0:ac3682c7c208 | 10 | class LcdScreen { |
nakata | 0:ac3682c7c208 | 11 | protected: |
nakata | 0:ac3682c7c208 | 12 | unsigned char cram[SCREEN_HEIGHT][SCREEN_WIDTH]; |
nakata | 1:e87727c8979d | 13 | unsigned char lastWritten[SCREEN_HEIGHT][SCREEN_WIDTH]; |
nakata | 1:e87727c8979d | 14 | int cursorX; |
nakata | 1:e87727c8979d | 15 | int cursorY; |
nakata | 0:ac3682c7c208 | 16 | public: |
nakata | 0:ac3682c7c208 | 17 | LcdScreen() |
nakata | 0:ac3682c7c208 | 18 | { |
nakata | 1:e87727c8979d | 19 | cursorX = 0; |
nakata | 1:e87727c8979d | 20 | cursorY = 0; |
nakata | 0:ac3682c7c208 | 21 | |
nakata | 0:ac3682c7c208 | 22 | int x, y; |
nakata | 0:ac3682c7c208 | 23 | for ( y = 0; y < SCREEN_HEIGHT; y++ ) { |
nakata | 0:ac3682c7c208 | 24 | for ( x = 0; x < SCREEN_WIDTH; x++ ) { |
nakata | 0:ac3682c7c208 | 25 | cram[y][x] = ' '; |
nakata | 1:e87727c8979d | 26 | lastWritten[y][x] = ' '; |
nakata | 0:ac3682c7c208 | 27 | } |
nakata | 0:ac3682c7c208 | 28 | } |
nakata | 0:ac3682c7c208 | 29 | |
nakata | 1:e87727c8979d | 30 | lcd.cls(); |
nakata | 0:ac3682c7c208 | 31 | } |
nakata | 0:ac3682c7c208 | 32 | |
nakata | 0:ac3682c7c208 | 33 | void syncScreen() |
nakata | 0:ac3682c7c208 | 34 | { |
nakata | 1:e87727c8979d | 35 | int x, y, xLimit; |
nakata | 0:ac3682c7c208 | 36 | |
nakata | 0:ac3682c7c208 | 37 | for ( y = 0; y < SCREEN_HEIGHT; y++ ) { |
nakata | 0:ac3682c7c208 | 38 | for ( x = 0; x < SCREEN_WIDTH; x++ ) { |
nakata | 1:e87727c8979d | 39 | if ( cram[y][x] != lastWritten[y][x] ) |
nakata | 1:e87727c8979d | 40 | break; |
nakata | 1:e87727c8979d | 41 | } |
nakata | 1:e87727c8979d | 42 | if ( x >= SCREEN_WIDTH ) { |
nakata | 1:e87727c8979d | 43 | continue; |
nakata | 1:e87727c8979d | 44 | } |
nakata | 1:e87727c8979d | 45 | for ( xLimit = SCREEN_WIDTH - 1; cram[y][xLimit] == lastWritten[y][xLimit]; xLimit-- ) |
nakata | 1:e87727c8979d | 46 | ; // empty loop body |
nakata | 1:e87727c8979d | 47 | lcd.locate(x,y); |
nakata | 1:e87727c8979d | 48 | for ( ;x <= xLimit; x++ ) { |
nakata | 0:ac3682c7c208 | 49 | lcd.putc(cram[y][x]); |
nakata | 0:ac3682c7c208 | 50 | } |
nakata | 0:ac3682c7c208 | 51 | } |
nakata | 1:e87727c8979d | 52 | for ( y = 0; y < SCREEN_HEIGHT; y++ ) { |
nakata | 1:e87727c8979d | 53 | memcpy(&(lastWritten[y][0]), &(cram[y][0]), SCREEN_WIDTH); |
nakata | 1:e87727c8979d | 54 | } |
nakata | 0:ac3682c7c208 | 55 | } |
nakata | 0:ac3682c7c208 | 56 | |
nakata | 0:ac3682c7c208 | 57 | void scroll() |
nakata | 0:ac3682c7c208 | 58 | { |
nakata | 0:ac3682c7c208 | 59 | int x; |
nakata | 0:ac3682c7c208 | 60 | for ( x = 0; x < SCREEN_WIDTH; x++ ) { |
nakata | 0:ac3682c7c208 | 61 | cram[0][x] = cram[1][x]; |
nakata | 0:ac3682c7c208 | 62 | cram[1][x] = ' '; |
nakata | 0:ac3682c7c208 | 63 | } |
nakata | 0:ac3682c7c208 | 64 | } |
nakata | 0:ac3682c7c208 | 65 | |
nakata | 0:ac3682c7c208 | 66 | void print(const unsigned char *data) |
nakata | 0:ac3682c7c208 | 67 | { |
nakata | 0:ac3682c7c208 | 68 | const unsigned char *p; |
nakata | 0:ac3682c7c208 | 69 | for ( p = data; *p != '\0'; p++ ) { |
nakata | 0:ac3682c7c208 | 70 | if ( *p == CR ) { |
nakata | 1:e87727c8979d | 71 | cursorX = 0; |
nakata | 0:ac3682c7c208 | 72 | } else if ( *p == LF ) { |
nakata | 1:e87727c8979d | 73 | cursorY++; |
nakata | 0:ac3682c7c208 | 74 | } else if ( 0x20 <= *p && *p <= 0x7f ) { |
nakata | 1:e87727c8979d | 75 | if ( cursorX >= SCREEN_WIDTH ) { |
nakata | 1:e87727c8979d | 76 | cursorX = 0; |
nakata | 1:e87727c8979d | 77 | cursorY++; |
nakata | 0:ac3682c7c208 | 78 | } |
nakata | 1:e87727c8979d | 79 | if ( cursorY >= SCREEN_HEIGHT ) { |
nakata | 0:ac3682c7c208 | 80 | scroll(); |
nakata | 1:e87727c8979d | 81 | cursorY = SCREEN_HEIGHT - 1; |
nakata | 0:ac3682c7c208 | 82 | } |
nakata | 1:e87727c8979d | 83 | cram[cursorY][cursorX++] = *p; |
nakata | 0:ac3682c7c208 | 84 | } |
nakata | 0:ac3682c7c208 | 85 | } |
nakata | 1:e87727c8979d | 86 | if ( cursorX >= SCREEN_WIDTH ) { |
nakata | 1:e87727c8979d | 87 | cursorX = 0; |
nakata | 1:e87727c8979d | 88 | ++cursorY; |
nakata | 0:ac3682c7c208 | 89 | } |
nakata | 0:ac3682c7c208 | 90 | syncScreen(); |
nakata | 0:ac3682c7c208 | 91 | } |
nakata | 0:ac3682c7c208 | 92 | }; |