replace time with uptime

This commit is contained in:
King Kévin 2017-01-30 09:50:01 +01:00
parent 98469964a5
commit db3ce48069
1 changed files with 2 additions and 12 deletions

14
main.c
View File

@ -117,16 +117,6 @@ static void process_command(char* str)
} else { } else {
goto error; goto error;
} }
} else if (0==strcmp(word,"time")) {
word = strtok(NULL,delimiter);
if (!word) {
printf("current time: %02lu:%02lu:%02lu\n", rtc_get_counter_val()/(60*60), (rtc_get_counter_val()%(60*60))/60, (rtc_get_counter_val()%60)); // get and print time from internal RTC
} else if (strlen(word)!=8 || word[0]<'0' || word[0]>'2' || word[1]<'0' || word[1]>'9' || word[3]<'0' || word[3]>'5' || word[4]<'0' || word[4]>'9' || word[6]<'0' || word[6]>'5' || word[7]<'0' || word[7]>'9') { // time format is incorrect
goto error;
} else {
rtc_set_counter_val(((word[0]-'0')*10+(word[1]-'0')*1)*(60*60)+((word[3]-'0')*10+(word[4]-'0')*1)*60+((word[6]-'0')*10+(word[7]-'0')*1)); // set time in internal RTC counter
printf("time set\n");
}
} else { } else {
goto error; goto error;
} }
@ -191,7 +181,7 @@ void main(void)
printf("OK\n"); printf("OK\n");
uint32_t ticks_time = rtc_get_counter_val(); // get time from internal RTC (since first start/power up) uint32_t ticks_time = rtc_get_counter_val(); // get time from internal RTC (since first start/power up)
printf("uptime: %02lu:%02lu:%02lu\n", ticks_time/(60*60), (ticks_time%(60*60))/60, (ticks_time%60)); // display time printf("uptime: %lu.%02lu:%02lu:%02lu\n", ticks_time/(60*60*24), (ticks_time/(60*60))%24, (ticks_time%(60*60))/60, (ticks_time%60)); // display uptime
// main loop // main loop
printf("command input: ready\n"); printf("command input: ready\n");
@ -245,7 +235,7 @@ void main(void)
ticks_time = rtc_get_counter_val(); // copy time from internal RTC for processing ticks_time = rtc_get_counter_val(); // copy time from internal RTC for processing
action = true; // action has been performed action = true; // action has been performed
if ((ticks_time%(60))==0) { // one minute passed if ((ticks_time%(60))==0) { // one minute passed
printf("uptime: %02lu:%02lu:%02lu\n", ticks_time/(60*60), (ticks_time%(60*60))/60, (ticks_time%60)); // display external time printf("uptime: %lu.%02lu:%02lu:%02lu\n", ticks_time/(60*60*24), (ticks_time/(60*60))%24, (ticks_time%(60*60))/60, (ticks_time%60)); // display uptime
} }
} }
if (action) { // go to sleep if nothing had to be done, else recheck for activity if (action) { // go to sleep if nothing had to be done, else recheck for activity