|
| 1 | +//Digole Digital Solutions: www.digole.com |
| 2 | +#include "DigoleSerial.h" |
| 3 | +#include <stdio.h> |
| 4 | +#include <string.h> |
| 5 | +#include <inttypes.h> |
| 6 | +#include "Arduino.h" |
| 7 | + |
| 8 | +/* |
| 9 | +// Communication set up command |
| 10 | + * "SB":Baud (ascII bytes end with 0x00/0x0A/0x0D) -- set UART Baud Rate |
| 11 | + * "SI2CA":Address(1 byte <127) -- Set I2C address, default address is:0x27 |
| 12 | + * "DC":1/0(1byte) -- set config display on/off, if set to 1, displayer will display current commucation setting when power on |
| 13 | +// Text Function command |
| 14 | + * "CL": -- Clear screen--OK |
| 15 | + * "CS":1/0 (1 byte)-- Cursor on/off |
| 16 | + * "TP":x(1 byte) y(1 byte) -- set text position |
| 17 | + * "TT":string(bytes) end with 0x00/0x0A/0x0D -- display string under regular mode |
| 18 | +// Graphic function command |
| 19 | + * "GP":x(1byte) y(1byte) -- set current graphic position |
| 20 | + * "DM":"C/!/~/&/|/^"(ASCII 1byte) -- set drawing mode--C="Copy",! and ~ = "Not", & = "And", | = "Or", ^ = "Xor" |
| 21 | + * "SC":1/0 (1byte) -- set draw color--only 1 and 0 |
| 22 | + * "LN":x0(1byte) y0(1byte) x1(1byte) y2(1byte)--draw line from x0,y0 to x1,y1,set new pot to x1,y1 |
| 23 | + * "LT":x(1byte) y(1byte) -- draw line from current pos to x,y |
| 24 | + * "CC":x(1byte) y(1byte) ratio(byte) -- draw circle at x,y with ratio |
| 25 | + * "DP":x(1byte) y(1byte) Color(1byte) -- draw a pixel--OK |
| 26 | + * "DR":x0(1byte) y0(1byte) x1(1byte) y2(1byte)--draw rectangle, top-left:x0,y0; right-bottom:x1,y1 |
| 27 | + * "FR":x0(1byte) y0(1byte) x1(1byte) y2(1byte)--draw filled rectangle, top-left:x0,y0; right-bottom:x1,y1 |
| 28 | + */ |
| 29 | + |
| 30 | +// that resetting the Arduino doesn't reset the LCD, so we |
| 31 | +// can't assume that its in that state when a sketch starts (and the |
| 32 | +// LiquidCrystal constructor is called). |
| 33 | + |
| 34 | +//UART function |
| 35 | + |
| 36 | +void DigoleSerialDisp::preprint(void) { |
| 37 | + //write((uint8_t)0); |
| 38 | + Print::print("TT"); |
| 39 | +} |
| 40 | + |
| 41 | +/*----------Functions for Graphic LCD/OLED adapters only---------*/ |
| 42 | +void DigoleSerialDisp::drawBitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap) { |
| 43 | + uint8_t i = 0; |
| 44 | + if ((w & 7) != 0) |
| 45 | + i = 1; |
| 46 | + Print::print("DIM"); |
| 47 | + write(x); //x; |
| 48 | + write(y); |
| 49 | + write(w); |
| 50 | + write(h); |
| 51 | + for (int j = 0; j < h * ((w >> 3) + i); j++) { |
| 52 | + write(pgm_read_byte_near(bitmap + j)); |
| 53 | +// delay(5); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +void DigoleSerialDisp::setRot90(void) { |
| 58 | + Print::print("SD1"); |
| 59 | +} |
| 60 | + |
| 61 | +void DigoleSerialDisp::setRot180(void) { |
| 62 | + Print::print("SD2"); |
| 63 | +} |
| 64 | + |
| 65 | +void DigoleSerialDisp::setRot270(void) { |
| 66 | + Print::print("SD3"); |
| 67 | +} |
| 68 | + |
| 69 | +void DigoleSerialDisp::undoRotation(void) { |
| 70 | + Print::print("SD0"); |
| 71 | +} |
| 72 | + |
| 73 | +void DigoleSerialDisp::setRotation(uint8_t d) { |
| 74 | + Print::print("SD"); |
| 75 | + write(d); |
| 76 | +} |
| 77 | + |
| 78 | +void DigoleSerialDisp::setContrast(uint8_t c) { |
| 79 | + Print::print("CT"); |
| 80 | + write(c); |
| 81 | +} |
| 82 | + |
| 83 | +void DigoleSerialDisp::drawBox(uint8_t x, uint8_t y, uint8_t w, uint8_t h) { |
| 84 | + Print::print("FR"); |
| 85 | + write(x); |
| 86 | + write(y); |
| 87 | + write(x + w); |
| 88 | + write(y + h); |
| 89 | +} |
| 90 | + |
| 91 | +void DigoleSerialDisp::drawCircle(uint8_t x, uint8_t y, uint8_t r, uint8_t f) { |
| 92 | + Print::print("CC"); |
| 93 | + write(x); |
| 94 | + write(y); |
| 95 | + write(r); |
| 96 | + write(f); |
| 97 | +} |
| 98 | + |
| 99 | +void DigoleSerialDisp::drawDisc(uint8_t x, uint8_t y, uint8_t r) { |
| 100 | + drawCircle(x, y, r, 1); |
| 101 | +} |
| 102 | + |
| 103 | +void DigoleSerialDisp::drawFrame(uint8_t x, uint8_t y, uint8_t w, uint8_t h) { |
| 104 | + Print::print("DR"); |
| 105 | + write(x); |
| 106 | + write(y); |
| 107 | + write(x + w); |
| 108 | + write(y + h); |
| 109 | +} |
| 110 | + |
| 111 | +void DigoleSerialDisp::drawPixel(uint8_t x, uint8_t y, uint8_t color) { |
| 112 | + Print::print("DP"); |
| 113 | + write(x); |
| 114 | + write(y); |
| 115 | + write(color); |
| 116 | +} |
| 117 | + |
| 118 | +void DigoleSerialDisp::drawLine(uint8_t x, uint8_t y, uint8_t x1, uint8_t y1) { |
| 119 | + Print::print("LN"); |
| 120 | + write(x); |
| 121 | + write(y); |
| 122 | + write(x1); |
| 123 | + write(y1); |
| 124 | +} |
| 125 | + |
| 126 | +void DigoleSerialDisp::drawLineTo(uint8_t x, uint8_t y) { |
| 127 | + Print::print("LT"); |
| 128 | + write(x); |
| 129 | + write(y); |
| 130 | +} |
| 131 | + |
| 132 | +void DigoleSerialDisp::drawHLine(uint8_t x, uint8_t y, uint8_t w) { |
| 133 | + drawLine(x, y, x + w, y); |
| 134 | +} |
| 135 | + |
| 136 | +void DigoleSerialDisp::drawVLine(uint8_t x, uint8_t y, uint8_t h) { |
| 137 | + drawLine(x, y, x, y + h); |
| 138 | +} |
| 139 | + |
| 140 | +void DigoleSerialDisp::nextTextLine(void) { |
| 141 | + write((uint8_t) 0); |
| 142 | + Print::print("TRT"); |
| 143 | +} |
| 144 | + |
| 145 | +void DigoleSerialDisp::setFont(uint8_t font) { |
| 146 | + Print::print("SF"); |
| 147 | + write(font); |
| 148 | +} |
| 149 | + |
| 150 | +void DigoleSerialDisp::setColor(uint8_t color) { |
| 151 | + Print::print("SC"); |
| 152 | + write(color); |
| 153 | +} |
| 154 | + |
| 155 | +void DigoleSerialDisp::backLightOn(void) { |
| 156 | + Print::print("BL"); |
| 157 | + write((uint8_t) 1); |
| 158 | +} |
| 159 | + |
| 160 | +void DigoleSerialDisp::backLightOff(void) { |
| 161 | + Print::print("BL"); |
| 162 | + write((uint8_t) 0); |
| 163 | +} |
| 164 | + |
| 165 | +void DigoleSerialDisp::directCommand(uint8_t d) { |
| 166 | + Print::print("MCD"); |
| 167 | + write(d); |
| 168 | +} |
| 169 | + |
| 170 | +void DigoleSerialDisp::directData(uint8_t d) { |
| 171 | + Print::print("MDT"); |
| 172 | + write(d); |
| 173 | +} |
| 174 | + |
| 175 | +void DigoleSerialDisp::moveArea(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, char xoffset, char yoffset) { |
| 176 | + Print::print("MA"); |
| 177 | + write(x0); |
| 178 | + write(y0); |
| 179 | + write(w); |
| 180 | + write(h); |
| 181 | + write(xoffset); |
| 182 | + write(yoffset); |
| 183 | +} |
| 184 | + |
| 185 | +void DigoleSerialDisp::uploadStartScreen(int lon, const unsigned char *data) { |
| 186 | + int j; |
| 187 | + uint8_t c; |
| 188 | + Print::print("SSS"); |
| 189 | + write((uint8_t) (lon % 256)); |
| 190 | + write((uint8_t) (lon / 256)); |
| 191 | + delay(300); |
| 192 | + for (j = 0; j < lon;j++) { |
| 193 | + if((j%32)==0) |
| 194 | + delay(50); |
| 195 | + delay(_Comdelay); |
| 196 | + c=pgm_read_byte_near(data+j); |
| 197 | + write(c); |
| 198 | + } |
| 199 | +} |
| 200 | + |
| 201 | +void DigoleSerialDisp::uploadUserFont(int lon, const unsigned char *data, uint8_t sect) { |
| 202 | + uint8_t c; |
| 203 | + Print::print("SUF"); |
| 204 | + write(sect); |
| 205 | + write((uint8_t) (lon % 256)); |
| 206 | + write((uint8_t) (lon / 256)); |
| 207 | + for (int j = 0; j < lon; j++) { |
| 208 | + if((j%32)==0) |
| 209 | + delay(50); |
| 210 | + delay(_Comdelay); |
| 211 | + c=pgm_read_byte_near(data+j); |
| 212 | + write(c); |
| 213 | + } |
| 214 | +} |
| 215 | +void DigoleSerialDisp::drawBitmap256(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap) { //display 256 color image |
| 216 | + uint8_t i = 0; |
| 217 | + Print::print("EDIM1"); |
| 218 | + write(x); //x; |
| 219 | + write(y); |
| 220 | + write(w); |
| 221 | + write(h); |
| 222 | + for (int j = 0; j < h * w; j++) { |
| 223 | + write(pgm_read_byte_near(bitmap + j)); |
| 224 | +// delay(5); |
| 225 | + } |
| 226 | +} |
| 227 | +void DigoleSerialDisp::drawBitmap262K(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap) { //display 256 color image |
| 228 | + uint8_t i = 0; |
| 229 | + Print::print("EDIM3"); |
| 230 | + write(x); //x; |
| 231 | + write(y); |
| 232 | + write(w); |
| 233 | + write(h); |
| 234 | + for (int j = 0; (j < h * w *3); j++) { |
| 235 | + write(pgm_read_byte_near(bitmap + j)); |
| 236 | +// delay(5); |
| 237 | + } |
| 238 | +} |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
0 commit comments