MCPcopy Create free account
hub / github.com/BruceDevices/firmware / init_clock

Function init_clock

src/main.cpp:339–372  ·  view source on GitHub ↗

** Function: init_clock ** Clock initialisation for propper display in menu *********************************************************************/

Source from the content-addressed store, hash-verified

337 ** Clock initialisation for propper display in menu
338 *********************************************************************/
339void init_clock() {
340#if defined(HAS_RTC)
341 _rtc.begin();
342#if defined(HAS_RTC_BM8563)
343 _rtc.GetBm8563Time();
344#endif
345#if defined(HAS_RTC_PCF85063A)
346 _rtc.GetPcf85063Time();
347#endif
348 _rtc.GetTime(&_time);
349 _rtc.GetDate(&_date);
350
351 struct tm timeinfo = {};
352 timeinfo.tm_sec = _time.Seconds;
353 timeinfo.tm_min = _time.Minutes;
354 timeinfo.tm_hour = _time.Hours;
355 timeinfo.tm_mday = _date.Date;
356 timeinfo.tm_mon = _date.Month > 0 ? _date.Month - 1 : 0;
357 timeinfo.tm_year = _date.Year >= 1900 ? _date.Year - 1900 : 0;
358 time_t epoch = mktime(&timeinfo);
359 struct timeval tv = {.tv_sec = epoch};
360 settimeofday(&tv, nullptr);
361#else
362 struct tm timeinfo = {};
363 timeinfo.tm_year = CURRENT_YEAR - 1900;
364 timeinfo.tm_mon = 0x05;
365 timeinfo.tm_mday = 0x14;
366 time_t epoch = mktime(&timeinfo);
367 rtc.setTime(epoch);
368 clock_set = true;
369 struct timeval tv = {.tv_sec = epoch};
370 settimeofday(&tv, nullptr);
371#endif
372}
373
374/*********************************************************************
375 ** Function: init_led

Callers 1

setupFunction · 0.85

Calls 5

GetBm8563TimeMethod · 0.80
GetPcf85063TimeMethod · 0.80
beginMethod · 0.45
GetTimeMethod · 0.45
GetDateMethod · 0.45

Tested by

no test coverage detected