-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWifiNetworks.cpp
72 lines (53 loc) · 1.3 KB
/
WifiNetworks.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
/*
WifiNetworks.cpp - Handle found wifi networks
Saul bertuccio 14 feb 2017
Released into the public domain.
*/
#include "Arduino.h"
#include "WifiNetworks.h"
WifiNetworks::WifiNetworks(int num )
: num(num), curr(0) {
if (num > 0)
nets = new WifiNetworks::Nets[num];
}
WifiNetworks::~WifiNetworks() {
delete [] nets;
}
int WifiNetworks::netNum() {
return curr;
}
String WifiNetworks::getName(int i) { return nets[i].nname; }
int WifiNetworks::getProtection(int i) { return nets[i].protection; }
long int WifiNetworks::getQuality(int i) { return nets[i].quality; }
void WifiNetworks::append(String nname, int protection, long int quality) {
if (curr > num)
return;
int pos = getPosition(nname);
if (pos == -1)
return;
if (pos < curr)
for (int i = curr; i > pos; i--) {
nets[i].nname = nets[i-1].nname;
nets[i].protection = nets[i-1].protection;
nets[i].quality = nets[i-1].quality;
}
++curr;
nets[pos].nname = nname;
nets[pos].protection = protection;
nets[pos].quality = quality;
}
int WifiNetworks::getPosition(String nname) {
nname.toLowerCase();
String tmp;
int i = 0;
while (i < curr) {
tmp = nets[i].nname;
tmp.toLowerCase();
if (tmp == nname)
return -1;
if (tmp > nname)
return i;
i++;
}
return i;
}