forked from filmote/WiFiManagerGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess_points.ino
314 lines (212 loc) · 9 KB
/
access_points.ino
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// -------------------------------------------------------------------------------------------------------
// Retrieve and render the detected access points.
int init_access_points() {
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS)
Serial.println(" ");
Serial.println("init_access_points()");
Serial.println(" Start scan");
#endif
// WiFi.scanNetworks will return the number of networks found ..
renderAccessPoints_Retrieving();
int n = WiFi.scanNetworks();
// Forece the 'No Access Points found' test case?
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS__NO_AP_FOUND__TEST_CASE)
n = 0;
#endif
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS)
Serial.println(" Scan done");
#endif
if (n == 0) {
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS)
Serial.println(" ** No networks found !");
#endif
accessPoint_highlightRow = ACCESSPOINT_ROW_MENU;
}
else {
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS)
Serial.print(" ");
Serial.print(n);
Serial.println(" networks found.");
for (int i = 0; i < n; i++) {
Serial.print(" ");
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
delay(10);
}
#endif
accessPoint_count = (n > ACCESSPOINT_MAX ? ACCESSPOINT_MAX : n);
hasAPNameBeenVerified = true;
for (int i = 0; i <= accessPoint_count; i++) {
accessPoints[i] = WiFi.SSID(i);
// Should the current SSID be highlighted?
if (ssid != "" && WiFi.SSID(i) == ssid) {
accessPoint_highlightRow = i;
// Make sure the highlighted row is visible ..
if (accessPoint_highlightRow == 0) { // highlighted row is the top one.
accessPoint_topRow = 0;
}
else if (accessPoint_highlightRow < accessPoint_count - ACCESSPOINT_ROWS_VISIBLE) { // highlighed row is not the top row and is not on the last 'page', set top to highlighed row minus one.
accessPoint_topRow = accessPoint_highlightRow - 1;
}
else { // highlighed row is on the last 'page', ensure that the top row is set to display ACCESSPOINT_ROWS_VISIBLE rows.
accessPoint_topRow = accessPoint_count - ACCESSPOINT_ROWS_VISIBLE;
}
}
}
}
renderAccessPoints();
// Change modes and wait for user input ..
status = STATUS_ACCESSPOINTS_LOOP;
return loop_access_points();
}
// -------------------------------------------------------------------------------------------------------
// Process user input ..
//
int loop_access_points() {
while (status == STATUS_ACCESSPOINTS_LOOP) {
yield();
sensorValue = analogRead(A0);
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_SENSOR_VALUE)
if (sensorValue < DEBUG_ACCESSPOINTS_SENSOR_VALUE_THRESHOLD) { Serial.println(sensorValue); }
#endif
if (sensorValue > (BUTTON_3 - BUTTON_VARIANCE) && sensorValue < (BUTTON_3 + BUTTON_VARIANCE)) { status = loop_access_points_button3_Click(); }
if (sensorValue > (BUTTON_4 - BUTTON_VARIANCE) && sensorValue < (BUTTON_4 + BUTTON_VARIANCE)) { status = loop_access_points_button4_Click(); }
if (sensorValue > (BUTTON_5 - BUTTON_VARIANCE) && sensorValue < (BUTTON_5 + BUTTON_VARIANCE)) { status = loop_access_points_button5_Click(); }
yield();
}
return status;
}
// -------------------------------------------------------------------------------------------------------
// Up button clicked ..
//
int loop_access_points_button3_Click() {
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_INIT)
Serial.println(" ");
Serial.println("loop_access_points_button3_Click():");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
#endif
if (accessPoint_highlightRow == ACCESSPOINT_ROW_MENU) {
accessPoint_highlightRow = accessPoint_count - 1;
accessPoint_topRow = (accessPoint_count > ACCESSPOINT_ROWS_VISIBLE ? accessPoint_highlightRow - ACCESSPOINT_ROWS_VISIBLE + 1 : 0);
}
else if (accessPoint_highlightRow == 0) {
accessPoint_highlightRow = ACCESSPOINT_ROW_MENU;
accessPoint_topRow = 0;
}
else if (accessPoint_highlightRow > 0) {
accessPoint_highlightRow--;
if (accessPoint_highlightRow > 0) {
accessPoint_topRow = accessPoint_highlightRow - 1;
}
}
renderAccessPoints();
delay(100);
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_FINAL)
Serial.println(" -- exit values");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
Serial.println(" return = STATUS_ACCESSPOINTS_LOOP");
#endif
return STATUS_ACCESSPOINTS_LOOP;
}
// -------------------------------------------------------------------------------------------------------
// Down button clicked ..
//
int loop_access_points_button4_Click() {
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_INIT)
Serial.println(" ");
Serial.println("loop_access_points_button3_Click():");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
#endif
if (accessPoint_highlightRow == ACCESSPOINT_ROW_MENU) {
accessPoint_topRow = 0;
accessPoint_highlightRow = 0;
}
else if (accessPoint_highlightRow + 1 == accessPoint_count) {
accessPoint_highlightRow = ACCESSPOINT_ROW_MENU;
}
else if (accessPoint_highlightRow < accessPoint_count) {
accessPoint_highlightRow++;
if (accessPoint_highlightRow >= accessPoint_topRow + ACCESSPOINT_ROWS_VISIBLE) {
accessPoint_topRow++;
}
}
renderAccessPoints();
delay(100);
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_FINAL)
Serial.println(" -- exit values");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
Serial.println(" return = STATUS_ACCESSPOINTS_LOOP");
#endif
return STATUS_ACCESSPOINTS_LOOP;
}
// -------------------------------------------------------------------------------------------------------
// Select button clicked ..
//
int loop_access_points_button5_Click() {
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_INIT)
Serial.println(" ");
Serial.println("loop_access_points_button5_Click():");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
#endif
if (accessPoint_highlightRow == ACCESSPOINT_ROW_MENU) {
accessPoint_highlightRow = 0;
accessPoint_topRow = 0;
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_FINAL)
Serial.println(" -- exit values");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
Serial.println(" return = STATUS_ACCESSPOINTS_INIT");
#endif
return STATUS_ACCESSPOINTS_INIT;
}
else {
ssid = accessPoints[accessPoint_highlightRow];
accessPoint_highlightRow = 0;
accessPoint_topRow = 0;
#if defined(DEBUG) && defined(DEBUG_ACCESSPOINTS) && defined(DEBUG_ACCESSPOINTS_VALUES_FINAL)
Serial.print(" -- exit values");
Serial.print(" accessPoint_highlightRow = ");
Serial.println(accessPoint_highlightRow);
Serial.print(" accessPoint_topRow = ");
Serial.println(accessPoint_topRow);
Serial.print(" accessPoint_count = ");
Serial.println(accessPoint_count);
Serial.println(" return = STATUS_ENTERPASSWORD_INIT");
#endif
return STATUS_ENTERPASSWORD_INIT;
}
}