Custom Channel Plan version of MTDOT Box firmware
Dependencies: DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot-Custom mDot_Channel_Plans
Fork of MTDOT-BOX-EVB-Factory-Firmware by
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 00083 // fill the whole length with blank space in case the previous value was longer than this one 00084 memset(buf, ' ', sizeof(buf)); 00085 00086 if (apply) 00087 startUpdate(); 00088 00089 snprintf(buf, sizeof(buf), "%s", value); 00090 // wipe out the null character - the LCD driver will just skip that character otherwise 00091 buf[size] = ' '; 00092 00093 ret = writeText(field._col, field._row, buf, field._maxSize); 00094 00095 if (apply) 00096 endUpdate(); 00097 00098 return true; 00099 } 00100 00101 bool Layout::writeImage(const Image& image, bool apply) { 00102 bool ret; 00103 00104 if (apply) 00105 startUpdate(); 00106 00107 ret = writeBmp(image._row, image._col, image._bmp); 00108 00109 if (apply) 00110 endUpdate(); 00111 00112 return ret; 00113 } 00114 00115 void Layout::removeField(const Field& field) { 00116 startUpdate(); 00117 std::string s(' ', field._maxSize); 00118 writeText(field._row, field._col, s.c_str(), s.size()); 00119 endUpdate(); 00120 } 00121 00122 bool Layout::writeText(uint8_t col, uint8_t row, const char* value, size_t size) { 00123 _lcd->writeText(col*6, row, font_6x8, value, size); 00124 00125 return true; 00126 } 00127 00128 bool Layout::writeBmp(uint8_t col, uint8_t row, const uint8_t* bmp) { 00129 _lcd->writeBitmap(col*6, row, bmp); 00130 00131 return true; 00132 } 00133
Generated on Tue Jul 12 2022 13:07:49 by 1.7.2