Set humidity and temperature with buttons
This commit is contained in:
148
Menu.cpp
148
Menu.cpp
@@ -2,33 +2,50 @@
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -36,22 +53,127 @@ const char* Menu::getItem(MenuType type, int index) {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (index < 0) {
|
||||
index = getSize(type) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::enter() {
|
||||
if (type == MENU_MAIN) {
|
||||
if (index == 1) type = MENU_SETUP;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
index = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -63,10 +185,24 @@ const char* Menu::getCurrent() {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user