Menu system broken
Dependencies: ANSITermMenuSystem
Fork of menuSystemMbed by
SerialGraphicLCD.cpp@8:6ddb8c26387a, 2013-05-04 (annotated)
- Committer:
- Rybowonder
- Date:
- Sat May 04 17:37:57 2013 +0000
- Revision:
- 8:6ddb8c26387a
- Parent:
- 4:1178a1905490
For Mitchener
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rybowonder | 4:1178a1905490 | 1 | #include "SerialGraphicLCD.h" |
Rybowonder | 4:1178a1905490 | 2 | |
Rybowonder | 4:1178a1905490 | 3 | #define XSIZE 6 |
Rybowonder | 4:1178a1905490 | 4 | #define YSIZE 9 |
Rybowonder | 4:1178a1905490 | 5 | |
Rybowonder | 4:1178a1905490 | 6 | SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx): |
Rybowonder | 4:1178a1905490 | 7 | Serial(tx, rx), _firmware(SFE_FW) |
Rybowonder | 4:1178a1905490 | 8 | { |
Rybowonder | 4:1178a1905490 | 9 | baud(115200); // default baud rate |
Rybowonder | 4:1178a1905490 | 10 | // baud(57600); |
Rybowonder | 4:1178a1905490 | 11 | resolution(LCD_128x64); // default resolution |
Rybowonder | 4:1178a1905490 | 12 | } |
Rybowonder | 4:1178a1905490 | 13 | |
Rybowonder | 4:1178a1905490 | 14 | SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx, int firmware): |
Rybowonder | 4:1178a1905490 | 15 | Serial(tx, rx), _firmware(firmware) |
Rybowonder | 4:1178a1905490 | 16 | { |
Rybowonder | 4:1178a1905490 | 17 | baud(115200); // default baud rate |
Rybowonder | 4:1178a1905490 | 18 | // baud(57600); |
Rybowonder | 4:1178a1905490 | 19 | resolution(LCD_128x64); // default resolution |
Rybowonder | 4:1178a1905490 | 20 | } |
Rybowonder | 4:1178a1905490 | 21 | |
Rybowonder | 4:1178a1905490 | 22 | void SerialGraphicLCD::clear() { |
Rybowonder | 4:1178a1905490 | 23 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 24 | putc(0x00); |
Rybowonder | 4:1178a1905490 | 25 | } |
Rybowonder | 4:1178a1905490 | 26 | |
Rybowonder | 4:1178a1905490 | 27 | void SerialGraphicLCD::pos(int col, int row) { |
Rybowonder | 4:1178a1905490 | 28 | if (_firmware == SD_FW) |
Rybowonder | 4:1178a1905490 | 29 | posXY(XSIZE*col, (YSIZE*row)); |
Rybowonder | 4:1178a1905490 | 30 | else if (_firmware == SFE_FW) |
Rybowonder | 4:1178a1905490 | 31 | posXY(XSIZE*col, _yMax-(YSIZE*row)-1); |
Rybowonder | 4:1178a1905490 | 32 | } |
Rybowonder | 4:1178a1905490 | 33 | |
Rybowonder | 4:1178a1905490 | 34 | void SerialGraphicLCD::posXY(int x, int y) { |
Rybowonder | 4:1178a1905490 | 35 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 36 | putc(0x18); |
Rybowonder | 4:1178a1905490 | 37 | putc(x); |
Rybowonder | 4:1178a1905490 | 38 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 39 | putc(0x19); |
Rybowonder | 4:1178a1905490 | 40 | putc(y); |
Rybowonder | 4:1178a1905490 | 41 | } |
Rybowonder | 4:1178a1905490 | 42 | |
Rybowonder | 4:1178a1905490 | 43 | void SerialGraphicLCD::pixel(int x, int y, bool set) { |
Rybowonder | 4:1178a1905490 | 44 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 45 | putc(0x10); |
Rybowonder | 4:1178a1905490 | 46 | putc(x); |
Rybowonder | 4:1178a1905490 | 47 | putc(y); |
Rybowonder | 4:1178a1905490 | 48 | putc((set) ? 0x01 : 0x00); |
Rybowonder | 4:1178a1905490 | 49 | } |
Rybowonder | 4:1178a1905490 | 50 | |
Rybowonder | 4:1178a1905490 | 51 | void SerialGraphicLCD::line(int x1, int y1, int x2, int y2, bool set) { |
Rybowonder | 4:1178a1905490 | 52 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 53 | putc(0x0c); |
Rybowonder | 4:1178a1905490 | 54 | putc(x1); |
Rybowonder | 4:1178a1905490 | 55 | putc(y1); |
Rybowonder | 4:1178a1905490 | 56 | putc(x2); |
Rybowonder | 4:1178a1905490 | 57 | putc(y2); |
Rybowonder | 4:1178a1905490 | 58 | putc((set) ? 0x01 : 0x00); |
Rybowonder | 4:1178a1905490 | 59 | } |
Rybowonder | 4:1178a1905490 | 60 | |
Rybowonder | 4:1178a1905490 | 61 | void SerialGraphicLCD::circle(int x, int y, int r, bool set) { |
Rybowonder | 4:1178a1905490 | 62 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 63 | putc(0x03); |
Rybowonder | 4:1178a1905490 | 64 | putc(x); |
Rybowonder | 4:1178a1905490 | 65 | putc(y); |
Rybowonder | 4:1178a1905490 | 66 | putc(r); |
Rybowonder | 4:1178a1905490 | 67 | putc((set) ? 0x01 : 0x00); |
Rybowonder | 4:1178a1905490 | 68 | } |
Rybowonder | 4:1178a1905490 | 69 | |
Rybowonder | 4:1178a1905490 | 70 | // Unfortunately, the datasheet is incorrect; the box command |
Rybowonder | 4:1178a1905490 | 71 | // does not take a 5th parameter for draw/erase like the others |
Rybowonder | 4:1178a1905490 | 72 | void SerialGraphicLCD::rect(int x1, int y1, int x2, int y2) { |
Rybowonder | 4:1178a1905490 | 73 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 74 | putc(0x0f); |
Rybowonder | 4:1178a1905490 | 75 | putc(x1); |
Rybowonder | 4:1178a1905490 | 76 | putc(y1); |
Rybowonder | 4:1178a1905490 | 77 | putc(x2); |
Rybowonder | 4:1178a1905490 | 78 | putc(y2); |
Rybowonder | 4:1178a1905490 | 79 | } |
Rybowonder | 4:1178a1905490 | 80 | |
Rybowonder | 4:1178a1905490 | 81 | void SerialGraphicLCD::erase(int x1, int y1, int x2, int y2) { |
Rybowonder | 4:1178a1905490 | 82 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 83 | putc(0x05); |
Rybowonder | 4:1178a1905490 | 84 | putc(x1); |
Rybowonder | 4:1178a1905490 | 85 | putc(y1); |
Rybowonder | 4:1178a1905490 | 86 | putc(x2); |
Rybowonder | 4:1178a1905490 | 87 | putc(y2); |
Rybowonder | 4:1178a1905490 | 88 | } |
Rybowonder | 4:1178a1905490 | 89 | |
Rybowonder | 4:1178a1905490 | 90 | void SerialGraphicLCD::backlight(int i) { |
Rybowonder | 4:1178a1905490 | 91 | if (i >= 0 && i <= 100) { |
Rybowonder | 4:1178a1905490 | 92 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 93 | putc(0x02); |
Rybowonder | 4:1178a1905490 | 94 | putc(i); |
Rybowonder | 4:1178a1905490 | 95 | } |
Rybowonder | 4:1178a1905490 | 96 | } |
Rybowonder | 4:1178a1905490 | 97 | |
Rybowonder | 4:1178a1905490 | 98 | void SerialGraphicLCD::reverseMode() { |
Rybowonder | 4:1178a1905490 | 99 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 100 | putc(0x12); |
Rybowonder | 4:1178a1905490 | 101 | } |
Rybowonder | 4:1178a1905490 | 102 | |
Rybowonder | 4:1178a1905490 | 103 | void SerialGraphicLCD::resolution(int type) { |
Rybowonder | 4:1178a1905490 | 104 | switch (type) { |
Rybowonder | 4:1178a1905490 | 105 | case LCD_128x64 : |
Rybowonder | 4:1178a1905490 | 106 | resolution(128, 64); |
Rybowonder | 4:1178a1905490 | 107 | break; |
Rybowonder | 4:1178a1905490 | 108 | case LCD_160x128 : |
Rybowonder | 4:1178a1905490 | 109 | resolution(160, 128); |
Rybowonder | 4:1178a1905490 | 110 | break; |
Rybowonder | 4:1178a1905490 | 111 | } |
Rybowonder | 4:1178a1905490 | 112 | } |
Rybowonder | 4:1178a1905490 | 113 | |
Rybowonder | 4:1178a1905490 | 114 | void SerialGraphicLCD::resolution(int x, int y) { |
Rybowonder | 4:1178a1905490 | 115 | _xMax = x; |
Rybowonder | 4:1178a1905490 | 116 | _yMax = y; |
Rybowonder | 4:1178a1905490 | 117 | } |
Rybowonder | 4:1178a1905490 | 118 | |
Rybowonder | 4:1178a1905490 | 119 | |
Rybowonder | 4:1178a1905490 | 120 | void SerialGraphicLCD::lcdbaud(int b) { |
Rybowonder | 4:1178a1905490 | 121 | if (b > 0 && b < 7) { |
Rybowonder | 4:1178a1905490 | 122 | putc(0x7c); |
Rybowonder | 4:1178a1905490 | 123 | putc(0x07); |
Rybowonder | 4:1178a1905490 | 124 | putc(b+'0'); |
Rybowonder | 4:1178a1905490 | 125 | } |
Rybowonder | 4:1178a1905490 | 126 | } |