-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeController.cpp
34 lines (26 loc) · 980 Bytes
/
TimeController.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
#include "TimeController.h"
void TimeController::init(String timeZoneName) {
Serial.println(F("[NTP] Initializing time server connection..."));
setDebug(DEBUG);
waitForSync();
_timeZone.setLocation(timeZoneName); // https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Serial.print(F("[NTP] Current local time: "));
Serial.println(_timeZone.dateTime());
}
String TimeController::getCurrentDate() {
return _timeZone.dateTime("Y.m.d");
}
String TimeController::getCurrentTime() {
return _timeZone.dateTime("H:i");
}
String TimeController::getCurrentDayOfWeek() {
return _timeZone.dateTime("l");
}
uint8_t TimeController::setEvent(void (*function)()) {
Serial.println(F("[NTP] Setting event."));
time_t alarmTime = makeTime(_timeZone.hour(), _timeZone.minute()+1, _timeZone.second(), _timeZone.day(), _timeZone.month(), _timeZone.year());
return _timeZone.setEvent(function, alarmTime);
}
void TimeController::processEvents() {
events();
}