-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.cpp
224 lines (206 loc) · 4.51 KB
/
Menu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
Copyright 2017 Evandro Pires Alves
This file is part of Frigorífico.
Frigorífico is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Frigorífico is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Frigorífico. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Menu.h"
Menu::Menu()
{
// init menus
menus[0].text = "0 Informacoes";
menus[0].id = MENU_INFO;
menus[1].text = "1 Frio";
menus[1].id = MENU_SENSOR1;
menus[2].text = "2 Gelo";
menus[2].id = MENU_SENSOR2;
menus[3].text = "3 Ambiente";
menus[3].id = MENU_SENSOR3;
menus[4].text = "* RESET";
menus[4].id = MENU_RESET;
// init LCD
lcd = new LiquidCrystal_I2C(0x3F,16,2);
lcd->init();
if (lcd_backlight) lcd->backlight(); else lcd->noBacklight();
lcd->createChar(0, temp_low);
lcd->createChar(1, temp_high);
// init NTCs
ntc1 = new Sensor(0, "Frio");
ntc2 = new Sensor(1, "Gelo");
ntc3 = new Sensor(2, "Ambiente");
}
void Menu::home() {
lcd->clear();
lcd->backlight();
lcd->print(" MAIN MENU");
lcd->setCursor(0,1);
lcd->print(menus[menu_current].text);
}
void Menu::next()
{
menu_current++;
if (menu_current >= MENU_ITEMS) {
menu_current = 0;
}
lcd->clear();
lcd->print(" MAIN MENU");
lcd->setCursor(0,1);
lcd->print(menus[menu_current].text);
}
void Menu::prev()
{
menu_current--;
if (menu_current < 0) {
menu_current = MENU_ITEMS - 1;
}
lcd->clear();
lcd->print(" MAIN MENU");
lcd->setCursor(0,1);
lcd->print(menus[menu_current].text);
}
void Menu::clear(byte line)
{
for (byte c = 0; c < 16; c++) {
lcd->setCursor(c, line);
lcd->print(" ");
}
}
void Menu::exec()
{
switch (menus[menu_selected].id)
{
case MENU_SENSOR1:
showSensor(ntc1);
break;
case MENU_SENSOR2:
showSensor(ntc2);
break;
case MENU_SENSOR3:
showSensor(ntc3);
break;
case MENU_RESET:
doReset();
break;
}
}
void Menu::showSensor(Sensor *sensor) {
lcd->clear();
lcd->print(sensor->name);
lcd->setCursor(12,0);
lcd->print(sensor->read());
lcd->setCursor(0,1);
lcd->write(byte(0));
lcd->print(" ");
lcd->print(sensor->min);
lcd->setCursor(7,1);
lcd->write(byte(1));
lcd->print(" ");
lcd->print(sensor->max);
}
void Menu::doReset() {
lcd->clear();
lcd->print("Reset de Mins");
lcd->setCursor(0,1);
lcd->print("e Maximos...");
ntc1->reset();
ntc2->reset();
ntc3->reset();
lcd->clear();
lcd->print("Terminado!");
}
void Menu::storeMin() {
switch (menu_current)
{
case MENU_SENSOR1:
ntc1->storeMin(ntc1->read());
break;
case MENU_SENSOR2:
ntc2->storeMin(ntc2->read());
break;
case MENU_SENSOR3:
ntc3->storeMin(ntc3->read());
break;
}
exec();
}
void Menu::storeMax() {
switch (menu_current)
{
case MENU_SENSOR1:
ntc1->storeMax(ntc1->read());
break;
case MENU_SENSOR2:
ntc2->storeMax(ntc2->read());
break;
case MENU_SENSOR3:
ntc3->storeMax(ntc3->read());
break;
}
exec();
}
void Menu::decode(decode_results result)
{
switch (result.value)
{
case REMOTE_ON:
if (lcd_backlight) {
lcd->clear();
lcd->noBacklight();
lcd->noDisplay();
lcd_backlight = false;
} else {
lcd->display();
home();
lcd_backlight = true;
}
break;
case REMOTE_NEXT:
next();
break;
case REMOTE_PREV:
prev();
break;
case REMOTE_PLAY:
menu_selected = menu_current;
exec();
break;
case REMOTE_SHUF:
menu_selected = -1;
home();
break;
case REMOTE_LESS:
storeMin();
break;
case REMOTE_MORE:
storeMax();
break;
case REMOTE_1:
menu_current = 1;
menu_selected = 1;
exec();
break;
case REMOTE_2:
menu_current = 2;
menu_selected = 2;
exec();
break;
case REMOTE_3:
menu_current = 3;
menu_selected = 3;
exec();
break;
case 0xFFFFFFFF:
// received remote signal unknown
break;
default:
break;
}
}