-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathomower-rtc.cpp
More file actions
46 lines (40 loc) · 1.08 KB
/
Copy pathomower-rtc.cpp
File metadata and controls
46 lines (40 loc) · 1.08 KB
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
// RTC module for OMower (internal RTC in ATSAM3X8E)
// $Id$
#include <omower-defs.h>
#include <omower-rtc.h>
#include <omower-debug.h>
// Hardware init
_hwstatus rtc::begin() {
debug(L_DEBUG, (char *) F("rtc::begin\n"));
#ifdef NO_RTC_CRYSTAL
myRTC = new RTCDue(RC);
#else
myRTC = new RTCDue(XTAL);
#endif
myRTC->begin();
readRTC();
return _hwstatus::ONLINE;
} // _hwstatus rtc::begin()
_status rtc::readRTC() {
year = myRTC->getYear();
month = myRTC->getMonth();
day = myRTC->getDay();
dayweek = myRTC->getDayofWeek();
hour = myRTC->getHours();
minute = myRTC->getMinutes();
second = myRTC->getSeconds();
return _status::NOERR;
} // _status rtc::readRTC()
uint32_t rtc::getUnixTime() {
return myRTC->unixtime();
} // uint32_t rtc::getUnixTime()
void rtc::setUnixTime(uint32_t unixtime) {
myRTC->setClock(unixtime);
readRTC();
} // void rtc::setUnixTime(uint32_t unixtime)
_status rtc::saveRTC() {
myRTC->setDate(day, month, year);
myRTC->setTime(hour, minute, second);
dayweek = myRTC->getDayofWeek();
return _status::NOERR;
} // _status rtc::saveRTC()