diff options
Diffstat (limited to 'Layout')
| -rw-r--r-- | Layout/Layout.cpp | 61 | ||||
| -rw-r--r-- | Layout/Layout.h | 11 | ||||
| -rw-r--r-- | Layout/LayoutConfig.cpp | 23 | ||||
| -rw-r--r-- | Layout/LayoutConfig.h | 20 | ||||
| -rw-r--r-- | Layout/LayoutDemoHelp.cpp | 28 | ||||
| -rw-r--r-- | Layout/LayoutDemoHelp.h | 22 | ||||
| -rw-r--r-- | Layout/LayoutJoin.cpp | 104 | ||||
| -rw-r--r-- | Layout/LayoutJoin.h | 46 | ||||
| -rw-r--r-- | Layout/LayoutScrollSelect.cpp | 244 | ||||
| -rw-r--r-- | Layout/LayoutScrollSelect.h | 40 | ||||
| -rw-r--r-- | Layout/LayoutSingleHelp.cpp | 26 | ||||
| -rw-r--r-- | Layout/LayoutSingleHelp.h | 21 | ||||
| -rw-r--r-- | Layout/LayoutStartup.cpp | 14 | ||||
| -rw-r--r-- | Layout/LayoutSweepHelp.cpp | 26 | ||||
| -rw-r--r-- | Layout/LayoutSweepHelp.h | 21 |
15 files changed, 693 insertions, 14 deletions
diff --git a/Layout/Layout.cpp b/Layout/Layout.cpp index b2ca942..7b0c375 100644 --- a/Layout/Layout.cpp +++ b/Layout/Layout.cpp @@ -35,15 +35,22 @@ void Layout::endUpdate() { _lcd->endUpdate(); } -bool Layout::writeField(uint8_t col, uint8_t row, std::string field, bool apply) { - return writeField(col, row, field.c_str(), field.size(), apply); +bool Layout::writeLabel(const Label& label) { + return writeText(label._col, label._row, label._value.c_str(), label._value.size()); } -bool Layout::writeField(uint8_t col, uint8_t row, const char* field, size_t size, bool apply) { +bool Layout::writeField(const Field& field, const std::string& value, bool apply) { + bool ret; + std::string v = value; + if (apply) startUpdate(); - _lcd->writeText(col*6, row, font_6x8, field, size); + // fill the whole length with blank space in case the previous value was longer than this one + while (v.size() < field._maxSize) + v += " "; + + ret = writeText(field._col, field._row, v.c_str(), field._maxSize); if (apply) endUpdate(); @@ -51,11 +58,20 @@ bool Layout::writeField(uint8_t col, uint8_t row, const char* field, size_t size return true; } -bool Layout::writeImage(uint8_t col, uint8_t row, const uint8_t* bmp, bool apply) { +bool Layout::writeField(const Field& field, const char* value, size_t size, bool apply) { + bool ret; + char buf[32]; + size_t s = (field._maxSize > size) ? size : field._maxSize; + + // fill the whole length with blank space in case the previous value was longer than this one + memset(buf, 0x20, sizeof(buf)); + if (apply) startUpdate(); - _lcd->writeBitmap(col, row, bmp); + snprintf(buf, s, "%s", value); + + ret = writeText(field._col, field._row, value, field._maxSize); if (apply) endUpdate(); @@ -63,3 +79,36 @@ bool Layout::writeImage(uint8_t col, uint8_t row, const uint8_t* bmp, bool apply return true; } +bool Layout::writeImage(const Image& image, bool apply) { + bool ret; + + if (apply) + startUpdate(); + + ret = writeBmp(image._row, image._col, image._bmp); + + if (apply) + endUpdate(); + + return ret; +} + +void Layout::removeField(const Field& field) { + startUpdate(); + std::string s(' ', field._maxSize); + writeText(field._row, field._col, s.c_str(), s.size()); + endUpdate(); +} + +bool Layout::writeText(uint8_t col, uint8_t row, const char* value, size_t size) { + _lcd->writeText(col*6, row, font_6x8, value, size); + + return true; +} + +bool Layout::writeBmp(uint8_t col, uint8_t row, const uint8_t* bmp) { + _lcd->writeBitmap(col*6, row, bmp); + + return true; +} + diff --git a/Layout/Layout.h b/Layout/Layout.h index 5b25458..29d59ff 100644 --- a/Layout/Layout.h +++ b/Layout/Layout.h @@ -42,11 +42,16 @@ class Layout { 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); + bool writeLabel(const Label& label); + bool writeField(const Field& field, const std::string& value, bool apply = false); + bool writeField(const Field& field, const char* value, size_t size, bool apply = false); + bool writeImage(const Image& image, bool apply = false); + void removeField(const Field& field); private: + bool writeText(uint8_t col, uint8_t row, const char* value, size_t size); + bool writeBmp(uint8_t col, uint8_t row, const uint8_t* bmp); + DOGS102* _lcd; }; diff --git a/Layout/LayoutConfig.cpp b/Layout/LayoutConfig.cpp new file mode 100644 index 0000000..dc28738 --- /dev/null +++ b/Layout/LayoutConfig.cpp @@ -0,0 +1,23 @@ +#include "LayoutConfig.h" + +LayoutConfig::LayoutConfig(DOGS102* lcd) + : Layout(lcd), + _lMode(0, 0, "Configuration"), + _lHelp1(0, 2, "Connect USB debug"), + _lHelp2(0, 3, "to PC at 115200"), + _lHelp3(0, 4, "baud to configure") +{} + +LayoutConfig::~LayoutConfig() {} + +void LayoutConfig::display() { + clear(); + startUpdate(); + + writeLabel(_lMode); + writeLabel(_lHelp1); + writeLabel(_lHelp2); + writeLabel(_lHelp3); + + endUpdate(); +} diff --git a/Layout/LayoutConfig.h b/Layout/LayoutConfig.h new file mode 100644 index 0000000..0fdba1c --- /dev/null +++ b/Layout/LayoutConfig.h @@ -0,0 +1,20 @@ +#ifndef __LAYOUTCONFIG_H__ +#define __LAYOUTCONFIG_H__ + +#include "Layout.h" + +class LayoutConfig : public Layout { + public: + LayoutConfig(DOGS102* lcd); + ~LayoutConfig(); + + void display(); + + private: + Label _lMode; + Label _lHelp1; + Label _lHelp2; + Label _lHelp3; +}; + +#endif diff --git a/Layout/LayoutDemoHelp.cpp b/Layout/LayoutDemoHelp.cpp new file mode 100644 index 0000000..dab907e --- /dev/null +++ b/Layout/LayoutDemoHelp.cpp @@ -0,0 +1,28 @@ +#include "LayoutDemoHelp.h" + +LayoutDemoHelp::LayoutDemoHelp(DOGS102* lcd) + : Layout(lcd), + _lMode(0, 0, "LoRa Demo"), + _lDesc(0, 1, "Select TX Method"), + _lIns1(0, 4, "Hold SW1 any time"), + _lIns2(0, 5, "for Main Menu"), + _lSw1(10, 7, "Trigger"), + _lSw2(0, 7, "Interval") +{} + +LayoutDemoHelp::~LayoutDemoHelp() {} + +void LayoutDemoHelp::display() { + clear(); + startUpdate(); + + writeLabel(_lMode); + writeLabel(_lDesc); + writeLabel(_lIns1); + writeLabel(_lIns2); + writeLabel(_lSw1); + writeLabel(_lSw2); + + endUpdate(); +} + diff --git a/Layout/LayoutDemoHelp.h b/Layout/LayoutDemoHelp.h new file mode 100644 index 0000000..3e20df9 --- /dev/null +++ b/Layout/LayoutDemoHelp.h @@ -0,0 +1,22 @@ +#ifndef __LAYOUTDEMOHELP_H__ +#define __LAYOUTDEMOHELP_H__ + +#include "Layout.h" + +class LayoutDemoHelp : public Layout { + public: + LayoutDemoHelp(DOGS102* lcd); + ~LayoutDemoHelp(); + + void display(); + + private: + Label _lMode; + Label _lDesc; + Label _lIns1; + Label _lIns2; + Label _lSw1; + Label _lSw2; +}; + +#endif diff --git a/Layout/LayoutJoin.cpp b/Layout/LayoutJoin.cpp new file mode 100644 index 0000000..3b67c28 --- /dev/null +++ b/Layout/LayoutJoin.cpp @@ -0,0 +1,104 @@ +#include "LayoutJoin.h" + +LayoutJoin::LayoutJoin(DOGS102* lcd, uint8_t band) + : Layout(lcd), + _lId(0, 1, "NI="), + _lKey(0, 2, "NK="), + _lFsb(0, 3, "FSB="), + _lRate(0, 5, "DR="), + _lPower(6, 5, "P="), + _lAttempt(11, 5, "A="), + _fStatus(0, 0, 17), + _fId(3, 1, 14), + _fKey(3, 2, 14), + _fFsb(4, 3, 2), + _fRate(3, 5, 2), + _fPower(8, 5, 2), + _fAttempt(13, 5, 4), + _fCountdown(0, 7, 9), + _fCountdownLabel(0, 6, 17), + _fCancel(11, 7, 6), + _band(band) +{} + +LayoutJoin::~LayoutJoin() {} + +void LayoutJoin::display() { + clear(); + startUpdate(); + + writeLabel(_lId); + writeLabel(_lKey); + if (_band == mDot::FB_915) { + writeLabel(_lFsb); + } + writeLabel(_lRate); + writeLabel(_lPower); + writeLabel(_lAttempt); + + displayCancel(); + + endUpdate(); +} + +void LayoutJoin::updateId(std::string id) { + writeField(_fId, id, true); +} + +void LayoutJoin::updateKey(std::string key) { + writeField(_fKey, key, true); +} + +void LayoutJoin::updateFsb(uint8_t band) { + char buf[8]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%u", band); + writeField(_fFsb, buf, size, true); +} + +void LayoutJoin::updateRate(std::string rate) { + writeField(_fRate, rate); +} + +void LayoutJoin::updatePower(uint32_t power) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", power); + writeField(_fPower, buf, size, true); +} + +void LayoutJoin::updateAttempt(uint32_t attempt) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", attempt); + writeField(_fAttempt, buf, size, true); +} + +void LayoutJoin::updateStatus(std::string status) { + writeField(_fStatus, status, true); +} + +void LayoutJoin::updateCountdown(uint32_t seconds) { + char buf[16]; + size_t size; + + writeField(_fCountdownLabel, "No Free Channel"); + size = snprintf(buf, sizeof(buf), "%lu", seconds); + writeField(_fPower, buf, size, true); +} + +void LayoutJoin::removeCountdown() { + removeField(_fCountdownLabel); + removeField(_fCountdown); +} + +void LayoutJoin::displayCancel(bool display) { + if (display) + writeField(_fCancel, "Cancel", true); + else + removeField(_fCancel); +} + diff --git a/Layout/LayoutJoin.h b/Layout/LayoutJoin.h new file mode 100644 index 0000000..2f71aec --- /dev/null +++ b/Layout/LayoutJoin.h @@ -0,0 +1,46 @@ +#ifndef __LAYOUTJOIN_H__ +#define __LAYOUTJOIN_H__ + +#include "Layout.h" +#include "mDot.h" + +class LayoutJoin : public Layout { + public: + LayoutJoin(DOGS102* lcd, uint8_t band); + ~LayoutJoin(); + + void display(); + + void updateId(std::string id); + void updateKey(std::string key); + void updateFsb(uint8_t band); + void updateRate(std::string rate); + void updatePower(uint32_t power); + void updateAttempt(uint32_t attempt); + void updateStatus(std::string status); + void updateCountdown(uint32_t seconds); + void removeCountdown(); + void displayCancel(bool display = true); + + private: + Label _lId; + Label _lKey; + Label _lFsb; + Label _lRate; + Label _lPower; + Label _lAttempt; + + Field _fStatus; + Field _fId; + Field _fKey; + Field _fFsb; + Field _fRate; + Field _fPower; + Field _fAttempt; + Field _fCountdown; + Field _fCountdownLabel; + Field _fCancel; + uint8_t _band; +}; + +#endif diff --git a/Layout/LayoutScrollSelect.cpp b/Layout/LayoutScrollSelect.cpp new file mode 100644 index 0000000..5c7072e --- /dev/null +++ b/Layout/LayoutScrollSelect.cpp @@ -0,0 +1,244 @@ +#include "LayoutScrollSelect.h" +#include "MTSLog.h" + +LayoutScrollSelect::LayoutScrollSelect(DOGS102* lcd, Items items, std::string info1, std::string info2) + : Layout(lcd), + _lSw1(0, 7, "Scroll"), + _lSw2(11, 7, "Select"), + _lInfo1(0, 0, info1), + _lInfo2(0, 1, info2), + _lCursor(0, 4, "=>"), + _fItem1(3, 2, 14), + _fItem2(3, 3, 14), + _fItem3(3, 4, 14), + _fItem4(3, 5, 14), + _fItem5(3, 6, 14), + _items(items) +{ + _size = _items.size(); + _selected = 0; +} + +LayoutScrollSelect::~LayoutScrollSelect() {} + +void LayoutScrollSelect::display() { + clear(); + startUpdate(); + + writeLabel(_lSw1); + writeLabel(_lSw2); + writeLabel(_lInfo1); + writeLabel(_lInfo2); + writeLabel(_lCursor); + + switch (_size) { + case 0: + // special case - no items + // (empty) + // (empty) + // => (empty) + // (empty) + // (empty) + break; + + case 1: + // special case - 1 item + // (empty) + // (empty) + // => item1 + // (empty) + // (empty) + writeField(_fItem3, _items[0]); + break; + + case 2: + // special case - 2 items + // (empty) + // (empty) + // => item1 + // item2 + // (empty) + writeField(_fItem3, _items[0]); + writeField(_fItem4, _items[1]); + break; + + case 3: + // special case - 3 items + // (empty) + // item3 + // => item1 + // item2 + // (empty) + writeField(_fItem2, _items[2]); + writeField(_fItem3, _items[0]); + writeField(_fItem4, _items[1]); + break; + + case 4: + // special case - 4 items + // item3 + // item4 + // => item1 + // item2 + // (empty) + writeField(_fItem1, _items[2]); + writeField(_fItem2, _items[3]); + writeField(_fItem3, _items[0]); + writeField(_fItem4, _items[1]); + break; + + default: + // this is the generic case - should handle lists of 5+ items correctly + // item4 item6 item9 + // item5 item7 item10 + // => item1 => item1 => item1 + // item2 item2 item2 + // item3 item3 item3 + writeField(_fItem1, _items[_size - 2]); + writeField(_fItem2, _items[_size - 1]); + writeField(_fItem3, _items[0]); + writeField(_fItem4, _items[1]); + writeField(_fItem5, _items[2]); + break; + } + + endUpdate(); +} + +void LayoutScrollSelect::scroll() { + size_t index; + + switch (_size) { + case 0: + case 1: + // nothing to scroll + break; + + case 2: + // special case - 2 items + // (empty) -> (empty) + // (empty) -> (empty) + // => item1 -> => item2 + // item2 -> item1 + // (empty) -> (empty) + + index = _selected; + // keep selected item up to date + increment(_selected); + + startUpdate(); + // previously selected item moves down to field4 + writeField(_fItem4, _items[index]); + increment(index); + // other item moves up to field3 + writeField(_fItem3, _items[index]); + endUpdate(); + break; + + case 3: + // special case - 3 items + // (empty) -> (empty) + // item3 -> item1 + // => item1 -> => item2 + // item2 -> item3 + // (empty) -> (empty) + + index = _selected; + // keep selected item up to date + increment(_selected); + + startUpdate(); + // previously selected item moves up to field2 + writeField(_fItem2, _items[index]); + increment(index); + // new selected item moves up to field3 + writeField(_fItem3, _items[index]); + increment(index); + // item from field2 moves down to field4 + writeField(_fItem4, _items[index]); + endUpdate(); + break; + + case 4: + // special case - 4 items + // item3 -> item4 + // item4 -> item1 + // => item1 -> => item2 + // item2 -> item3 + // (empty) -> (empty) + + index = _selected; + // keep selected item up to date + increment(_selected); + + startUpdate(); + // previously selected item moves up to field2 + writeField(_fItem2, _items[index]); + increment(index); + // new selected item moves up to field3 + writeField(_fItem3, _items[index]); + increment(index); + // item from field1 moves down to field4 + writeField(_fItem4, _items[index]); + increment(index); + // item from field2 moves up to field1 + writeField(_fItem1, _items[index]); + endUpdate(); + break; + + default: + // this is the generic case - should handle lists of 5+ items correctly + // item4 -> item5 item6 -> item7 + // item5 -> item1 item7 -> item1 + // => item1 -> => item2 => item1 -> => item2 + // item2 -> item3 item2 -> item3 + // item3 -> item4 item3 -> item4 + + index = _selected; + // keep selected item up to date + increment(_selected); + + startUpdate(); + decrement(index); + // item from field2 moves up to field1 + writeField(_fItem1, _items[index]); + increment(index); + // previously selected item moves up to field2 + writeField(_fItem2, _items[index]); + increment(index); + // new selected item moves up to field3 + writeField(_fItem3, _items[index]); + increment(index); + // item from field5 moves up to field4 + writeField(_fItem4, _items[index]); + increment(index); + // next item (from field1 or off screen) moves up to field5 + writeField(_fItem5, _items[index]); + endUpdate(); + break; + } +} + +std::string LayoutScrollSelect::select() { + std::string selected = ""; + if (_size > 0) + selected = _items[_selected]; + + return selected; +} + +void LayoutScrollSelect::increment(size_t& index) { + if (_size > 1) { + index++; + index %= _size; + } +} + +void LayoutScrollSelect::decrement(size_t& index) { + if (_size > 1) { + if (index == 0) + index = _size - 1; + else + index--; + } +} diff --git a/Layout/LayoutScrollSelect.h b/Layout/LayoutScrollSelect.h new file mode 100644 index 0000000..4811ae5 --- /dev/null +++ b/Layout/LayoutScrollSelect.h @@ -0,0 +1,40 @@ +#ifndef __LAYOUTSCROLLSELECT_H__ +#define __LAYOUTSCROLLSELECT_H__ + +#include "Layout.h" +#include <vector> + +typedef std::vector<std::string> Items; + +class LayoutScrollSelect : public Layout { + public: + LayoutScrollSelect(DOGS102* lcd, Items items, std::string info1 = "", std::string info2 = ""); + ~LayoutScrollSelect(); + + void display(); + + void scroll(); + std::string select(); + + private: + void increment(size_t& index); + void decrement(size_t& index); + + Label _lSw1; + Label _lSw2; + Label _lInfo1; + Label _lInfo2; + Label _lCursor; + + Field _fItem1; + Field _fItem2; + Field _fItem3; + Field _fItem4; + Field _fItem5; + + Items _items; + size_t _selected; + size_t _size; +}; + +#endif diff --git a/Layout/LayoutSingleHelp.cpp b/Layout/LayoutSingleHelp.cpp new file mode 100644 index 0000000..82c4270 --- /dev/null +++ b/Layout/LayoutSingleHelp.cpp @@ -0,0 +1,26 @@ +#include "LayoutSingleHelp.h" + +LayoutSingleHelp::LayoutSingleHelp(DOGS102* lcd) + : Layout(lcd), + _lMode(0, 0, "Survey Single"), + _lIns1(0, 4, "Hold SW1 any time"), + _lIns2(0, 5, "for Main Menu"), + _lSw1(11, 7, "DR/PWR"), + _lSw2(0, 7, "Survey") +{} + +LayoutSingleHelp::~LayoutSingleHelp() {} + +void LayoutSingleHelp::display() { + clear(); + startUpdate(); + + writeLabel(_lMode); + writeLabel(_lIns1); + writeLabel(_lIns2); + writeLabel(_lSw1); + writeLabel(_lSw2); + + endUpdate(); +} + diff --git a/Layout/LayoutSingleHelp.h b/Layout/LayoutSingleHelp.h new file mode 100644 index 0000000..421bc1c --- /dev/null +++ b/Layout/LayoutSingleHelp.h @@ -0,0 +1,21 @@ +#ifndef __LAYOUTSINGLEHELP_H__ +#define __LAYOUTSINGLEHELP_H__ + +#include "Layout.h" + +class LayoutSingleHelp : public Layout { + public: + LayoutSingleHelp(DOGS102* lcd); + ~LayoutSingleHelp(); + + void display(); + + private: + Label _lMode; + Label _lIns1; + Label _lIns2; + Label _lSw1; + Label _lSw2; +}; + +#endif diff --git a/Layout/LayoutStartup.cpp b/Layout/LayoutStartup.cpp index c005b2f..850ea50 100644 --- a/Layout/LayoutStartup.cpp +++ b/Layout/LayoutStartup.cpp @@ -11,15 +11,19 @@ LayoutStartup::LayoutStartup(DOGS102* lcd) _iLogo(0, 0, MultiTech_Logo) {} +LayoutStartup::~LayoutStartup() {} + void LayoutStartup::display() { + std::string version = MTDOT_BOX_VERSION; + clear(); startUpdate(); - writeImage(_iLogo._col, _iLogo._row, _iLogo._bmp); - writeField(_lName._col, _lName._row, _lName._value); - writeField(_lInfo._col, _lInfo._row, _lInfo._value); - writeField(_lVersion._col, _lVersion._row, _lVersion._value); - writeField(_fVersion._col, _fVersion._row, MTDOT_BOX_VERSION, sizeof(MTDOT_BOX_VERSION)); + writeImage(_iLogo); + writeLabel(_lName); + writeLabel(_lInfo); + writeLabel(_lVersion); + writeField(_fVersion, version); endUpdate(); } diff --git a/Layout/LayoutSweepHelp.cpp b/Layout/LayoutSweepHelp.cpp new file mode 100644 index 0000000..eb40013 --- /dev/null +++ b/Layout/LayoutSweepHelp.cpp @@ -0,0 +1,26 @@ +#include "LayoutSweepHelp.h" + +LayoutSweepHelp::LayoutSweepHelp(DOGS102* lcd) + : Layout(lcd), + _lMode(0, 0, "Survey Sweep"), + _lIns1(0, 4, "Hold SW1 any time"), + _lIns2(0, 5, "for Main Menu"), + _lSw1(11, 7, "Cancel"), + _lSw2(0, 7, "Sweep") +{} + +LayoutSweepHelp::~LayoutSweepHelp() {} + +void LayoutSweepHelp::display() { + clear(); + startUpdate(); + + writeLabel(_lMode); + writeLabel(_lIns1); + writeLabel(_lIns2); + writeLabel(_lSw1); + writeLabel(_lSw2); + + endUpdate(); +} + diff --git a/Layout/LayoutSweepHelp.h b/Layout/LayoutSweepHelp.h new file mode 100644 index 0000000..0ec0e45 --- /dev/null +++ b/Layout/LayoutSweepHelp.h @@ -0,0 +1,21 @@ +#ifndef __LAYOUTSWEEPHELP_H__ +#define __LAYOUTSWEEPHELP_H__ + +#include "Layout.h" + +class LayoutSweepHelp : public Layout { + public: + LayoutSweepHelp(DOGS102* lcd); + ~LayoutSweepHelp(); + + void display(); + + private: + Label _lMode; + Label _lIns1; + Label _lIns2; + Label _lSw1; + Label _lSw2; +}; + +#endif |
