diff options
author | Mike Fiore <mfiore@multitech.com> | 2015-11-09 16:10:34 -0600 |
---|---|---|
committer | Mike Fiore <mfiore@multitech.com> | 2015-11-09 16:10:34 -0600 |
commit | 43af6ab4573b90d2cfde09333c68bec8e501ec23 (patch) | |
tree | 6264a36b746a1d3ffbf5bc367379496bc6fd958b | |
parent | 6e5a9c6d76b041237b5f535c1080b39a607e2889 (diff) | |
download | mtdot-box-evb-factory-firmware-43af6ab4573b90d2cfde09333c68bec8e501ec23.tar.gz mtdot-box-evb-factory-firmware-43af6ab4573b90d2cfde09333c68bec8e501ec23.tar.bz2 mtdot-box-evb-factory-firmware-43af6ab4573b90d2cfde09333c68bec8e501ec23.zip |
add DisplayManager
-rw-r--r-- | DisplayManager/DisplayManager.cpp | 59 | ||||
-rw-r--r-- | DisplayManager/DisplayManager.h | 48 | ||||
-rw-r--r-- | main.cpp | 22 |
3 files changed, 111 insertions, 18 deletions
diff --git a/DisplayManager/DisplayManager.cpp b/DisplayManager/DisplayManager.cpp new file mode 100644 index 0000000..e58ffad --- /dev/null +++ b/DisplayManager/DisplayManager.cpp @@ -0,0 +1,59 @@ +#include "DisplayManager.h" +#include "font_6x8.h" +#include "MultiTech_Logo.h" +#include "MTSLog.h" +#include "version.h" + +// product and version information +std::string DisplayManager::_product_name = "MTDOT-BOX/EVB"; +std::string DisplayManager::_program_name = "Factory Firmware"; +std::string DisplayManager::_program_version = std::string("Version ") + MTDOT_BOX_VERSION; + +DisplayManager::DisplayManager(DOGS102* lcd) : _lcd(lcd) {} + +DisplayManager::DisplayManager(DOGS102* lcd, const Layout layout) : _lcd(lcd), _layout(layout) {} + +DisplayManager::~DisplayManager() {} + +void DisplayManager::displaySplashScreen() { + _lcd->startUpdate(); + _lcd->writeBitmap(0, 0, MultiTech_Logo); + _lcd->writeText(0, 3, font_6x8, _product_name.c_str(), _product_name.size()); + _lcd->writeText(0, 4, font_6x8, _program_name.c_str(), _program_name.size()); + _lcd->writeText(0, 5, font_6x8, _program_version.c_str(), _program_version.size()); + _lcd->endUpdate(); +} + +bool DisplayManager::addLayout(Layout layout) { + _lcd->clearBuffer(); + + _layout = layout; + + _lcd->startUpdate(); + Labels l = _layout.first; + for (Labels::iterator it = l.begin(); it != l.end(); it++) + _lcd->writeText(it->column, it->page, font_6x8, it->value, it->size); + _lcd->endUpdate(); + + return true; +} + +bool DisplayManager::updateField(const int32_t& id, const char* field, const uint32_t& fieldSize) { + Fields f = _layout.second; + for (Fields::iterator it = f.begin(); it!= f.end(); it++) { + if (it->id == id) { + _lcd->startUpdate(); + uint8_t size = (fieldSize > it->maxSize) ? it->maxSize : fieldSize; + _lcd->writeText(it->column, it->page, font_6x8, field, size); + _lcd->endUpdate(); + return true; + } + } + + logError("field ID not found"); + return false; +} + +bool DisplayManager::updateField(const int32_t& id, const std::string& field) { + return updateField(id, field.c_str(), field.size()); +} diff --git a/DisplayManager/DisplayManager.h b/DisplayManager/DisplayManager.h new file mode 100644 index 0000000..c8dc4f3 --- /dev/null +++ b/DisplayManager/DisplayManager.h @@ -0,0 +1,48 @@ +#ifndef __DISPLAYMANAGER_H__ +#define __DISPLAYMANAGER_H__ + +#include "DOGS102.h" + +#include <string> +#include <vector> + +typedef struct field { + int32_t id; + uint8_t column; + uint8_t page; + uint8_t maxSize; +} Field; + +typedef struct label { + uint8_t column; + uint8_t page; + const char* value; + uint8_t size; +} Label; + +typedef std::vector<Field> Fields; +typedef std::vector<Label> Labels; +typedef std::pair<Labels, Fields> Layout; + +class DisplayManager { + public: + DisplayManager(DOGS102* lcd); + DisplayManager(DOGS102* lcd, const Layout layout); + ~DisplayManager(); + + void displaySplashScreen(); + + bool addLayout(const Layout layout); + + bool updateField(const int32_t& id, const char* field, const uint32_t& fieldSize); + bool updateField(const int32_t& id, const std::string& field); + + private: + Layout _layout; + DOGS102* _lcd; + static std::string _product_name; + static std::string _program_name; + static std::string _program_version; +}; + +#endif @@ -1,24 +1,16 @@ #include "mbed.h" #include "rtos.h" -#include "font_6x8.h" -#include "MultiTech_Logo.h" - #include "DOGS102.h" #include "ISL29011.h" #include "MMA845x.h" #include "MPL3115A2.h" #include "NCP5623B.h" #include "GPSPARSER.h" +#include "DisplayManager.h" #include "mDot.h" #include "MTSLog.h" -#include "version.h" - -// product and version information -static const std::string product_name = "MTDOT-BOX/EVB"; -static const std::string program_name = "Factory Firmware"; -static const std::string program_version = std::string("Version ") + MTDOT_BOX_VERSION; // LCD and backlight controllers SPI lcd_spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); @@ -27,6 +19,7 @@ DigitalOut lcd_spi_cs(SPI1_CS, 1); DigitalOut lcd_cd(XBEE_ON_SLEEP, 1); DOGS102* lcd; NCP5623B* lcd_backlight; +DisplayManager* display; // Serial debug port Serial debug(USBTX, USBRX); @@ -37,17 +30,10 @@ int main() { lcd = new DOGS102(lcd_spi, lcd_spi_cs, lcd_cd); lcd_backlight = new NCP5623B(backlight_i2c); + display = new DisplayManager(lcd); logInfo("starting..."); - - lcd->startUpdate(); - lcd->writeBitmap(0, 0, MultiTech_Logo); - lcd->writeText(0, 3, font_6x8, product_name.c_str(), product_name.size()); - lcd->writeText(0, 4, font_6x8, program_name.c_str(), program_name.size()); - lcd->writeText(0, 5, font_6x8, program_version.c_str(), program_version.size()); - lcd->endUpdate(); - - logInfo("on screen"); + display->displaySplashScreen(); while (true) { logInfo("in loop"); |