UART object

Dependencies:   mbed

Fork of DigoleSerialDisp1 by James Novak

Committer:
jpnovak
Date:
Tue Nov 17 16:09:34 2015 +0000
Revision:
5:7d3fd21b9ead
Parent:
0:3cf7c2683c3a
Child:
6:fc42c0dc7b7f
text commands working.  not recognizing header files in command set.  Only partial commands working. ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:3cf7c2683c3a 1 /** Digole Serial Display library
shimniok 0:3cf7c2683c3a 2 *
shimniok 0:3cf7c2683c3a 3 * @Author: Digole Digital Solutions : www.digole.com ported to mbed by Michael Shimniok www.bot-thoughts.com
shimniok 0:3cf7c2683c3a 4 */
shimniok 0:3cf7c2683c3a 5
shimniok 0:3cf7c2683c3a 6 #include "mbed.h"
shimniok 0:3cf7c2683c3a 7 #include "DigoleSerialDisp.h"
shimniok 0:3cf7c2683c3a 8 #include <stdio.h>
shimniok 0:3cf7c2683c3a 9 #include <string.h>
shimniok 0:3cf7c2683c3a 10 #include <inttypes.h>
shimniok 0:3cf7c2683c3a 11
shimniok 0:3cf7c2683c3a 12 char null = 0;
shimniok 0:3cf7c2683c3a 13
shimniok 0:3cf7c2683c3a 14
shimniok 0:3cf7c2683c3a 15 // that resetting the Arduino doesn't reset the LCD, so we
shimniok 0:3cf7c2683c3a 16 // can't assume that its in that state when a sketch starts (and the
shimniok 0:3cf7c2683c3a 17 // LiquidCrystal constructor is called).
shimniok 0:3cf7c2683c3a 18
shimniok 0:3cf7c2683c3a 19 //UART function
shimniok 0:3cf7c2683c3a 20
shimniok 0:3cf7c2683c3a 21 char buf[128];
shimniok 0:3cf7c2683c3a 22 char tmp[128];
jpnovak 5:7d3fd21b9ead 23 /*
shimniok 0:3cf7c2683c3a 24 DigoleSerialDisp::DigoleSerialDisp(PinName sda, PinName scl, uint8_t address):
shimniok 0:3cf7c2683c3a 25 _device(sda, scl)
shimniok 0:3cf7c2683c3a 26 {
shimniok 0:3cf7c2683c3a 27 _address = (address<<1);
shimniok 0:3cf7c2683c3a 28 _device.frequency(100000);
shimniok 0:3cf7c2683c3a 29 _Comdelay=70;
shimniok 0:3cf7c2683c3a 30 }
jpnovak 5:7d3fd21b9ead 31 */
jpnovak 5:7d3fd21b9ead 32 /*
jpnovak 5:7d3fd21b9ead 33 DigoleSerialDisp(PinName tx, PinName rx, unsigned long baud) //UART set up
jpnovak 5:7d3fd21b9ead 34 {
jpnovak 5:7d3fd21b9ead 35 _mySerial = s;
jpnovak 5:7d3fd21b9ead 36 _Baud = baud;
jpnovak 5:7d3fd21b9ead 37 _Comdelay=2;
jpnovak 5:7d3fd21b9ead 38 }
jpnovak 5:7d3fd21b9ead 39 */
jpnovak 5:7d3fd21b9ead 40
shimniok 0:3cf7c2683c3a 41
shimniok 0:3cf7c2683c3a 42 size_t DigoleSerialDisp::write(const char x)
shimniok 0:3cf7c2683c3a 43 {
shimniok 0:3cf7c2683c3a 44 _device.write(_address, (char *) &x, 1);
shimniok 0:3cf7c2683c3a 45
shimniok 0:3cf7c2683c3a 46 return 1;
shimniok 0:3cf7c2683c3a 47 }
shimniok 0:3cf7c2683c3a 48
shimniok 0:3cf7c2683c3a 49 size_t DigoleSerialDisp::write(const char *str)
shimniok 0:3cf7c2683c3a 50 {
shimniok 0:3cf7c2683c3a 51 if (str == NULL) return 0;
shimniok 0:3cf7c2683c3a 52 return write(str, strlen(str));
shimniok 0:3cf7c2683c3a 53 }
shimniok 0:3cf7c2683c3a 54
shimniok 0:3cf7c2683c3a 55 size_t DigoleSerialDisp::write(const char *buffer, size_t size)
shimniok 0:3cf7c2683c3a 56 {
shimniok 0:3cf7c2683c3a 57 int len = 0;
shimniok 0:3cf7c2683c3a 58 if (buffer != NULL) {
shimniok 0:3cf7c2683c3a 59 _device.write(_address, (char *) buffer, size);
shimniok 0:3cf7c2683c3a 60 len = size;
shimniok 0:3cf7c2683c3a 61 delay(7);
shimniok 0:3cf7c2683c3a 62 }
shimniok 0:3cf7c2683c3a 63 return len;
shimniok 0:3cf7c2683c3a 64 }
shimniok 0:3cf7c2683c3a 65
shimniok 0:3cf7c2683c3a 66
shimniok 0:3cf7c2683c3a 67 size_t DigoleSerialDisp::print(const char c)
shimniok 0:3cf7c2683c3a 68 {
shimniok 0:3cf7c2683c3a 69 buf[0] = 'T';
shimniok 0:3cf7c2683c3a 70 buf[1] = 'T';
shimniok 0:3cf7c2683c3a 71 buf[2] = c;
shimniok 0:3cf7c2683c3a 72 buf[3] = 0;
shimniok 0:3cf7c2683c3a 73 write(buf);
shimniok 0:3cf7c2683c3a 74 write(null);
shimniok 0:3cf7c2683c3a 75 return 1;
shimniok 0:3cf7c2683c3a 76 }
shimniok 0:3cf7c2683c3a 77
shimniok 0:3cf7c2683c3a 78 size_t DigoleSerialDisp::print(const char s[])
shimniok 0:3cf7c2683c3a 79 {
shimniok 0:3cf7c2683c3a 80 int len = strlen(s);
shimniok 0:3cf7c2683c3a 81
shimniok 0:3cf7c2683c3a 82 if (s == NULL) return 0;
shimniok 0:3cf7c2683c3a 83
shimniok 0:3cf7c2683c3a 84 buf[0] = 'T';
shimniok 0:3cf7c2683c3a 85 buf[1] = 'T';
shimniok 0:3cf7c2683c3a 86 buf[2] = 0;
shimniok 0:3cf7c2683c3a 87 strncat(buf, s, 125);
shimniok 0:3cf7c2683c3a 88 write(buf);
shimniok 0:3cf7c2683c3a 89 write(null);
shimniok 0:3cf7c2683c3a 90 return len;
shimniok 0:3cf7c2683c3a 91 }
shimniok 0:3cf7c2683c3a 92
shimniok 0:3cf7c2683c3a 93 size_t DigoleSerialDisp::println(const char s[])
shimniok 0:3cf7c2683c3a 94 {
shimniok 0:3cf7c2683c3a 95 return print(s);
shimniok 0:3cf7c2683c3a 96 }
shimniok 0:3cf7c2683c3a 97
shimniok 0:3cf7c2683c3a 98 /*
shimniok 0:3cf7c2683c3a 99 Print.cpp - Base class that provides print() and println()
shimniok 0:3cf7c2683c3a 100 Copyright (c) 2008 David A. Mellis. All right reserved.
shimniok 0:3cf7c2683c3a 101
shimniok 0:3cf7c2683c3a 102 This library is free software; you can redistribute it and/or
shimniok 0:3cf7c2683c3a 103 modify it under the terms of the GNU Lesser General Public
shimniok 0:3cf7c2683c3a 104 License as published by the Free Software Foundation; either
shimniok 0:3cf7c2683c3a 105 version 2.1 of the License, or (at your option) any later version.
shimniok 0:3cf7c2683c3a 106
shimniok 0:3cf7c2683c3a 107 This library is distributed in the hope that it will be useful,
shimniok 0:3cf7c2683c3a 108 but WITHOUT ANY WARRANTY; without even the implied warranty of
shimniok 0:3cf7c2683c3a 109 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
shimniok 0:3cf7c2683c3a 110 Lesser General Public License for more details.
shimniok 0:3cf7c2683c3a 111
shimniok 0:3cf7c2683c3a 112 You should have received a copy of the GNU Lesser General Public
shimniok 0:3cf7c2683c3a 113 License along with this library; if not, write to the Free Software
shimniok 0:3cf7c2683c3a 114 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
shimniok 0:3cf7c2683c3a 115
shimniok 0:3cf7c2683c3a 116 Modified 23 November 2006 by David A. Mellis
shimniok 0:3cf7c2683c3a 117 */
shimniok 0:3cf7c2683c3a 118
shimniok 0:3cf7c2683c3a 119 size_t DigoleSerialDisp::print(unsigned char b, int base)
shimniok 0:3cf7c2683c3a 120 {
shimniok 0:3cf7c2683c3a 121 return print((unsigned long) b, base);
shimniok 0:3cf7c2683c3a 122 }
shimniok 0:3cf7c2683c3a 123
shimniok 0:3cf7c2683c3a 124 size_t DigoleSerialDisp::print(int n, int base)
shimniok 0:3cf7c2683c3a 125 {
shimniok 0:3cf7c2683c3a 126 return print((long) n, base);
shimniok 0:3cf7c2683c3a 127 }
shimniok 0:3cf7c2683c3a 128
shimniok 0:3cf7c2683c3a 129 size_t DigoleSerialDisp::print(unsigned int n, int base)
shimniok 0:3cf7c2683c3a 130 {
shimniok 0:3cf7c2683c3a 131 return print((unsigned long) n, base);
shimniok 0:3cf7c2683c3a 132 }
shimniok 0:3cf7c2683c3a 133
shimniok 0:3cf7c2683c3a 134 size_t DigoleSerialDisp::print(long n, int base)
shimniok 0:3cf7c2683c3a 135 {
shimniok 0:3cf7c2683c3a 136 if (base == 0) {
shimniok 0:3cf7c2683c3a 137 return write(n);
shimniok 0:3cf7c2683c3a 138 } else if (base == 10) {
shimniok 0:3cf7c2683c3a 139 if (n < 0) {
shimniok 0:3cf7c2683c3a 140 int t = print('-');
shimniok 0:3cf7c2683c3a 141 n = -n;
shimniok 0:3cf7c2683c3a 142 return printNumber(n, 10) + t;
shimniok 0:3cf7c2683c3a 143 }
shimniok 0:3cf7c2683c3a 144 return printNumber(n, 10);
shimniok 0:3cf7c2683c3a 145 } else {
shimniok 0:3cf7c2683c3a 146 return printNumber(n, base);
shimniok 0:3cf7c2683c3a 147 }
shimniok 0:3cf7c2683c3a 148 }
shimniok 0:3cf7c2683c3a 149
shimniok 0:3cf7c2683c3a 150 size_t DigoleSerialDisp::print(unsigned long n, int base)
shimniok 0:3cf7c2683c3a 151 {
shimniok 0:3cf7c2683c3a 152 if (base == 0) return write(n);
shimniok 0:3cf7c2683c3a 153 else return printNumber(n, base);
shimniok 0:3cf7c2683c3a 154 }
shimniok 0:3cf7c2683c3a 155
shimniok 0:3cf7c2683c3a 156 size_t DigoleSerialDisp::print(double n, int digits)
shimniok 0:3cf7c2683c3a 157 {
shimniok 0:3cf7c2683c3a 158 return printFloat(n, digits);
shimniok 0:3cf7c2683c3a 159 }
shimniok 0:3cf7c2683c3a 160
shimniok 0:3cf7c2683c3a 161 size_t DigoleSerialDisp::println(unsigned char b, int base)
shimniok 0:3cf7c2683c3a 162 {
shimniok 0:3cf7c2683c3a 163 size_t n = print(b, base);
shimniok 0:3cf7c2683c3a 164 n += println();
shimniok 0:3cf7c2683c3a 165 return n;
shimniok 0:3cf7c2683c3a 166 }
shimniok 0:3cf7c2683c3a 167
shimniok 0:3cf7c2683c3a 168 size_t DigoleSerialDisp::println(int num, int base)
shimniok 0:3cf7c2683c3a 169 {
shimniok 0:3cf7c2683c3a 170 size_t n = print(num, base);
shimniok 0:3cf7c2683c3a 171 n += println();
shimniok 0:3cf7c2683c3a 172 return n;
shimniok 0:3cf7c2683c3a 173 }
shimniok 0:3cf7c2683c3a 174
shimniok 0:3cf7c2683c3a 175 size_t DigoleSerialDisp::println(unsigned int num, int base)
shimniok 0:3cf7c2683c3a 176 {
shimniok 0:3cf7c2683c3a 177 size_t n = print(num, base);
shimniok 0:3cf7c2683c3a 178 n += println();
shimniok 0:3cf7c2683c3a 179 return n;
shimniok 0:3cf7c2683c3a 180 }
shimniok 0:3cf7c2683c3a 181
shimniok 0:3cf7c2683c3a 182 size_t DigoleSerialDisp::println(long num, int base)
shimniok 0:3cf7c2683c3a 183 {
shimniok 0:3cf7c2683c3a 184 size_t n = print(num, base);
shimniok 0:3cf7c2683c3a 185 n += println();
shimniok 0:3cf7c2683c3a 186 return n;
shimniok 0:3cf7c2683c3a 187 }
shimniok 0:3cf7c2683c3a 188
shimniok 0:3cf7c2683c3a 189 size_t DigoleSerialDisp::println(unsigned long num, int base)
shimniok 0:3cf7c2683c3a 190 {
shimniok 0:3cf7c2683c3a 191 size_t n = print(num, base);
shimniok 0:3cf7c2683c3a 192 n += println();
shimniok 0:3cf7c2683c3a 193 return n;
shimniok 0:3cf7c2683c3a 194 }
shimniok 0:3cf7c2683c3a 195
shimniok 0:3cf7c2683c3a 196 size_t DigoleSerialDisp::println(double num, int digits)
shimniok 0:3cf7c2683c3a 197 {
shimniok 0:3cf7c2683c3a 198 size_t n = print(num, digits);
shimniok 0:3cf7c2683c3a 199 n += println();
shimniok 0:3cf7c2683c3a 200 return n;
shimniok 0:3cf7c2683c3a 201 }
shimniok 0:3cf7c2683c3a 202
shimniok 0:3cf7c2683c3a 203 size_t DigoleSerialDisp::println(void)
shimniok 0:3cf7c2683c3a 204 {
shimniok 0:3cf7c2683c3a 205 return 1;
shimniok 0:3cf7c2683c3a 206 }
shimniok 0:3cf7c2683c3a 207
shimniok 0:3cf7c2683c3a 208 // Private Methods /////////////////////////////////////////////////////////////
shimniok 0:3cf7c2683c3a 209
shimniok 0:3cf7c2683c3a 210 size_t DigoleSerialDisp::printNumber(unsigned long n, uint8_t base) {
shimniok 0:3cf7c2683c3a 211 char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
shimniok 0:3cf7c2683c3a 212 char *str = &buf[sizeof(buf) - 1];
shimniok 0:3cf7c2683c3a 213
shimniok 0:3cf7c2683c3a 214 *str = '\0';
shimniok 0:3cf7c2683c3a 215
shimniok 0:3cf7c2683c3a 216 // prevent crash if called with base == 1
shimniok 0:3cf7c2683c3a 217 if (base < 2) base = 10;
shimniok 0:3cf7c2683c3a 218
shimniok 0:3cf7c2683c3a 219 do {
shimniok 0:3cf7c2683c3a 220 unsigned long m = n;
shimniok 0:3cf7c2683c3a 221 n /= base;
shimniok 0:3cf7c2683c3a 222 char c = m - base * n;
shimniok 0:3cf7c2683c3a 223 *--str = c < 10 ? c + '0' : c + 'A' - 10;
shimniok 0:3cf7c2683c3a 224 } while(n);
shimniok 0:3cf7c2683c3a 225
shimniok 0:3cf7c2683c3a 226 return write(str);
shimniok 0:3cf7c2683c3a 227 }
shimniok 0:3cf7c2683c3a 228
shimniok 0:3cf7c2683c3a 229 size_t DigoleSerialDisp::printFloat(double number, uint8_t digits)
shimniok 0:3cf7c2683c3a 230 {
shimniok 0:3cf7c2683c3a 231 size_t n = 0;
shimniok 0:3cf7c2683c3a 232
shimniok 0:3cf7c2683c3a 233 if (isnan(number)) return print("nan");
shimniok 0:3cf7c2683c3a 234 if (isinf(number)) return print("inf");
shimniok 0:3cf7c2683c3a 235 if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
shimniok 0:3cf7c2683c3a 236 if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
shimniok 0:3cf7c2683c3a 237
shimniok 0:3cf7c2683c3a 238 // Handle negative numbers
shimniok 0:3cf7c2683c3a 239 if (number < 0.0)
shimniok 0:3cf7c2683c3a 240 {
shimniok 0:3cf7c2683c3a 241 n += print('-');
shimniok 0:3cf7c2683c3a 242 number = -number;
shimniok 0:3cf7c2683c3a 243 }
shimniok 0:3cf7c2683c3a 244
shimniok 0:3cf7c2683c3a 245 // Round correctly so that print(1.999, 2) prints as "2.00"
shimniok 0:3cf7c2683c3a 246 double rounding = 0.5;
shimniok 0:3cf7c2683c3a 247 for (uint8_t i=0; i<digits; ++i)
shimniok 0:3cf7c2683c3a 248 rounding /= 10.0;
shimniok 0:3cf7c2683c3a 249
shimniok 0:3cf7c2683c3a 250 number += rounding;
shimniok 0:3cf7c2683c3a 251
shimniok 0:3cf7c2683c3a 252 // Extract the integer part of the number and print it
shimniok 0:3cf7c2683c3a 253 unsigned long int_part = (unsigned long)number;
shimniok 0:3cf7c2683c3a 254 double remainder = number - (double)int_part;
shimniok 0:3cf7c2683c3a 255 n += print(int_part);
shimniok 0:3cf7c2683c3a 256
shimniok 0:3cf7c2683c3a 257 // Print the decimal point, but only if there are digits beyond
shimniok 0:3cf7c2683c3a 258 if (digits > 0) {
shimniok 0:3cf7c2683c3a 259 n += print(".");
shimniok 0:3cf7c2683c3a 260 }
shimniok 0:3cf7c2683c3a 261
shimniok 0:3cf7c2683c3a 262 // Extract digits from the remainder one at a time
shimniok 0:3cf7c2683c3a 263 while (digits-- > 0)
shimniok 0:3cf7c2683c3a 264 {
shimniok 0:3cf7c2683c3a 265 remainder *= 10.0;
shimniok 0:3cf7c2683c3a 266 int toPrint = int(remainder);
shimniok 0:3cf7c2683c3a 267 n += print(toPrint);
shimniok 0:3cf7c2683c3a 268 remainder -= toPrint;
shimniok 0:3cf7c2683c3a 269 }
shimniok 0:3cf7c2683c3a 270
shimniok 0:3cf7c2683c3a 271 return n;
shimniok 0:3cf7c2683c3a 272 }
shimniok 0:3cf7c2683c3a 273
shimniok 0:3cf7c2683c3a 274 /*---------functions for Text and Graphic LCD adapters---------*/
shimniok 0:3cf7c2683c3a 275 void DigoleSerialDisp::disableCursor(void)
shimniok 0:3cf7c2683c3a 276 {
shimniok 0:3cf7c2683c3a 277 write("CS");
shimniok 0:3cf7c2683c3a 278 write(null);
shimniok 0:3cf7c2683c3a 279 }
shimniok 0:3cf7c2683c3a 280
shimniok 0:3cf7c2683c3a 281 void DigoleSerialDisp::enableCursor(void)
shimniok 0:3cf7c2683c3a 282 {
shimniok 0:3cf7c2683c3a 283 write("CS");
shimniok 0:3cf7c2683c3a 284 write(1);
shimniok 0:3cf7c2683c3a 285 }
shimniok 0:3cf7c2683c3a 286
shimniok 0:3cf7c2683c3a 287 void DigoleSerialDisp::drawStr(uint8_t x, uint8_t y, const char *s)
shimniok 0:3cf7c2683c3a 288 {
shimniok 0:3cf7c2683c3a 289 write("TP");
shimniok 0:3cf7c2683c3a 290 write(x);
shimniok 0:3cf7c2683c3a 291 write(y);
shimniok 0:3cf7c2683c3a 292 write("TT");
shimniok 0:3cf7c2683c3a 293 write(s);
shimniok 0:3cf7c2683c3a 294 write(null);
shimniok 0:3cf7c2683c3a 295 }
shimniok 0:3cf7c2683c3a 296
shimniok 0:3cf7c2683c3a 297 void DigoleSerialDisp::setPrintPos(uint8_t x, uint8_t y, uint8_t graph)
shimniok 0:3cf7c2683c3a 298 {
shimniok 0:3cf7c2683c3a 299 if (graph == _TEXT_) {
shimniok 0:3cf7c2683c3a 300 write("TP");
shimniok 0:3cf7c2683c3a 301 write(x);
shimniok 0:3cf7c2683c3a 302 write(y);
shimniok 0:3cf7c2683c3a 303 } else {
shimniok 0:3cf7c2683c3a 304 write("GP");
shimniok 0:3cf7c2683c3a 305 write(x);
shimniok 0:3cf7c2683c3a 306 write(y);
shimniok 0:3cf7c2683c3a 307 }
shimniok 0:3cf7c2683c3a 308 }
shimniok 0:3cf7c2683c3a 309
shimniok 0:3cf7c2683c3a 310 void DigoleSerialDisp::clearScreen(void)
shimniok 0:3cf7c2683c3a 311 {
shimniok 0:3cf7c2683c3a 312 //write(null);
shimniok 0:3cf7c2683c3a 313 write("CL");
shimniok 0:3cf7c2683c3a 314 }
shimniok 0:3cf7c2683c3a 315
shimniok 0:3cf7c2683c3a 316 void DigoleSerialDisp::setLCDColRow(uint8_t col, uint8_t row)
shimniok 0:3cf7c2683c3a 317 {
shimniok 0:3cf7c2683c3a 318 write("STCR");
shimniok 0:3cf7c2683c3a 319 write(col);
shimniok 0:3cf7c2683c3a 320 write(row);
shimniok 0:3cf7c2683c3a 321 write("\x80\xC0\x94\xD4");
shimniok 0:3cf7c2683c3a 322 }
shimniok 0:3cf7c2683c3a 323
shimniok 0:3cf7c2683c3a 324 void DigoleSerialDisp::setI2CAddress(uint8_t add)
shimniok 0:3cf7c2683c3a 325 {
shimniok 0:3cf7c2683c3a 326 write("SI2CA");
shimniok 0:3cf7c2683c3a 327 write(add);
shimniok 0:3cf7c2683c3a 328 _address = (add<<1);
shimniok 0:3cf7c2683c3a 329 }
shimniok 0:3cf7c2683c3a 330
shimniok 0:3cf7c2683c3a 331 void DigoleSerialDisp::displayConfig(uint8_t v)
shimniok 0:3cf7c2683c3a 332 {
shimniok 0:3cf7c2683c3a 333 write("DC");
shimniok 0:3cf7c2683c3a 334 write(v);
shimniok 0:3cf7c2683c3a 335 }
shimniok 0:3cf7c2683c3a 336
shimniok 0:3cf7c2683c3a 337 void DigoleSerialDisp::preprint(void)
shimniok 0:3cf7c2683c3a 338 {
shimniok 0:3cf7c2683c3a 339 //print("TT");
shimniok 0:3cf7c2683c3a 340 }
shimniok 0:3cf7c2683c3a 341
shimniok 0:3cf7c2683c3a 342 /*----------Functions for Graphic LCD/OLED adapters only---------*/
shimniok 0:3cf7c2683c3a 343 void DigoleSerialDisp::drawBitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap) {
shimniok 0:3cf7c2683c3a 344 uint8_t i = 0;
shimniok 0:3cf7c2683c3a 345 if ((w & 7) != 0)
shimniok 0:3cf7c2683c3a 346 i = 1;
shimniok 0:3cf7c2683c3a 347 write("DIM");
shimniok 0:3cf7c2683c3a 348 write(x); //x;
shimniok 0:3cf7c2683c3a 349 write(y);
shimniok 0:3cf7c2683c3a 350 write(w);
shimniok 0:3cf7c2683c3a 351 write(h);
shimniok 0:3cf7c2683c3a 352 for (int j = 0; j < h * ((w >> 3) + i); j++) {
shimniok 0:3cf7c2683c3a 353 write( (const char *) (bitmap+j) );
shimniok 0:3cf7c2683c3a 354 delay(1);
shimniok 0:3cf7c2683c3a 355 }
shimniok 0:3cf7c2683c3a 356 }
shimniok 0:3cf7c2683c3a 357
shimniok 0:3cf7c2683c3a 358 void DigoleSerialDisp::setRot90(void) {
shimniok 0:3cf7c2683c3a 359 write("SD1");
shimniok 0:3cf7c2683c3a 360 }
shimniok 0:3cf7c2683c3a 361
shimniok 0:3cf7c2683c3a 362 void DigoleSerialDisp::setRot180(void) {
shimniok 0:3cf7c2683c3a 363 write("SD2");
shimniok 0:3cf7c2683c3a 364 }
shimniok 0:3cf7c2683c3a 365
shimniok 0:3cf7c2683c3a 366 void DigoleSerialDisp::setRot270(void) {
shimniok 0:3cf7c2683c3a 367 write("SD3");
shimniok 0:3cf7c2683c3a 368 }
shimniok 0:3cf7c2683c3a 369
shimniok 0:3cf7c2683c3a 370 void DigoleSerialDisp::undoRotation(void) {
shimniok 0:3cf7c2683c3a 371 write("SD0");
shimniok 0:3cf7c2683c3a 372 }
shimniok 0:3cf7c2683c3a 373
shimniok 0:3cf7c2683c3a 374 void DigoleSerialDisp::setRotation(uint8_t d) {
shimniok 0:3cf7c2683c3a 375 write("SD");
shimniok 0:3cf7c2683c3a 376 write(d);
shimniok 0:3cf7c2683c3a 377 }
shimniok 0:3cf7c2683c3a 378
shimniok 0:3cf7c2683c3a 379 void DigoleSerialDisp::setContrast(uint8_t c) {
shimniok 0:3cf7c2683c3a 380 write("CT");
shimniok 0:3cf7c2683c3a 381 write(c);
shimniok 0:3cf7c2683c3a 382 }
shimniok 0:3cf7c2683c3a 383
shimniok 0:3cf7c2683c3a 384 void DigoleSerialDisp::drawBox(uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
shimniok 0:3cf7c2683c3a 385 write("FR");
shimniok 0:3cf7c2683c3a 386 write(x);
shimniok 0:3cf7c2683c3a 387 write(y);
shimniok 0:3cf7c2683c3a 388 write(x + w);
shimniok 0:3cf7c2683c3a 389 write(y + h);
shimniok 0:3cf7c2683c3a 390 }
shimniok 0:3cf7c2683c3a 391
shimniok 0:3cf7c2683c3a 392 void DigoleSerialDisp::drawCircle(uint8_t x, uint8_t y, uint8_t r, uint8_t f) {
shimniok 0:3cf7c2683c3a 393 write("CC");
shimniok 0:3cf7c2683c3a 394 write(x);
shimniok 0:3cf7c2683c3a 395 write(y);
shimniok 0:3cf7c2683c3a 396 write(r);
shimniok 0:3cf7c2683c3a 397 write(f);
shimniok 0:3cf7c2683c3a 398 }
shimniok 0:3cf7c2683c3a 399
shimniok 0:3cf7c2683c3a 400 void DigoleSerialDisp::drawDisc(uint8_t x, uint8_t y, uint8_t r) {
shimniok 0:3cf7c2683c3a 401 drawCircle(x, y, r, 1);
shimniok 0:3cf7c2683c3a 402 }
shimniok 0:3cf7c2683c3a 403
shimniok 0:3cf7c2683c3a 404 void DigoleSerialDisp::drawFrame(uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
shimniok 0:3cf7c2683c3a 405 write("DR");
shimniok 0:3cf7c2683c3a 406 write(x);
shimniok 0:3cf7c2683c3a 407 write(y);
shimniok 0:3cf7c2683c3a 408 write(x + w);
shimniok 0:3cf7c2683c3a 409 write(y + h);
shimniok 0:3cf7c2683c3a 410 }
shimniok 0:3cf7c2683c3a 411
shimniok 0:3cf7c2683c3a 412 void DigoleSerialDisp::drawPixel(uint8_t x, uint8_t y, uint8_t color) {
shimniok 0:3cf7c2683c3a 413 write("DP");
shimniok 0:3cf7c2683c3a 414 write(x);
shimniok 0:3cf7c2683c3a 415 write(y);
shimniok 0:3cf7c2683c3a 416 write(color);
shimniok 0:3cf7c2683c3a 417 }
shimniok 0:3cf7c2683c3a 418
shimniok 0:3cf7c2683c3a 419 void DigoleSerialDisp::drawLine(uint8_t x, uint8_t y, uint8_t x1, uint8_t y1) {
shimniok 0:3cf7c2683c3a 420 write("LN");
shimniok 0:3cf7c2683c3a 421 write(x);
shimniok 0:3cf7c2683c3a 422 write(y);
shimniok 0:3cf7c2683c3a 423 write(x1);
shimniok 0:3cf7c2683c3a 424 write(y1);
shimniok 0:3cf7c2683c3a 425 }
shimniok 0:3cf7c2683c3a 426
shimniok 0:3cf7c2683c3a 427 void DigoleSerialDisp::drawLineTo(uint8_t x, uint8_t y) {
shimniok 0:3cf7c2683c3a 428 write("LT");
shimniok 0:3cf7c2683c3a 429 write(x);
shimniok 0:3cf7c2683c3a 430 write(y);
shimniok 0:3cf7c2683c3a 431 }
shimniok 0:3cf7c2683c3a 432
shimniok 0:3cf7c2683c3a 433 void DigoleSerialDisp::drawHLine(uint8_t x, uint8_t y, uint8_t w) {
shimniok 0:3cf7c2683c3a 434 drawLine(x, y, x + w, y);
shimniok 0:3cf7c2683c3a 435 }
shimniok 0:3cf7c2683c3a 436
shimniok 0:3cf7c2683c3a 437 void DigoleSerialDisp::drawVLine(uint8_t x, uint8_t y, uint8_t h) {
shimniok 0:3cf7c2683c3a 438 drawLine(x, y, x, y + h);
shimniok 0:3cf7c2683c3a 439 }
shimniok 0:3cf7c2683c3a 440
shimniok 0:3cf7c2683c3a 441 void DigoleSerialDisp::nextTextLine(void) {
shimniok 0:3cf7c2683c3a 442 write(null);
shimniok 0:3cf7c2683c3a 443 write("TRT");
shimniok 0:3cf7c2683c3a 444 }
shimniok 0:3cf7c2683c3a 445
shimniok 0:3cf7c2683c3a 446 void DigoleSerialDisp::setFont(uint8_t font) {
shimniok 0:3cf7c2683c3a 447 write("SF");
shimniok 0:3cf7c2683c3a 448 write(font);
shimniok 0:3cf7c2683c3a 449 }
shimniok 0:3cf7c2683c3a 450
shimniok 0:3cf7c2683c3a 451 void DigoleSerialDisp::setColor(uint8_t color) {
shimniok 0:3cf7c2683c3a 452 write("SC");
shimniok 0:3cf7c2683c3a 453 write(color);
shimniok 0:3cf7c2683c3a 454 }
shimniok 0:3cf7c2683c3a 455
shimniok 0:3cf7c2683c3a 456 void DigoleSerialDisp::backLightOn(void) {
shimniok 0:3cf7c2683c3a 457 write("BL");
shimniok 0:3cf7c2683c3a 458 write(1);
shimniok 0:3cf7c2683c3a 459 }
shimniok 0:3cf7c2683c3a 460
shimniok 0:3cf7c2683c3a 461 void DigoleSerialDisp::backLightOff(void) {
shimniok 0:3cf7c2683c3a 462 write("BL");
shimniok 0:3cf7c2683c3a 463 write(null);
shimniok 0:3cf7c2683c3a 464 }
shimniok 0:3cf7c2683c3a 465
shimniok 0:3cf7c2683c3a 466 void DigoleSerialDisp::directCommand(uint8_t d) {
shimniok 0:3cf7c2683c3a 467 write("MCD");
shimniok 0:3cf7c2683c3a 468 write(d);
shimniok 0:3cf7c2683c3a 469 }
shimniok 0:3cf7c2683c3a 470
shimniok 0:3cf7c2683c3a 471 void DigoleSerialDisp::directData(uint8_t d) {
shimniok 0:3cf7c2683c3a 472 write("MDT");
shimniok 0:3cf7c2683c3a 473 write(d);
shimniok 0:3cf7c2683c3a 474 }
shimniok 0:3cf7c2683c3a 475
shimniok 0:3cf7c2683c3a 476 void DigoleSerialDisp::moveArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, char xoffset, char yoffset) {
shimniok 0:3cf7c2683c3a 477 write("MA");
shimniok 0:3cf7c2683c3a 478 write(x0);
shimniok 0:3cf7c2683c3a 479 write(y0);
shimniok 0:3cf7c2683c3a 480 write(x1);
shimniok 0:3cf7c2683c3a 481 write(y1);
shimniok 0:3cf7c2683c3a 482 write(xoffset);
shimniok 0:3cf7c2683c3a 483 write(yoffset);
shimniok 0:3cf7c2683c3a 484 }
shimniok 0:3cf7c2683c3a 485
shimniok 0:3cf7c2683c3a 486
shimniok 0:3cf7c2683c3a 487 void DigoleSerialDisp::displayStartScreen(uint8_t m) {
shimniok 0:3cf7c2683c3a 488 write("DSS");
shimniok 0:3cf7c2683c3a 489 write(m);
shimniok 0:3cf7c2683c3a 490 } //display start screen
shimniok 0:3cf7c2683c3a 491
shimniok 0:3cf7c2683c3a 492
shimniok 0:3cf7c2683c3a 493 void DigoleSerialDisp::setMode(uint8_t m) {
shimniok 0:3cf7c2683c3a 494 write("DM");
shimniok 0:3cf7c2683c3a 495 write(m);
shimniok 0:3cf7c2683c3a 496 } //set display mode
shimniok 0:3cf7c2683c3a 497
shimniok 0:3cf7c2683c3a 498
shimniok 0:3cf7c2683c3a 499 void DigoleSerialDisp::setTextPosBack(void) {
shimniok 0:3cf7c2683c3a 500 write("ETB");
shimniok 0:3cf7c2683c3a 501 } //set text position back to previous, only one back allowed
shimniok 0:3cf7c2683c3a 502
shimniok 0:3cf7c2683c3a 503
shimniok 0:3cf7c2683c3a 504 void DigoleSerialDisp::setTextPosOffset(char xoffset, char yoffset) {
shimniok 0:3cf7c2683c3a 505 write("ETO");
shimniok 0:3cf7c2683c3a 506 write(xoffset);
shimniok 0:3cf7c2683c3a 507 write(yoffset);
shimniok 0:3cf7c2683c3a 508 }
shimniok 0:3cf7c2683c3a 509
shimniok 0:3cf7c2683c3a 510
shimniok 0:3cf7c2683c3a 511 void DigoleSerialDisp::setTextPosAbs(uint8_t x, uint8_t y) {
shimniok 0:3cf7c2683c3a 512 write("ETP");
shimniok 0:3cf7c2683c3a 513 write(x);
shimniok 0:3cf7c2683c3a 514 write(y);
shimniok 0:3cf7c2683c3a 515 }
shimniok 0:3cf7c2683c3a 516
shimniok 0:3cf7c2683c3a 517
shimniok 0:3cf7c2683c3a 518 void DigoleSerialDisp::setLinePattern(uint8_t pattern) {
shimniok 0:3cf7c2683c3a 519 write("SLP");
shimniok 0:3cf7c2683c3a 520 write(pattern);
shimniok 0:3cf7c2683c3a 521 }
shimniok 0:3cf7c2683c3a 522
shimniok 0:3cf7c2683c3a 523
shimniok 0:3cf7c2683c3a 524 void DigoleSerialDisp::setLCDChip(uint8_t chip) { //only for universal LCD adapter
shimniok 0:3cf7c2683c3a 525 write("SLCD");
shimniok 0:3cf7c2683c3a 526 write(chip);
shimniok 0:3cf7c2683c3a 527 }
shimniok 0:3cf7c2683c3a 528
shimniok 0:3cf7c2683c3a 529
shimniok 0:3cf7c2683c3a 530 void DigoleSerialDisp::uploadStartScreen(int lon, const unsigned char *data)
shimniok 0:3cf7c2683c3a 531 {
shimniok 0:3cf7c2683c3a 532 int j;
shimniok 0:3cf7c2683c3a 533 uint8_t c;
shimniok 0:3cf7c2683c3a 534 write("SSS");
shimniok 0:3cf7c2683c3a 535 write((uint8_t) (lon % 256));
shimniok 0:3cf7c2683c3a 536 write((uint8_t) (lon / 256));
shimniok 0:3cf7c2683c3a 537 for (j = 0; j < lon;j++) {
shimniok 0:3cf7c2683c3a 538 if((j%32)==0)
shimniok 0:3cf7c2683c3a 539 delay(10);
shimniok 0:3cf7c2683c3a 540 delay(_Comdelay);
shimniok 0:3cf7c2683c3a 541 c = data[j];
shimniok 0:3cf7c2683c3a 542 write(c);
shimniok 0:3cf7c2683c3a 543 }
shimniok 0:3cf7c2683c3a 544 }
shimniok 0:3cf7c2683c3a 545
shimniok 0:3cf7c2683c3a 546
shimniok 0:3cf7c2683c3a 547 void DigoleSerialDisp::uploadUserFont(int lon, const unsigned char *data, uint8_t sect) {
shimniok 0:3cf7c2683c3a 548 uint8_t c;
shimniok 0:3cf7c2683c3a 549 write("SUF");
shimniok 0:3cf7c2683c3a 550 write(sect);
shimniok 0:3cf7c2683c3a 551 write((uint8_t) (lon % 256));
shimniok 0:3cf7c2683c3a 552 write((uint8_t) (lon / 256));
shimniok 0:3cf7c2683c3a 553 for (int j = 0; j < lon; j++) {
shimniok 0:3cf7c2683c3a 554 if((j%32)==0)
shimniok 0:3cf7c2683c3a 555 delay(10);
shimniok 0:3cf7c2683c3a 556 delay(_Comdelay);
shimniok 0:3cf7c2683c3a 557 c = data[j];
shimniok 0:3cf7c2683c3a 558 write(c);
shimniok 0:3cf7c2683c3a 559 }
shimniok 0:3cf7c2683c3a 560 }
shimniok 0:3cf7c2683c3a 561
shimniok 0:3cf7c2683c3a 562 void DigoleSerialDisp::digitalOutput(uint8_t x)
shimniok 0:3cf7c2683c3a 563 {
shimniok 0:3cf7c2683c3a 564 write("DOUT");
shimniok 0:3cf7c2683c3a 565 write(x);
shimniok 0:3cf7c2683c3a 566 }