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