72 lines
1.2 KiB
C++
72 lines
1.2 KiB
C++
#include "Menu.h"
|
|
|
|
Menu::Menu() {
|
|
type = MENU_MAIN;
|
|
index = 0;
|
|
}
|
|
|
|
int Menu::getSize(MenuType type) {
|
|
switch (type) {
|
|
case MENU_MAIN: return MAIN_SIZE;
|
|
case MENU_SETUP: return SETUP_SIZE;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
const char* Menu::getItem(MenuType type, int index) {
|
|
switch (type) {
|
|
case MENU_MAIN:
|
|
switch (index) {
|
|
case 0: return "Start";
|
|
case 1: return "Setup";
|
|
case 2: return "Version";
|
|
}
|
|
break;
|
|
|
|
case MENU_SETUP:
|
|
switch (index) {
|
|
case 0: return "Temperature";
|
|
case 1: return "Humidity";
|
|
case 2: return "Back";
|
|
}
|
|
break;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
void Menu::next() {
|
|
index = (index + 1) % getSize(type);
|
|
}
|
|
|
|
void Menu::prev() {
|
|
index--;
|
|
if (index < 0) index = getSize(type) - 1;
|
|
}
|
|
|
|
void Menu::enter() {
|
|
if (type == MENU_MAIN) {
|
|
if (index == 1) type = MENU_SETUP;
|
|
}
|
|
index = 0;
|
|
}
|
|
|
|
void Menu::back() {
|
|
if (type != MENU_MAIN) {
|
|
type = MENU_MAIN;
|
|
index = 0;
|
|
}
|
|
}
|
|
|
|
const char* Menu::getCurrent() {
|
|
return getItem(type, index);
|
|
}
|
|
|
|
const char* Menu::getNext() {
|
|
int nextIndex = (index + 1) % getSize(type);
|
|
return getItem(type, nextIndex);
|
|
}
|
|
|
|
MenuType Menu::getType() {
|
|
return type;
|
|
} |