diff --git a/ubitx_iop/menu.h b/ubitx_iop/menu.h index 3d3bcb5..57773a2 100644 --- a/ubitx_iop/menu.h +++ b/ubitx_iop/menu.h @@ -13,8 +13,8 @@ extern SpeechCompressor speechCompressor; // This should be somewhere else. // 16 characters on display -#define MAX_TEXT_LEN 16 -#define MENU_SELECTED_CHAR '>' +const int MAX_TEXT_LEN = 16; +const char MENU_SELECTED_CHAR = '>'; const char blankLine[17] = " "; @@ -29,25 +29,89 @@ class MenuItem { virtual MenuItem* prev() = 0; virtual MenuItem* next() = 0; }; -/* + +//====================================================================== +// ListMenu +//====================================================================== + +const int MAX_LISTMENU_TEXT_LEN = 15; + class ListMenu : public MenuItem { public: - ListMenu(const char* title, std::initializer_list items) { - _items = new MenuItem*[items.size()]; - } - virtual ~MenuItem() { - delete _items; - } - virtual void update() { - //sprintf(_text, " + ListMenu(const char* text, std::initializer_list items): + _length(items.size()), _current(0), _dirty(true) + { + char temp[MAX_LISTMENU_TEXT_LEN]; + strncpy(temp, text, MAX_LISTMENU_TEXT_LEN); + temp[MAX_LISTMENU_TEXT_LEN] = '\0'; + + _items = new MenuItem*[_length]; + + int count = 0; + for (auto element : items) { + _items[count] = element; + count++; + } + + sprintf(_text, "%c%s", MENU_SELECTED_CHAR, temp); } + virtual ~ListMenu() { + delete [] _items; + } + + virtual void update() + { + if (_dirty) { + sendIOPMenuDisplay(_text); + _dirty = false; + } + } + + virtual MenuItem* select() + { + _dirty = true; + return _items[_current]; + } + + virtual MenuItem* altSelect() + { + _dirty = true; + return this; + } + + virtual MenuItem* exit() + { + _dirty = true; + return NULL; + } + + virtual MenuItem* prev() + { + if (--_current < 0) { + _current += _length; + } + _dirty = true; + return this; + } + + virtual MenuItem* next() + { + _current = ++_current % _length; + _dirty = true; + return this; + } + private: - + bool _dirty; MenuItem** _items; - char _text[MAX_TEXT_LEN+1]; + int _length; + int _current; + char _text[MAX_LISTMENU_TEXT_LEN+1]; }; -*/ + +//====================================================================== + const char modeID[] = {'s', 'S', 'c', 'C', 'd', 'D', 't', 'T'}; const char* const filterID[NUM_RIG_MODES][NUM_RX_FILTERS] = { {"2.8", "2.4", "1.8"}, // LSB