Updated to libmDot 1.0.8-1
Dependencies: DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot mbed-rtos mbed
Fork of MTDOT-BOX-EVB-Factory-Firmware by
Layout/Layout.cpp@1:71125aa00e33, 2016-02-04 (annotated)
- Committer:
- Mike Fiore
- Date:
- Thu Feb 04 12:36:36 2016 -0600
- Revision:
- 1:71125aa00e33
add rest of source - version 2.0.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:71125aa00e33 | 1 | /* Copyright (c) <2016> <MultiTech Systems>, MIT License |
Mike Fiore |
1:71125aa00e33 | 2 | * |
Mike Fiore |
1:71125aa00e33 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Mike Fiore |
1:71125aa00e33 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Mike Fiore |
1:71125aa00e33 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Mike Fiore |
1:71125aa00e33 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Mike Fiore |
1:71125aa00e33 | 7 | * furnished to do so, subject to the following conditions: |
Mike Fiore |
1:71125aa00e33 | 8 | * |
Mike Fiore |
1:71125aa00e33 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Mike Fiore |
1:71125aa00e33 | 10 | * substantial portions of the Software. |
Mike Fiore |
1:71125aa00e33 | 11 | * |
Mike Fiore |
1:71125aa00e33 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Mike Fiore |
1:71125aa00e33 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Mike Fiore |
1:71125aa00e33 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Mike Fiore |
1:71125aa00e33 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Mike Fiore |
1:71125aa00e33 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Mike Fiore |
1:71125aa00e33 | 17 | */ |
Mike Fiore |
1:71125aa00e33 | 18 | |
Mike Fiore |
1:71125aa00e33 | 19 | #include "Layout.h" |
Mike Fiore |
1:71125aa00e33 | 20 | #include "font_6x8.h" |
Mike Fiore |
1:71125aa00e33 | 21 | |
Mike Fiore |
1:71125aa00e33 | 22 | Label::Label(uint8_t col, uint8_t row, std::string value) |
Mike Fiore |
1:71125aa00e33 | 23 | : _col(col), |
Mike Fiore |
1:71125aa00e33 | 24 | _row(row), |
Mike Fiore |
1:71125aa00e33 | 25 | _value(value) |
Mike Fiore |
1:71125aa00e33 | 26 | {} |
Mike Fiore |
1:71125aa00e33 | 27 | |
Mike Fiore |
1:71125aa00e33 | 28 | Field::Field(uint8_t col, uint8_t row, uint8_t maxSize) |
Mike Fiore |
1:71125aa00e33 | 29 | : _col(col), |
Mike Fiore |
1:71125aa00e33 | 30 | _row(row), |
Mike Fiore |
1:71125aa00e33 | 31 | _maxSize(maxSize) |
Mike Fiore |
1:71125aa00e33 | 32 | {} |
Mike Fiore |
1:71125aa00e33 | 33 | |
Mike Fiore |
1:71125aa00e33 | 34 | Image::Image(uint8_t col, uint8_t row, const uint8_t* bmp) |
Mike Fiore |
1:71125aa00e33 | 35 | : _col(col), |
Mike Fiore |
1:71125aa00e33 | 36 | _row(row), |
Mike Fiore |
1:71125aa00e33 | 37 | _bmp(bmp) |
Mike Fiore |
1:71125aa00e33 | 38 | {} |
Mike Fiore |
1:71125aa00e33 | 39 | |
Mike Fiore |
1:71125aa00e33 | 40 | Layout::Layout(DOGS102* lcd) : _lcd(lcd) {} |
Mike Fiore |
1:71125aa00e33 | 41 | |
Mike Fiore |
1:71125aa00e33 | 42 | Layout::~Layout() {} |
Mike Fiore |
1:71125aa00e33 | 43 | |
Mike Fiore |
1:71125aa00e33 | 44 | void Layout::clear() { |
Mike Fiore |
1:71125aa00e33 | 45 | _lcd->clearBuffer(); |
Mike Fiore |
1:71125aa00e33 | 46 | } |
Mike Fiore |
1:71125aa00e33 | 47 | |
Mike Fiore |
1:71125aa00e33 | 48 | void Layout::startUpdate() { |
Mike Fiore |
1:71125aa00e33 | 49 | _lcd->startUpdate(); |
Mike Fiore |
1:71125aa00e33 | 50 | } |
Mike Fiore |
1:71125aa00e33 | 51 | |
Mike Fiore |
1:71125aa00e33 | 52 | void Layout::endUpdate() { |
Mike Fiore |
1:71125aa00e33 | 53 | _lcd->endUpdate(); |
Mike Fiore |
1:71125aa00e33 | 54 | } |
Mike Fiore |
1:71125aa00e33 | 55 | |
Mike Fiore |
1:71125aa00e33 | 56 | bool Layout::writeLabel(const Label& label) { |
Mike Fiore |
1:71125aa00e33 | 57 | return writeText(label._col, label._row, label._value.c_str(), label._value.size()); |
Mike Fiore |
1:71125aa00e33 | 58 | } |
Mike Fiore |
1:71125aa00e33 | 59 | |
Mike Fiore |
1:71125aa00e33 | 60 | bool Layout::writeField(const Field& field, const std::string& value, bool apply) { |
Mike Fiore |
1:71125aa00e33 | 61 | bool ret; |
Mike Fiore |
1:71125aa00e33 | 62 | std::string v = value; |
Mike Fiore |
1:71125aa00e33 | 63 | |
Mike Fiore |
1:71125aa00e33 | 64 | if (apply) |
Mike Fiore |
1:71125aa00e33 | 65 | startUpdate(); |
Mike Fiore |
1:71125aa00e33 | 66 | |
Mike Fiore |
1:71125aa00e33 | 67 | // fill the whole length with blank space in case the previous value was longer than this one |
Mike Fiore |
1:71125aa00e33 | 68 | while (v.size() < field._maxSize) |
Mike Fiore |
1:71125aa00e33 | 69 | v += " "; |
Mike Fiore |
1:71125aa00e33 | 70 | |
Mike Fiore |
1:71125aa00e33 | 71 | ret = writeText(field._col, field._row, v.c_str(), field._maxSize); |
Mike Fiore |
1:71125aa00e33 | 72 | |
Mike Fiore |
1:71125aa00e33 | 73 | if (apply) |
Mike Fiore |
1:71125aa00e33 | 74 | endUpdate(); |
Mike Fiore |
1:71125aa00e33 | 75 | |
Mike Fiore |
1:71125aa00e33 | 76 | return true; |
Mike Fiore |
1:71125aa00e33 | 77 | } |
Mike Fiore |
1:71125aa00e33 | 78 | |
Mike Fiore |
1:71125aa00e33 | 79 | bool Layout::writeField(const Field& field, const char* value, size_t size, bool apply) { |
Mike Fiore |
1:71125aa00e33 | 80 | bool ret; |
Mike Fiore |
1:71125aa00e33 | 81 | char buf[32]; |
Mike Fiore |
1:71125aa00e33 | 82 | |
Mike Fiore |
1:71125aa00e33 | 83 | // fill the whole length with blank space in case the previous value was longer than this one |
Mike Fiore |
1:71125aa00e33 | 84 | memset(buf, ' ', sizeof(buf)); |
Mike Fiore |
1:71125aa00e33 | 85 | |
Mike Fiore |
1:71125aa00e33 | 86 | if (apply) |
Mike Fiore |
1:71125aa00e33 | 87 | startUpdate(); |
Mike Fiore |
1:71125aa00e33 | 88 | |
Mike Fiore |
1:71125aa00e33 | 89 | snprintf(buf, sizeof(buf), "%s", value); |
Mike Fiore |
1:71125aa00e33 | 90 | // wipe out the null character - the LCD driver will just skip that character otherwise |
Mike Fiore |
1:71125aa00e33 | 91 | buf[size] = ' '; |
Mike Fiore |
1:71125aa00e33 | 92 | |
Mike Fiore |
1:71125aa00e33 | 93 | ret = writeText(field._col, field._row, buf, field._maxSize); |
Mike Fiore |
1:71125aa00e33 | 94 | |
Mike Fiore |
1:71125aa00e33 | 95 | if (apply) |
Mike Fiore |
1:71125aa00e33 | 96 | endUpdate(); |
Mike Fiore |
1:71125aa00e33 | 97 | |
Mike Fiore |
1:71125aa00e33 | 98 | return true; |
Mike Fiore |
1:71125aa00e33 | 99 | } |
Mike Fiore |
1:71125aa00e33 | 100 | |
Mike Fiore |
1:71125aa00e33 | 101 | bool Layout::writeImage(const Image& image, bool apply) { |
Mike Fiore |
1:71125aa00e33 | 102 | bool ret; |
Mike Fiore |
1:71125aa00e33 | 103 | |
Mike Fiore |
1:71125aa00e33 | 104 | if (apply) |
Mike Fiore |
1:71125aa00e33 | 105 | startUpdate(); |
Mike Fiore |
1:71125aa00e33 | 106 | |
Mike Fiore |
1:71125aa00e33 | 107 | ret = writeBmp(image._row, image._col, image._bmp); |
Mike Fiore |
1:71125aa00e33 | 108 | |
Mike Fiore |
1:71125aa00e33 | 109 | if (apply) |
Mike Fiore |
1:71125aa00e33 | 110 | endUpdate(); |
Mike Fiore |
1:71125aa00e33 | 111 | |
Mike Fiore |
1:71125aa00e33 | 112 | return ret; |
Mike Fiore |
1:71125aa00e33 | 113 | } |
Mike Fiore |
1:71125aa00e33 | 114 | |
Mike Fiore |
1:71125aa00e33 | 115 | void Layout::removeField(const Field& field) { |
Mike Fiore |
1:71125aa00e33 | 116 | startUpdate(); |
Mike Fiore |
1:71125aa00e33 | 117 | std::string s(' ', field._maxSize); |
Mike Fiore |
1:71125aa00e33 | 118 | writeText(field._row, field._col, s.c_str(), s.size()); |
Mike Fiore |
1:71125aa00e33 | 119 | endUpdate(); |
Mike Fiore |
1:71125aa00e33 | 120 | } |
Mike Fiore |
1:71125aa00e33 | 121 | |
Mike Fiore |
1:71125aa00e33 | 122 | bool Layout::writeText(uint8_t col, uint8_t row, const char* value, size_t size) { |
Mike Fiore |
1:71125aa00e33 | 123 | _lcd->writeText(col*6, row, font_6x8, value, size); |
Mike Fiore |
1:71125aa00e33 | 124 | |
Mike Fiore |
1:71125aa00e33 | 125 | return true; |
Mike Fiore |
1:71125aa00e33 | 126 | } |
Mike Fiore |
1:71125aa00e33 | 127 | |
Mike Fiore |
1:71125aa00e33 | 128 | bool Layout::writeBmp(uint8_t col, uint8_t row, const uint8_t* bmp) { |
Mike Fiore |
1:71125aa00e33 | 129 | _lcd->writeBitmap(col*6, row, bmp); |
Mike Fiore |
1:71125aa00e33 | 130 | |
Mike Fiore |
1:71125aa00e33 | 131 | return true; |
Mike Fiore |
1:71125aa00e33 | 132 | } |
Mike Fiore |
1:71125aa00e33 | 133 |