application: fix uptime action

This commit is contained in:
King Kévin 2020-02-17 18:08:17 +01:00
parent d2d09edaf8
commit afd5bef309
1 changed files with 6 additions and 6 deletions

View File

@ -13,9 +13,9 @@
*
*/
/** STM32F1 application example
* @file application.c
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @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);
}
}