Skip to content

Commit f760eff

Browse files
committed
特定条件下で無限ループする部分を修正
1 parent ca1e985 commit f760eff

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

poketch/src/lib/ntp.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,27 @@ static const char *ntpServer = "ntp.jst.mfeed.ad.jp"; // NTP server
66
static const long gmtOffset_sec = 9 * 3600; // Time offset 9hr
77
static const int daylightOffset_sec = 0; // No summer time
88

9-
struct tm timeinfo;
10-
11-
void getTimeFromNTP()
12-
{
13-
// To get Time from NTP server
14-
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
15-
while (!getLocalTime(&timeinfo))
16-
{
17-
delay(1000);
18-
}
19-
}
20-
219
void setNTP2RTC()
2210
{
11+
static struct tm timeinfo;
12+
2313
RTC_DateTypeDef RTC_DateStruct; // Data
2414
RTC_TimeTypeDef RTC_TimeStruct; // Time
25-
// timeSet
26-
getTimeFromNTP();
15+
// To get Time from NTP server
16+
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
2717
getLocalTime(&timeinfo);
18+
2819
// read RTC
2920
M5.Rtc.GetTime(&RTC_TimeStruct);
3021
M5.Rtc.GetDate(&RTC_DateStruct);
22+
3123
// --- to over write date&time
3224
RTC_DateStruct.Year = timeinfo.tm_year + 1900;
3325
RTC_DateStruct.Month = timeinfo.tm_mon + 1;
3426
RTC_DateStruct.Date = timeinfo.tm_mday;
3527
RTC_DateStruct.WeekDay = timeinfo.tm_wday;
3628
M5.Rtc.SetDate(&RTC_DateStruct);
29+
3730
RTC_TimeStruct.Hours = timeinfo.tm_hour;
3831
RTC_TimeStruct.Minutes = timeinfo.tm_min;
3932
RTC_TimeStruct.Seconds = timeinfo.tm_sec;

0 commit comments

Comments
 (0)