From afd5bef30944389d3844911644b39ea193270414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 17 Feb 2020 18:08:17 +0100 Subject: [PATCH] application: fix uptime action --- application.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/application.c b/application.c index a000c55..385c496 100644 --- a/application.c +++ b/application.c @@ -13,9 +13,9 @@ * */ /** STM32F1 application example - * @file application.c + * @file * @author King Kévin - * @date 2016-2019 + * @date 2016-2020 */ /* standard libraries */ @@ -237,7 +237,7 @@ static void command_version(void* argument) static void command_uptime(void* argument) { (void)argument; // we won't use the argument - uint32_t uptime = rtc_get_counter_val() - time_start; // get time from internal RTC + uint32_t uptime = (rtc_get_counter_val() - time_start) / RTC_TICKS_SECOND; // get time from internal RTC printf("uptime: %u.%02u:%02u:%02u\n", uptime / (24 * 60 * 60), (uptime / (60 * 60)) % 24, (uptime / 60) % 60, uptime % 60); } @@ -246,7 +246,7 @@ static void command_datetime(void* argument) { char* datetime = (char*)argument; // argument is optional date time if (NULL == argument) { // no date and time provided, just show the current day and time - time_t time_rtc = rtc_get_counter_val(); // get time from internal RTC + time_t time_rtc = rtc_get_counter_val() / RTC_TICKS_SECOND; // get time from internal RTC struct tm* time_tm = localtime(&time_rtc); // convert time printf("date: %d-%02d-%02d %02d:%02d:%02d\n", 1900 + time_tm->tm_year, time_tm->tm_mon, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec); } else { // date and time provided, set it @@ -267,8 +267,8 @@ static void command_datetime(void* argument) time_tm.tm_min = strtol(&datetime[14], NULL, 10); // parse minutes time_tm.tm_sec = strtol(&datetime[17], NULL, 10); // parse seconds time_t time_rtc = mktime(&time_tm); // get back seconds - time_start = time_rtc + (rtc_get_counter_val() - time_start); // update uptime with current date - rtc_set_counter_val(time_rtc); // save date/time to internal RTC + time_start = time_rtc * RTC_TICKS_SECOND + (rtc_get_counter_val() - time_start); // update uptime with current date + rtc_set_counter_val(time_rtc * RTC_TICKS_SECOND); // save date/time to internal RTC printf("date and time saved: %d-%02d-%02d %02d:%02d:%02d\n", 1900 + time_tm.tm_year, time_tm.tm_mon, time_tm.tm_mday, time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec); } }