208 lines
2.9 KiB
C++
208 lines
2.9 KiB
C++
#include "Menu.h"
|
|
|
|
Menu::Menu() {
|
|
type = MENU_MAIN;
|
|
state = STATE_BROWSING;
|
|
|
|
index = 0;
|
|
|
|
targetTemperature = 25;
|
|
targetHumidity = 40;
|
|
}
|
|
|
|
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() {
|
|
|
|
// EDIT MODE
|
|
if (state == STATE_EDITING) {
|
|
|
|
// Temperature
|
|
if (type == MENU_SETUP && index == 0) {
|
|
|
|
targetTemperature++;
|
|
|
|
if (targetTemperature > 60) {
|
|
targetTemperature = 60;
|
|
}
|
|
}
|
|
|
|
// Humidity
|
|
else if (type == MENU_SETUP && index == 1) {
|
|
|
|
targetHumidity++;
|
|
|
|
if (targetHumidity > 100) {
|
|
targetHumidity = 100;
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// BROWSING MODE
|
|
index = (index + 1) % getSize(type);
|
|
}
|
|
|
|
void Menu::prev() {
|
|
|
|
// EDIT MODE
|
|
if (state == STATE_EDITING) {
|
|
|
|
// Temperature
|
|
if (type == MENU_SETUP && index == 0) {
|
|
|
|
targetTemperature--;
|
|
|
|
if (targetTemperature < 0) {
|
|
targetTemperature = 0;
|
|
}
|
|
}
|
|
|
|
// Humidity
|
|
else if (type == MENU_SETUP && index == 1) {
|
|
|
|
targetHumidity--;
|
|
|
|
if (targetHumidity < 0) {
|
|
targetHumidity = 0;
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// BROWSING MODE
|
|
index--;
|
|
|
|
if (index < 0) {
|
|
index = getSize(type) - 1;
|
|
}
|
|
}
|
|
|
|
void Menu::enter() {
|
|
|
|
// EXIT EDIT MODE
|
|
if (state == STATE_EDITING) {
|
|
state = STATE_BROWSING;
|
|
return;
|
|
}
|
|
|
|
// MAIN MENU
|
|
if (type == MENU_MAIN) {
|
|
|
|
switch (index) {
|
|
|
|
case 1:
|
|
type = MENU_SETUP;
|
|
index = 0;
|
|
break;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// SETUP MENU
|
|
if (type == MENU_SETUP) {
|
|
|
|
switch (index) {
|
|
|
|
// Temperature
|
|
case 0:
|
|
state = STATE_EDITING;
|
|
break;
|
|
|
|
// Humidity
|
|
case 1:
|
|
state = STATE_EDITING;
|
|
break;
|
|
|
|
// Back
|
|
case 2:
|
|
back();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Menu::back() {
|
|
|
|
// EXIT EDIT MODE
|
|
if (state == STATE_EDITING) {
|
|
state = STATE_BROWSING;
|
|
return;
|
|
}
|
|
|
|
// RETURN TO MAIN MENU
|
|
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;
|
|
}
|
|
|
|
bool Menu::isEditing() {
|
|
return state == STATE_EDITING;
|
|
}
|
|
|
|
int Menu::getTargetTemperature() {
|
|
return targetTemperature;
|
|
}
|
|
|
|
int Menu::getTargetHumidity() {
|
|
return targetHumidity;
|
|
} |