Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
io/LCDDisplay.cpp@138:f8ab852e83e7, 2016-08-08 (annotated)
- Committer:
- xinlei
- Date:
- Mon Aug 08 11:05:57 2016 +0000
- Revision:
- 138:f8ab852e83e7
- Parent:
- 95:5dfdc8568e9f
Etisalat and Teleena APN.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xinlei | 95:5dfdc8568e9f | 1 | #include <ctype.h> |
xinlei | 92:0acd11870c6a | 2 | #include "LCDDisplay.h" |
xinlei | 92:0acd11870c6a | 3 | #include "logging.h" |
xinlei | 92:0acd11870c6a | 4 | |
xinlei | 92:0acd11870c6a | 5 | #define DEF "\033[39m" |
xinlei | 92:0acd11870c6a | 6 | #define GRE "\033[32m" |
xinlei | 92:0acd11870c6a | 7 | #define CYA "\033[36m" |
xinlei | 92:0acd11870c6a | 8 | |
xinlei | 92:0acd11870c6a | 9 | void LCDDisplay::_setLine(char *dest, const char* src, size_t n) |
xinlei | 92:0acd11870c6a | 10 | { |
xinlei | 92:0acd11870c6a | 11 | if (n == 0) { |
xinlei | 92:0acd11870c6a | 12 | return ; |
xinlei | 92:0acd11870c6a | 13 | } else if (src && src!=dest) { |
xinlei | 95:5dfdc8568e9f | 14 | size_t j = 0; |
xinlei | 95:5dfdc8568e9f | 15 | for (size_t i = 0; src[i] && j<n; ++i) { |
xinlei | 95:5dfdc8568e9f | 16 | if (isprint(src[i])) |
xinlei | 95:5dfdc8568e9f | 17 | dest[j++] = src[i]; |
xinlei | 95:5dfdc8568e9f | 18 | } |
xinlei | 92:0acd11870c6a | 19 | dest[n-1] = '\0'; |
xinlei | 95:5dfdc8568e9f | 20 | if (j < n) |
xinlei | 95:5dfdc8568e9f | 21 | dest[j] = '\0'; |
xinlei | 92:0acd11870c6a | 22 | } |
xinlei | 92:0acd11870c6a | 23 | } |
xinlei | 92:0acd11870c6a | 24 | |
xinlei | 92:0acd11870c6a | 25 | void LCDDisplay::clear() |
xinlei | 92:0acd11870c6a | 26 | { |
xinlei | 92:0acd11870c6a | 27 | _setLine(firstLine, "", sizeof(firstLine)); |
xinlei | 92:0acd11870c6a | 28 | _setLine(secondLine, "", sizeof(secondLine)); |
xinlei | 92:0acd11870c6a | 29 | _setLine(thirdLine, "", sizeof(thirdLine)); |
xinlei | 92:0acd11870c6a | 30 | _lcd.cls(); |
xinlei | 92:0acd11870c6a | 31 | } |
xinlei | 92:0acd11870c6a | 32 | |
xinlei | 92:0acd11870c6a | 33 | void LCDDisplay::setFirstLine(const char* p) |
xinlei | 92:0acd11870c6a | 34 | { |
xinlei | 92:0acd11870c6a | 35 | _setLine(firstLine, p, sizeof(firstLine)); |
xinlei | 92:0acd11870c6a | 36 | lcdPrint(firstLine, secondLine, thirdLine); |
xinlei | 92:0acd11870c6a | 37 | } |
xinlei | 92:0acd11870c6a | 38 | |
xinlei | 92:0acd11870c6a | 39 | void LCDDisplay::setSecondLine(const char* p) |
xinlei | 92:0acd11870c6a | 40 | { |
xinlei | 92:0acd11870c6a | 41 | _setLine(secondLine, p, sizeof(secondLine)); |
xinlei | 92:0acd11870c6a | 42 | lcdPrint(firstLine, secondLine, thirdLine); |
xinlei | 92:0acd11870c6a | 43 | } |
xinlei | 92:0acd11870c6a | 44 | |
xinlei | 92:0acd11870c6a | 45 | void LCDDisplay::setThirdLine(const char* p) |
xinlei | 92:0acd11870c6a | 46 | { |
xinlei | 92:0acd11870c6a | 47 | _setLine(thirdLine, p, sizeof(thirdLine)); |
xinlei | 92:0acd11870c6a | 48 | lcdPrint(firstLine, secondLine, thirdLine); |
xinlei | 92:0acd11870c6a | 49 | } |
xinlei | 92:0acd11870c6a | 50 | |
xinlei | 92:0acd11870c6a | 51 | void LCDDisplay::setLines(const char *p1, const char *p2, const char *p3) |
xinlei | 92:0acd11870c6a | 52 | { |
xinlei | 92:0acd11870c6a | 53 | _setLine(firstLine, p1, sizeof(firstLine)); |
xinlei | 92:0acd11870c6a | 54 | if (p2) |
xinlei | 92:0acd11870c6a | 55 | _setLine(secondLine, p2, sizeof(secondLine)); |
xinlei | 92:0acd11870c6a | 56 | else |
xinlei | 92:0acd11870c6a | 57 | _setLine(secondLine, "", sizeof(secondLine)); |
xinlei | 92:0acd11870c6a | 58 | |
xinlei | 92:0acd11870c6a | 59 | if (p3) |
xinlei | 92:0acd11870c6a | 60 | _setLine(thirdLine, p3, sizeof(thirdLine)); |
xinlei | 92:0acd11870c6a | 61 | else |
xinlei | 92:0acd11870c6a | 62 | _setLine(thirdLine, "", sizeof(thirdLine)); |
xinlei | 92:0acd11870c6a | 63 | lcdPrint(firstLine, secondLine, thirdLine); |
xinlei | 92:0acd11870c6a | 64 | } |
xinlei | 92:0acd11870c6a | 65 | |
xinlei | 92:0acd11870c6a | 66 | void LCDDisplay::lcdPrint(const char *l1, const char *l2, const char *l3) |
xinlei | 92:0acd11870c6a | 67 | { |
xinlei | 92:0acd11870c6a | 68 | lcdLock.lock(); |
xinlei | 92:0acd11870c6a | 69 | _lcd.cls(); |
xinlei | 92:0acd11870c6a | 70 | _lcd.locate(0, 0); |
xinlei | 92:0acd11870c6a | 71 | _lcd.printf("%s\n", l1); |
xinlei | 92:0acd11870c6a | 72 | |
xinlei | 95:5dfdc8568e9f | 73 | if (l2) { |
xinlei | 92:0acd11870c6a | 74 | _lcd.printf("%s\n", l2); |
xinlei | 92:0acd11870c6a | 75 | |
xinlei | 95:5dfdc8568e9f | 76 | if (l3) { |
xinlei | 92:0acd11870c6a | 77 | _lcd.printf("%s\n", l3); |
xinlei | 92:0acd11870c6a | 78 | } |
xinlei | 92:0acd11870c6a | 79 | } |
xinlei | 92:0acd11870c6a | 80 | lcdLock.unlock(); |
xinlei | 92:0acd11870c6a | 81 | } |