-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hal.cpp
72 lines (58 loc) · 1.51 KB
/
hal.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
#include "hal.h"
ESP32Time rtc(0);
void setupPeripherals() {
pinMode(LOAD_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BLUE_LED_PIN, OUTPUT);
EEPROM.begin(EEPROM_SIZE);
rtc.setTime();
}
void setupSerial() {
Serial.begin(SERIAL_RATE);
}
uint32_t getTimeInSeconds() {
return rtc.getEpoch();
}
void blinkLED(int numberOfBlinks, int LEDPin) {
int i;
for (i = 0; i < numberOfBlinks; i++) {
digitalWrite(LEDPin, HIGH);
// Wait for 1 second
delay(LED_BLINK_TIME);
// Turn the LED off
digitalWrite(LEDPin, LOW);
// Wait for 1 second
delay(LED_BLINK_TIME);
}
}
void blinkRedLED(int numberOfBlinks) {
blinkLED(numberOfBlinks, RED_LED_PIN);
}
void blinkGreenLED(int numberOfBlinks) {
blinkLED(numberOfBlinks, GREEN_LED_PIN);
}
void blinkBlueLED(int numberOfBlinks) {
blinkLED(numberOfBlinks, BLUE_LED_PIN);
}
void switchLoad(bool active) {
if (active) {
digitalWrite(LOAD_PIN, HIGH);
} else {
digitalWrite(LOAD_PIN, LOW);
}
}
// ----- Metrics collection functions ----- //
// For this example it uses random data, change it for actual measurements
uint8_t getNumberOfDaysOfMetrics() {
return random(1, 31);
}
float getPowerGenerated(uint8_t day) {
return random(1000, 6000) / 100.0f;
}
float getHoursOfLighting(uint8_t day) {
return random(100, 800) / 100.0f;
}
float getAverageBatteryVoltage(uint8_t day) {
return random(1200, 1440) / 100.0f;
}