![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
UI/SerialGraphicLCD/SerialGraphicLCD.cpp@0:a6a169de725f, 2013-05-27 (annotated)
- Committer:
- shimniok
- Date:
- Mon May 27 13:26:03 2013 +0000
- Revision:
- 0:a6a169de725f
Working version with priorities set and update time display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a6a169de725f | 1 | #include "SerialGraphicLCD.h" |
shimniok | 0:a6a169de725f | 2 | |
shimniok | 0:a6a169de725f | 3 | #define XSIZE 6 |
shimniok | 0:a6a169de725f | 4 | #define YSIZE 9 |
shimniok | 0:a6a169de725f | 5 | |
shimniok | 0:a6a169de725f | 6 | SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx): |
shimniok | 0:a6a169de725f | 7 | Serial(tx, rx), _firmware(SFE_FW) |
shimniok | 0:a6a169de725f | 8 | { |
shimniok | 0:a6a169de725f | 9 | baud(115200); // default baud rate |
shimniok | 0:a6a169de725f | 10 | resolution(LCD_128x64); // default resolution |
shimniok | 0:a6a169de725f | 11 | } |
shimniok | 0:a6a169de725f | 12 | |
shimniok | 0:a6a169de725f | 13 | SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx, int firmware): |
shimniok | 0:a6a169de725f | 14 | Serial(tx, rx), _firmware(firmware) |
shimniok | 0:a6a169de725f | 15 | { |
shimniok | 0:a6a169de725f | 16 | baud(115200); // default baud rate |
shimniok | 0:a6a169de725f | 17 | resolution(LCD_128x64); // default resolution |
shimniok | 0:a6a169de725f | 18 | } |
shimniok | 0:a6a169de725f | 19 | |
shimniok | 0:a6a169de725f | 20 | void SerialGraphicLCD::clear() { |
shimniok | 0:a6a169de725f | 21 | putc(0x7c); |
shimniok | 0:a6a169de725f | 22 | putc(0x00); |
shimniok | 0:a6a169de725f | 23 | } |
shimniok | 0:a6a169de725f | 24 | |
shimniok | 0:a6a169de725f | 25 | void SerialGraphicLCD::pos(int col, int row) { |
shimniok | 0:a6a169de725f | 26 | // if (_firmware == SD_FW) |
shimniok | 0:a6a169de725f | 27 | posXY(XSIZE*col, (YSIZE*row)); |
shimniok | 0:a6a169de725f | 28 | // else if (_firmware == SFE_FW) |
shimniok | 0:a6a169de725f | 29 | //posXY(XSIZE*col, _yMax-(YSIZE*row)); |
shimniok | 0:a6a169de725f | 30 | } |
shimniok | 0:a6a169de725f | 31 | |
shimniok | 0:a6a169de725f | 32 | void SerialGraphicLCD::posXY(int x, int y) { |
shimniok | 0:a6a169de725f | 33 | putc(0x7c); |
shimniok | 0:a6a169de725f | 34 | putc(0x18); |
shimniok | 0:a6a169de725f | 35 | putc(x); |
shimniok | 0:a6a169de725f | 36 | putc(0x7c); |
shimniok | 0:a6a169de725f | 37 | putc(0x19); |
shimniok | 0:a6a169de725f | 38 | putc(y); |
shimniok | 0:a6a169de725f | 39 | } |
shimniok | 0:a6a169de725f | 40 | |
shimniok | 0:a6a169de725f | 41 | void SerialGraphicLCD::pixel(int x, int y, bool set) { |
shimniok | 0:a6a169de725f | 42 | putc(0x7c); |
shimniok | 0:a6a169de725f | 43 | putc(0x10); |
shimniok | 0:a6a169de725f | 44 | putc(x); |
shimniok | 0:a6a169de725f | 45 | putc(y); |
shimniok | 0:a6a169de725f | 46 | putc((set) ? 0x01 : 0x00); |
shimniok | 0:a6a169de725f | 47 | } |
shimniok | 0:a6a169de725f | 48 | |
shimniok | 0:a6a169de725f | 49 | void SerialGraphicLCD::line(int x1, int y1, int x2, int y2, bool set) { |
shimniok | 0:a6a169de725f | 50 | putc(0x7c); |
shimniok | 0:a6a169de725f | 51 | putc(0x0c); |
shimniok | 0:a6a169de725f | 52 | putc(x1); |
shimniok | 0:a6a169de725f | 53 | putc(y1); |
shimniok | 0:a6a169de725f | 54 | putc(x2); |
shimniok | 0:a6a169de725f | 55 | putc(y2); |
shimniok | 0:a6a169de725f | 56 | putc((set) ? 0x01 : 0x00); |
shimniok | 0:a6a169de725f | 57 | } |
shimniok | 0:a6a169de725f | 58 | |
shimniok | 0:a6a169de725f | 59 | void SerialGraphicLCD::circle(int x, int y, int r, bool set) { |
shimniok | 0:a6a169de725f | 60 | putc(0x7c); |
shimniok | 0:a6a169de725f | 61 | putc(0x03); |
shimniok | 0:a6a169de725f | 62 | putc(x); |
shimniok | 0:a6a169de725f | 63 | putc(y); |
shimniok | 0:a6a169de725f | 64 | putc(r); |
shimniok | 0:a6a169de725f | 65 | putc((set) ? 0x01 : 0x00); |
shimniok | 0:a6a169de725f | 66 | } |
shimniok | 0:a6a169de725f | 67 | |
shimniok | 0:a6a169de725f | 68 | // Unfortunately, the datasheet for the stock firmware is incorrect; |
shimniok | 0:a6a169de725f | 69 | // the box command does not take a 5th parameter for draw/erase like the others |
shimniok | 0:a6a169de725f | 70 | // However, it does in the sd firmware |
shimniok | 0:a6a169de725f | 71 | void SerialGraphicLCD::rect(int x1, int y1, int x2, int y2) { |
shimniok | 0:a6a169de725f | 72 | putc(0x7c); |
shimniok | 0:a6a169de725f | 73 | putc(0x0f); |
shimniok | 0:a6a169de725f | 74 | putc(x1); |
shimniok | 0:a6a169de725f | 75 | putc(y1); |
shimniok | 0:a6a169de725f | 76 | putc(x2); |
shimniok | 0:a6a169de725f | 77 | putc(y2); |
shimniok | 0:a6a169de725f | 78 | if (_firmware == SD_FW) |
shimniok | 0:a6a169de725f | 79 | putc(0x01); |
shimniok | 0:a6a169de725f | 80 | } |
shimniok | 0:a6a169de725f | 81 | |
shimniok | 0:a6a169de725f | 82 | void SerialGraphicLCD::rect(int x1, int y1, int x2, int y2, bool set) { |
shimniok | 0:a6a169de725f | 83 | putc(0x7c); |
shimniok | 0:a6a169de725f | 84 | putc(0x0f); |
shimniok | 0:a6a169de725f | 85 | putc(x1); |
shimniok | 0:a6a169de725f | 86 | putc(y1); |
shimniok | 0:a6a169de725f | 87 | putc(x2); |
shimniok | 0:a6a169de725f | 88 | putc(y2); |
shimniok | 0:a6a169de725f | 89 | if (_firmware == SD_FW) |
shimniok | 0:a6a169de725f | 90 | putc((set) ? 0x01 : 0x00); |
shimniok | 0:a6a169de725f | 91 | } |
shimniok | 0:a6a169de725f | 92 | |
shimniok | 0:a6a169de725f | 93 | void SerialGraphicLCD::rectFill(int x1, int y1, int x2, int y2, char fillByte) { |
shimniok | 0:a6a169de725f | 94 | if (_firmware == SD_FW) { |
shimniok | 0:a6a169de725f | 95 | |
shimniok | 0:a6a169de725f | 96 | // Bugs in firmware; if y2-y1 == 2, nothing drawn; if y2-y1 == 3, fill is 4 tall |
shimniok | 0:a6a169de725f | 97 | // if ((y2 - y1) > 3) { |
shimniok | 0:a6a169de725f | 98 | putc(0x7c); |
shimniok | 0:a6a169de725f | 99 | putc(0x12); |
shimniok | 0:a6a169de725f | 100 | putc(x1); |
shimniok | 0:a6a169de725f | 101 | putc(y1); |
shimniok | 0:a6a169de725f | 102 | putc(x2+1); // bug in firmware, off-by-one on x2 |
shimniok | 0:a6a169de725f | 103 | putc(y2); |
shimniok | 0:a6a169de725f | 104 | putc(fillByte); |
shimniok | 0:a6a169de725f | 105 | // } else { |
shimniok | 0:a6a169de725f | 106 | // for (int y=y1; y <= y2; y++) |
shimniok | 0:a6a169de725f | 107 | // line(x1, y, x2, y, fillByte == FILL); |
shimniok | 0:a6a169de725f | 108 | // } |
shimniok | 0:a6a169de725f | 109 | } |
shimniok | 0:a6a169de725f | 110 | } |
shimniok | 0:a6a169de725f | 111 | |
shimniok | 0:a6a169de725f | 112 | void SerialGraphicLCD::erase(int x1, int y1, int x2, int y2) { |
shimniok | 0:a6a169de725f | 113 | putc(0x7c); |
shimniok | 0:a6a169de725f | 114 | putc(0x05); |
shimniok | 0:a6a169de725f | 115 | putc(x1); |
shimniok | 0:a6a169de725f | 116 | putc(y1); |
shimniok | 0:a6a169de725f | 117 | putc(x2); |
shimniok | 0:a6a169de725f | 118 | putc(y2); |
shimniok | 0:a6a169de725f | 119 | } |
shimniok | 0:a6a169de725f | 120 | |
shimniok | 0:a6a169de725f | 121 | void SerialGraphicLCD::backlight(int i) { |
shimniok | 0:a6a169de725f | 122 | if (i >= 0 && i <= 100) { |
shimniok | 0:a6a169de725f | 123 | putc(0x7c); |
shimniok | 0:a6a169de725f | 124 | putc(0x02); |
shimniok | 0:a6a169de725f | 125 | putc(i); |
shimniok | 0:a6a169de725f | 126 | } |
shimniok | 0:a6a169de725f | 127 | } |
shimniok | 0:a6a169de725f | 128 | |
shimniok | 0:a6a169de725f | 129 | void SerialGraphicLCD::reverseMode() { |
shimniok | 0:a6a169de725f | 130 | putc(0x7c); |
shimniok | 0:a6a169de725f | 131 | putc(0x12); |
shimniok | 0:a6a169de725f | 132 | } |
shimniok | 0:a6a169de725f | 133 | |
shimniok | 0:a6a169de725f | 134 | void SerialGraphicLCD::resolution(int type) { |
shimniok | 0:a6a169de725f | 135 | switch (type) { |
shimniok | 0:a6a169de725f | 136 | case LCD_128x64 : |
shimniok | 0:a6a169de725f | 137 | resolution(128, 64); |
shimniok | 0:a6a169de725f | 138 | break; |
shimniok | 0:a6a169de725f | 139 | case LCD_160x128 : |
shimniok | 0:a6a169de725f | 140 | resolution(160, 128); |
shimniok | 0:a6a169de725f | 141 | break; |
shimniok | 0:a6a169de725f | 142 | } |
shimniok | 0:a6a169de725f | 143 | } |
shimniok | 0:a6a169de725f | 144 | |
shimniok | 0:a6a169de725f | 145 | void SerialGraphicLCD::resolution(int x, int y) { |
shimniok | 0:a6a169de725f | 146 | _xMax = x; |
shimniok | 0:a6a169de725f | 147 | _yMax = y; |
shimniok | 0:a6a169de725f | 148 | } |
shimniok | 0:a6a169de725f | 149 | |
shimniok | 0:a6a169de725f | 150 | |
shimniok | 0:a6a169de725f | 151 | void SerialGraphicLCD::lcdbaud(int b) { |
shimniok | 0:a6a169de725f | 152 | if (b > 0 && b < 7) { |
shimniok | 0:a6a169de725f | 153 | putc(0x7c); |
shimniok | 0:a6a169de725f | 154 | putc(0x07); |
shimniok | 0:a6a169de725f | 155 | putc(b+'0'); |
shimniok | 0:a6a169de725f | 156 | } |
shimniok | 0:a6a169de725f | 157 | } |