#include "include.h"
#include "rtcTest.h"
#include <ArduinoLog.h>
#include <RTClib.h>
// https://www.arduino.cn/thread-91034-1-1.html
// https://adafruit.github.io/RTClib/html/class_r_t_c___d_s1307.html
RTC_DS1307 ds1307;
// 初始化时间模块
void initRtc()
{
auto result = ds1307.begin();
Log.infoln("时钟初始化 %t", result);
if(result){
// 第一次使用时设置一下时间,这里使用编码时间
// 以后通过网络得到世界时,并进行校正
// ds1307.adjust(DateTime(__DATE__, __TIME__));
}
}
// 更新时间模块
void updateRtc()
{
if(ds1307.isrunning()){
auto time = ds1307.now();
auto strTime = time.timestamp(DateTime::TIMESTAMP_TIME);
// Log.infoln("当前时间 %s", strTime.c_str());
char fulltime[16];
sprintf(fulltime, "%2d-%2d %s", time.month(), time.day(), strTime.c_str());
oputputCurrentTime(fulltime); // 在 lcd 中显示
}
}