Scott Hoppe / Mbed OS 4_Ecolab_RSSI_Checker

Dependencies:   DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot-dev-mbed5-deprecated

Fork of MTDOT-BOX-EVB-Factory-Firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Layout.cpp Source File

Layout.cpp

00001 /* Copyright (c) <2016> <MultiTech Systems>, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction, 
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or 
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 
00019 #include "Layout.h"
00020 #include "font_6x8.h"
00021 
00022 Label::Label(uint8_t col, uint8_t row, std::string value)
00023   : _col(col),
00024     _row(row),
00025     _value(value)
00026 {}
00027 
00028 Field::Field(uint8_t col, uint8_t row, uint8_t maxSize)
00029   : _col(col),
00030     _row(row),
00031     _maxSize(maxSize)
00032 {}
00033 
00034 Image::Image(uint8_t col, uint8_t row, const uint8_t* bmp)
00035   : _col(col),
00036     _row(row),
00037     _bmp(bmp)
00038 {}
00039 
00040 Layout::Layout(DOGS102* lcd) : _lcd(lcd) {}
00041 
00042 Layout::~Layout() {}
00043 
00044 void Layout::clear() {
00045     _lcd->clearBuffer();
00046 }
00047 
00048 void Layout::startUpdate() {
00049     _lcd->startUpdate();
00050 }
00051 
00052 void Layout::endUpdate() {
00053     _lcd->endUpdate();
00054 }
00055 
00056 bool Layout::writeLabel(const Label& label) {
00057     return writeText(label._col, label._row, label._value.c_str(), label._value.size());
00058 }
00059 
00060 bool Layout::writeField(const Field& field, const std::string& value, bool apply) {
00061     bool ret;
00062     std::string v = value;
00063 
00064     if (apply)
00065         startUpdate();
00066 
00067     // fill the whole length with blank space in case the previous value was longer than this one
00068     while (v.size() < field._maxSize)
00069         v += " ";
00070 
00071     ret = writeText(field._col, field._row, v.c_str(), field._maxSize);
00072 
00073     if (apply)
00074         endUpdate();
00075 
00076     return true;
00077 }
00078 
00079 bool Layout::writeField(const Field& field, const char* value, size_t size, bool apply) {
00080     bool ret;
00081     char buf[32];
00082     // fill the whole length with blank space in case the previous value was longer than this one
00083     memset(buf, ' ', sizeof(buf));
00084 
00085     if (apply)
00086         startUpdate();
00087 
00088     snprintf(buf, sizeof(buf), "%s", value);
00089     // wipe out the null character - the LCD driver will just skip that character otherwise
00090     buf[size] = ' ';
00091 
00092     ret = writeText(field._col, field._row, buf, field._maxSize);
00093 
00094     if (apply)
00095         endUpdate();
00096 
00097     return true;
00098 }
00099 
00100 bool Layout::writeImage(const Image& image, bool apply) {
00101     bool ret;
00102 
00103     if (apply)
00104         startUpdate();
00105 
00106     ret = writeBmp(image._row, image._col, image._bmp);
00107 
00108     if (apply)
00109         endUpdate();
00110 
00111     return ret;
00112 }
00113 
00114 void Layout::removeField(const Field& field) {
00115     startUpdate();
00116     std::string s(' ', field._maxSize);
00117     writeText(field._row, field._col, s.c_str(), s.size());
00118     endUpdate();
00119 }
00120 
00121 bool Layout::writeText(uint8_t col, uint8_t row, const char* value, size_t size) {
00122     _lcd->writeText(col*6, row, font_6x8, value, size);
00123 
00124     return true;
00125 }
00126 
00127 bool Layout::writeBmp(uint8_t col, uint8_t row, const uint8_t* bmp) {
00128     _lcd->writeBitmap(col*6, row, bmp);
00129 
00130     return true;
00131 }
00132