Ryan Scott / menuSystemMbedBroken

Dependencies:   ANSITermMenuSystem

Fork of menuSystemMbed by Ryan Scott

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SerialGraphicLCD.cpp Source File

SerialGraphicLCD.cpp

00001 #include "SerialGraphicLCD.h"
00002 
00003 #define XSIZE 6
00004 #define YSIZE 9
00005 
00006 SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx): 
00007     Serial(tx, rx), _firmware(SFE_FW)
00008 {
00009     baud(115200);               // default baud rate
00010  //   baud(57600);
00011     resolution(LCD_128x64);     // default resolution
00012 }
00013 
00014 SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx, int firmware):
00015     Serial(tx, rx), _firmware(firmware)
00016 {
00017     baud(115200);               // default baud rate
00018 //    baud(57600);
00019     resolution(LCD_128x64);     // default resolution
00020 }
00021 
00022 void SerialGraphicLCD::clear() {
00023     putc(0x7c);
00024     putc(0x00);
00025 }
00026 
00027 void SerialGraphicLCD::pos(int col, int row) {
00028     if (_firmware == SD_FW)
00029         posXY(XSIZE*col, (YSIZE*row));
00030     else if (_firmware == SFE_FW)
00031         posXY(XSIZE*col, _yMax-(YSIZE*row)-1);
00032 }
00033 
00034 void SerialGraphicLCD::posXY(int x, int y) {
00035     putc(0x7c);
00036     putc(0x18);
00037     putc(x);
00038     putc(0x7c);
00039     putc(0x19);
00040     putc(y);
00041 }
00042 
00043 void SerialGraphicLCD::pixel(int x, int y, bool set) {
00044     putc(0x7c);
00045     putc(0x10);
00046     putc(x);
00047     putc(y);
00048     putc((set) ? 0x01 : 0x00);
00049 }
00050 
00051 void SerialGraphicLCD::line(int x1, int y1, int x2, int y2, bool set) {
00052     putc(0x7c);
00053     putc(0x0c);
00054     putc(x1);
00055     putc(y1);
00056     putc(x2);
00057     putc(y2);
00058     putc((set) ? 0x01 : 0x00);
00059 }
00060 
00061 void SerialGraphicLCD::circle(int x, int y, int r, bool set) {
00062     putc(0x7c);
00063     putc(0x03);
00064     putc(x);
00065     putc(y);
00066     putc(r);
00067     putc((set) ? 0x01 : 0x00);
00068 }
00069 
00070 // Unfortunately, the datasheet is incorrect; the box command
00071 // does not take a 5th parameter for draw/erase like the others
00072 void SerialGraphicLCD::rect(int x1, int y1, int x2, int y2) {
00073     putc(0x7c);
00074     putc(0x0f);
00075     putc(x1);
00076     putc(y1);
00077     putc(x2);
00078     putc(y2);
00079 }
00080 
00081 void SerialGraphicLCD::erase(int x1, int y1, int x2, int y2) {
00082     putc(0x7c);
00083     putc(0x05);
00084     putc(x1);
00085     putc(y1);
00086     putc(x2);
00087     putc(y2);
00088 }
00089 
00090 void SerialGraphicLCD::backlight(int i) {
00091     if (i >= 0 && i <= 100) {
00092         putc(0x7c);
00093         putc(0x02);
00094         putc(i);
00095     }
00096 }
00097 
00098 void SerialGraphicLCD::reverseMode() {
00099     putc(0x7c);
00100     putc(0x12);
00101 }
00102 
00103 void SerialGraphicLCD::resolution(int type) {
00104     switch (type) {
00105     case LCD_128x64 :
00106         resolution(128, 64);
00107         break;
00108     case LCD_160x128 :
00109         resolution(160, 128);
00110         break;
00111     }
00112 }
00113 
00114 void SerialGraphicLCD::resolution(int x, int y) {
00115     _xMax = x;
00116     _yMax = y;
00117 }
00118 
00119 
00120 void SerialGraphicLCD::lcdbaud(int b) {
00121     if (b > 0 && b < 7) {
00122         putc(0x7c);
00123         putc(0x07);
00124         putc(b+'0');
00125     }
00126 }