Demo program for the EAQVGAOLED library. Characters from a terminal program connected to the mbed USB are echoed on the display.

Dependencies:   mbed

Committer:
gbloice
Date:
Sat Feb 12 12:07:52 2011 +0000
Revision:
0:12f5969f567d
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gbloice 0:12f5969f567d 1 #include "mbed.h"
gbloice 0:12f5969f567d 2 #include "EAQVGAOLED.h"
gbloice 0:12f5969f567d 3
gbloice 0:12f5969f567d 4 Serial pc(USBTX, USBRX); // tx, rx
gbloice 0:12f5969f567d 5
gbloice 0:12f5969f567d 6 int main() {
gbloice 0:12f5969f567d 7 EAQVGAOLED display = EAQVGAOLED(p5, p6, p7, p8, p9, p10);
gbloice 0:12f5969f567d 8
gbloice 0:12f5969f567d 9 display.background(BLACK);
gbloice 0:12f5969f567d 10 display.foreground(DARK_GRAY);
gbloice 0:12f5969f567d 11 display.cls();
gbloice 0:12f5969f567d 12
gbloice 0:12f5969f567d 13 bool inEscape = false; // Flag, set when in an escape sequence
gbloice 0:12f5969f567d 14 bool inCursor = false; // Flag, set when in a cursor sequence
gbloice 0:12f5969f567d 15
gbloice 0:12f5969f567d 16 // Loop drawing characters from USB onto the display
gbloice 0:12f5969f567d 17 while(1) {
gbloice 0:12f5969f567d 18
gbloice 0:12f5969f567d 19 if (pc.readable()) {
gbloice 0:12f5969f567d 20 char inChar = pc.getc();
gbloice 0:12f5969f567d 21 // The terminal sends escape sequences for cursor keys,
gbloice 0:12f5969f567d 22 // these need to be converted to control characters
gbloice 0:12f5969f567d 23 if (inCursor) {
gbloice 0:12f5969f567d 24 switch(inChar) {
gbloice 0:12f5969f567d 25 case 'A':
gbloice 0:12f5969f567d 26 display.putc(CURSOR_UP);
gbloice 0:12f5969f567d 27 break;
gbloice 0:12f5969f567d 28 case 'B':
gbloice 0:12f5969f567d 29 display.putc(CURSOR_DOWN);
gbloice 0:12f5969f567d 30 break;
gbloice 0:12f5969f567d 31 case 'C':
gbloice 0:12f5969f567d 32 display.putc(CURSOR_RIGHT);
gbloice 0:12f5969f567d 33 break;
gbloice 0:12f5969f567d 34 case 'D':
gbloice 0:12f5969f567d 35 display.putc(CURSOR_LEFT);
gbloice 0:12f5969f567d 36 break;
gbloice 0:12f5969f567d 37 default:
gbloice 0:12f5969f567d 38 display.putc(inChar);
gbloice 0:12f5969f567d 39 break;
gbloice 0:12f5969f567d 40 }
gbloice 0:12f5969f567d 41 inCursor = false;
gbloice 0:12f5969f567d 42 }
gbloice 0:12f5969f567d 43 else if (inEscape) {
gbloice 0:12f5969f567d 44 if (inChar == 91) {
gbloice 0:12f5969f567d 45 inCursor = true;
gbloice 0:12f5969f567d 46 }
gbloice 0:12f5969f567d 47 else {
gbloice 0:12f5969f567d 48 display.putc(inChar);
gbloice 0:12f5969f567d 49 }
gbloice 0:12f5969f567d 50 inEscape = false;
gbloice 0:12f5969f567d 51 }
gbloice 0:12f5969f567d 52 else {
gbloice 0:12f5969f567d 53 switch (inChar) {
gbloice 0:12f5969f567d 54 case '+':
gbloice 0:12f5969f567d 55 display.backlightControl(true);
gbloice 0:12f5969f567d 56 break;
gbloice 0:12f5969f567d 57 case '-':
gbloice 0:12f5969f567d 58 display.backlightControl(false);
gbloice 0:12f5969f567d 59 break;
gbloice 0:12f5969f567d 60 case 27:
gbloice 0:12f5969f567d 61 inEscape = true;
gbloice 0:12f5969f567d 62 break;
gbloice 0:12f5969f567d 63 default:
gbloice 0:12f5969f567d 64 display.putc(inChar);
gbloice 0:12f5969f567d 65 break;
gbloice 0:12f5969f567d 66 }
gbloice 0:12f5969f567d 67 }
gbloice 0:12f5969f567d 68 pc.printf("Got char %d, inEscape: %d, inCursor: %d\r\n", inChar, inEscape, inCursor);
gbloice 0:12f5969f567d 69
gbloice 0:12f5969f567d 70 }
gbloice 0:12f5969f567d 71 }
gbloice 0:12f5969f567d 72 }