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