-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ino
83 lines (74 loc) · 1.96 KB
/
helpers.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
void handleDelay(int howLong) {
yield();
if (howLong < 0)
return;
unsigned int startTime = millis();
while (timeDiffNow(startTime) < howLong) {
server.handleClient();
if ((deviceMode == 1 || deviceMode == 2) && useMQTT)
psClient.loop();
}
} // end handleDelay()
void printStars(const char* input) {
for (int i = 0; i < strlen(input); i++)
Serial.print(F("*"));
} // end printStars()
char* generateHostName() {
char lastThree[11] = "ESP-";
byte temp, mac[6];
WiFi.macAddress(mac);
for (int i = 3; i < 6; i++) {
temp = mac[i] / 16;
if (temp > 9)
lastThree[2 * i - 2] = temp + 55;
else
lastThree[2 * i - 2] = temp + 48;
temp = mac[i] % 16;
if (temp > 9)
lastThree[2 * i - 1] = temp + 55;
else
lastThree[2 * i - 1] = temp + 48;
}
lastThree[10] = 0;
Serial.print(F("Generated: "));
Serial.print(lastThree);
Serial.println(F(" from device MAC ID."));
return lastThree;
} // end sixMAC()
long unsigned int timeDiffNow(long unsigned int a) {
return timeDiff(a, millis());
} // end timeDiffNow
long unsigned int timeDiff(long unsigned int a, long unsigned int b) {
if (a > b)
return a - b;
else
return b - a;
} // end timeDiff()
void floatHelper(float input, char* output) {
char floaters[3] = "";
int timesHundred = input * 100;
itoa(timesHundred / 100, output, 10);
strcat(output, ".");
itoa(timesHundred % 100, floaters, 10);
strcat(output, floaters);
} // void floatHelper()
void slideFloat(float arr[], int arrSize) {
for (int i = arrSize - 1; i > 0; i--)
arr[i] = arr[i - 1];
} // end slideDown()
float averageFloat(float arr[], int arrSize) {
float average = 0;
int count = 0;
for (int i = 0; i < arrSize; i++)
if (arr[i] != -500) {
average += arr[i];
count++;
}
if (count == 0)
return -500;
return average / count;
} // end average()
void clearBuffer() {
for (int i = 0; i < BUFFSIZE; i++)
buffer[i] = 0;
} // end clearBuffer()