diff options
| -rw-r--r-- | Layout/Layout.cpp | 88 | ||||
| -rw-r--r-- | Layout/Layout.h | 75 | 
2 files changed, 87 insertions, 76 deletions
| diff --git a/Layout/Layout.cpp b/Layout/Layout.cpp index e58ffad..b2ca942 100644 --- a/Layout/Layout.cpp +++ b/Layout/Layout.cpp @@ -1,59 +1,65 @@ -#include "DisplayManager.h" +#include "Layout.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; +Label::Label(uint8_t col, uint8_t row, std::string value) +  : _col(col), +    _row(row), +    _value(value) +{} -DisplayManager::DisplayManager(DOGS102* lcd) : _lcd(lcd) {} +Field::Field(uint8_t col, uint8_t row, uint8_t maxSize) +  : _col(col), +    _row(row), +    _maxSize(maxSize) +{} -DisplayManager::DisplayManager(DOGS102* lcd, const Layout layout) : _lcd(lcd), _layout(layout) {} +Image::Image(uint8_t col, uint8_t row, const uint8_t* bmp) +  : _col(col), +    _row(row), +    _bmp(bmp) +{} -DisplayManager::~DisplayManager() {} +Layout::Layout(DOGS102* lcd) : _lcd(lcd) {} -void DisplayManager::displaySplashScreen() { +Layout::~Layout() {} + +void Layout::clear() { +    _lcd->clearBuffer(); +} + +void Layout::startUpdate() {      _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()); +} + +void Layout::endUpdate() {      _lcd->endUpdate();  } -bool DisplayManager::addLayout(Layout layout) { -    _lcd->clearBuffer(); +bool Layout::writeField(uint8_t col, uint8_t row, std::string field, bool apply) { +    return writeField(col, row, field.c_str(), field.size(), apply); +} -    _layout = layout; +bool Layout::writeField(uint8_t col, uint8_t row, const char* field, size_t size, bool apply) { +    if (apply) +        startUpdate(); -    _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(); +    _lcd->writeText(col*6, row, font_6x8, field, size); + +    if (apply) +        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 Layout::writeImage(uint8_t col, uint8_t row, const uint8_t* bmp, bool apply) { +    if (apply) +        startUpdate(); -bool DisplayManager::updateField(const int32_t& id, const std::string& field) { -    return updateField(id, field.c_str(), field.size()); +    _lcd->writeBitmap(col, row, bmp); + +    if (apply) +        endUpdate(); + +    return true;  } + diff --git a/Layout/Layout.h b/Layout/Layout.h index c8dc4f3..5b25458 100644 --- a/Layout/Layout.h +++ b/Layout/Layout.h @@ -1,48 +1,53 @@ -#ifndef __DISPLAYMANAGER_H__ -#define __DISPLAYMANAGER_H__ +#ifndef __LAYOUT_H__ +#define __LAYOUT_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 { + +class Label {      public: -        DisplayManager(DOGS102* lcd); -        DisplayManager(DOGS102* lcd, const Layout layout); -        ~DisplayManager(); +        Label(uint8_t col, uint8_t row, std::string value); + +        uint8_t _col; +        uint8_t _row; +        std::string _value; +}; -        void displaySplashScreen(); +class Field { +    public: +        Field(uint8_t col, uint8_t row, uint8_t maxSize); -        bool addLayout(const Layout layout); +        uint8_t _col; +        uint8_t _row; +        uint8_t _maxSize; +}; -        bool updateField(const int32_t& id, const char* field, const uint32_t& fieldSize); -        bool updateField(const int32_t& id, const std::string& field); +class Image { +    public: +        Image(uint8_t col, uint8_t row, const uint8_t* bmp); + +        uint8_t _col; +        uint8_t _row; +        const uint8_t* _bmp; +}; + +class Layout { +    public: +        Layout(DOGS102* lcd); +        ~Layout(); + +        virtual void display() = 0; +         +    protected: +        void clear(); +        void startUpdate(); +        void endUpdate(); +        bool writeField(uint8_t col, uint8_t row, std::string field, bool apply = false); +        bool writeField(uint8_t col, uint8_t row, const char* field, size_t size, bool apply = false); +        bool writeImage(uint8_t col, uint8_t row, const uint8_t* bmp, bool apply = false);      private: -        Layout _layout;          DOGS102* _lcd; -        static std::string _product_name; -        static std::string _program_name; -        static std::string _program_version;  };  #endif | 
