Complete rewrite of Application
This commit is contained in:
72
Menu.cpp
Normal file
72
Menu.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user