You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
1.5 KiB
102 lines
1.5 KiB
#include "watchos.h"
|
|
#include "Module_RTC.h"
|
|
|
|
#include <DS3232RTC.h>
|
|
// https://github.com/JChristensen/DS3232RTC
|
|
|
|
DS3232RTC RTC;
|
|
tmElements_t rtc_time;
|
|
|
|
|
|
Module_RTC::Module_RTC()
|
|
{
|
|
RTC.squareWave(SQWAVE_NONE);
|
|
RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0);
|
|
RTC.alarmInterrupt(ALARM_2, true);
|
|
RTC.alarmInterrupt(ALARM_1, false);
|
|
refresh();
|
|
}
|
|
|
|
void Module_RTC::initialize()
|
|
{
|
|
}
|
|
|
|
void Module_RTC::start()
|
|
{
|
|
}
|
|
|
|
void Module_RTC::suspend()
|
|
{
|
|
}
|
|
|
|
void Module_RTC::refresh()
|
|
{
|
|
byte read_result = RTC.read(rtc_time);
|
|
}
|
|
|
|
void Module_RTC::tick()
|
|
{
|
|
if (RTC.alarm(ALARM_2))
|
|
{
|
|
refresh();
|
|
watchos::kernel()->pushEvent(WATCHOS_MODULE_RTC, WATCHOS_EVENT_TYPE_RTC_MINUTE, rtc_time.Hour, rtc_time.Minute);
|
|
watchos::debug("New time: %d:%d", rtc_time.Hour, rtc_time.Minute);
|
|
}
|
|
if (RTC.alarm(ALARM_1))
|
|
{
|
|
watchos::debug("Alarm 1 fired?");
|
|
}
|
|
}
|
|
|
|
int Module_RTC::getHour()
|
|
{
|
|
return rtc_time.Hour;
|
|
}
|
|
|
|
int Module_RTC::getMinute()
|
|
{
|
|
return rtc_time.Minute;
|
|
}
|
|
|
|
int Module_RTC::getSecond()
|
|
{
|
|
return rtc_time.Second;
|
|
}
|
|
|
|
int Module_RTC::getYear()
|
|
{
|
|
return rtc_time.Year + 1970;
|
|
}
|
|
|
|
int Module_RTC::getMonth()
|
|
{
|
|
return rtc_time.Month;
|
|
}
|
|
|
|
int Module_RTC::getDay()
|
|
{
|
|
return rtc_time.Day;
|
|
}
|
|
|
|
char* Module_RTC::getDayOfWeek()
|
|
{
|
|
switch (rtc_time.Wday)
|
|
{
|
|
case 1:
|
|
return "Sunday";
|
|
case 2:
|
|
return "Monday";
|
|
case 3:
|
|
return "Tuesday";
|
|
case 4:
|
|
return "Wednesday";
|
|
case 5:
|
|
return "Thursday";
|
|
case 6:
|
|
return "Friday";
|
|
case 7:
|
|
return "Saturday";
|
|
default:
|
|
return "Unknown";
|
|
}
|
|
}
|
|
|