-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cpp
197 lines (154 loc) · 4.45 KB
/
Settings.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
#include "Settings.h"
#define MAX_MENU_ITEMS 5
#define MENU_RESET_MAXMIN 0
#define MENU_TEMP_UNITS 1
#define MENU_ALTITUDE 2
#define MENU_WIFI 3
#define MENU_EXIT 4
Settings::Settings(Tiny_SH1106 *lcd, Button *leftButton, Button *middleButton, Button *rightButton, Stats *stats, TheWifi *network)
{
_lcd = lcd;
_leftButton = leftButton;
_middleButton = middleButton;
_rightButton = rightButton;
_stats = stats;
_network = network;
}
void Settings::UpdateSettingsUI()
{
bool wasExitSelected = false;
_lcd->clearDisplay();
_lcd->setTextSize(1);
_lcd->setTextColor(WHITE);
_lcd->setCursor(10,0);
_lcd->print(F("Configuration Menu"));
_lcd->drawFastHLine(1, 10, 127, WHITE);
_lcd->display();
int firstItem = 0;
int selectedItem = 0;
DrawMenu(firstItem, selectedItem);
while (!wasExitSelected)
{
uint8_t middle = _middleButton->State();
if ((middle == BUTTON_CLICKED || middle == BUTTON_HELD) && selectedItem == MENU_EXIT)
{
wasExitSelected = true;
continue;
}
if (middle == BUTTON_HELD)
{
Serial.println("SETTING MIDDLE");
ChangeSetting(selectedItem);
DrawMenu(firstItem, selectedItem);
}
if (_rightButton->State() == BUTTON_CLICKED && selectedItem < MAX_MENU_ITEMS - 1)
{
selectedItem++;
DrawMenu(firstItem, selectedItem);
}
if (_leftButton->State() == BUTTON_CLICKED && selectedItem > 0)
{
selectedItem--;
DrawMenu(firstItem, selectedItem);
}
}
_lcd->clearDisplay();
}
void Settings::DrawMenu(int firstItem, int selectedItem)
{
int currentItem = firstItem;
int y = 14;
while (currentItem < MAX_MENU_ITEMS)
{
uint16_t background = currentItem == selectedItem ? WHITE : BLACK;
uint16_t foreground = currentItem == selectedItem ? BLACK : WHITE;
_lcd->fillRect(1, y, 127, 10, background);
_lcd->setTextColor(foreground);
_lcd->setCursor(4,y+1);
switch(currentItem)
{
case MENU_RESET_MAXMIN:
_lcd->print(F("Reset Max / Min"));
break;
case MENU_TEMP_UNITS:
_lcd->print(F("Units: Centigrade"));
break;
case MENU_ALTITUDE:
_lcd->print(F("Altitude"));
break;
case MENU_WIFI:
_lcd->print(F("WIFI"));
break;
case MENU_EXIT:
_lcd->print(F("Exit"));
break;
}
y += 10;
currentItem++;
}
_lcd->display();
}
void Settings::ChangeSetting(int selectedItem)
{
_lcd->fillRect(1, 11, 127, 53, BLACK);
switch(selectedItem)
{
case MENU_RESET_MAXMIN: ResetMaxMin(); break;
case MENU_WIFI: MenuWifi(); break;
/*
case MENU_TEMP_UNITS
_lcd->print(F("Units: Centigrade"));
break;
case MENU_ALTITUDE:
_lcd->print(F("Altitude"));
break;
case MENU_WIFI:
_lcd->print(F("WIFI"));
break;
case MENU_EXIT:
_lcd->print(F("Exit"));
break;
*/
}
_lcd->fillRect(1, 11, 127, 53, BLACK);
}
void Settings::ResetMaxMin()
{
_stats->ResetMaxMin();
_lcd->setTextColor(WHITE);
_lcd->setCursor(10,30);
_lcd->print("Max amd min values");
_lcd->setCursor(19,40);
_lcd->print("have been reset");
_lcd->display();
Interval shortDelay(10000, false);
while (!shortDelay.Ready())
if (_middleButton->State() == BUTTON_CLICKED)
break;
}
void Settings::MenuWifi()
{
_lcd->setTextColor(WHITE);
Interval every(1000, false);
while (true)
{
if (_middleButton->State() == BUTTON_CLICKED)
break;
if (!every.Ready())
continue;
_lcd->fillRect(1, 11, 127, 53, BLACK);
_lcd->setCursor(1, 14);
_lcd->print("Status:");
_lcd->print(_network->GetStatus());
_lcd->setCursor(1,24);
_lcd->print("SSID:");
_lcd->print(_network->GetSSID());
_lcd->setCursor(1,34);
_lcd->print("RSSI:");
_lcd->print(_network->GetRSSI());
_lcd->setCursor(1,44);
_lcd->print("IP:");
_lcd->print(_network->GetIP());
_lcd->display();
}
}