add DCF command

This commit is contained in:
King Kévin 2016-07-30 15:24:40 +02:00
parent e68335340c
commit 933ebef400
1 changed files with 24 additions and 3 deletions

27
main.c
View File

@ -335,10 +335,24 @@ static void process_command(char* str)
// parse command
if (0==strcmp(word,"help")) {
printf("available commands:\n");
printf("DCF77 on|off\n");
printf("time [HH:MM:SS]\n");
#if defined(EXTERNAL_RTC) && EXTERNAL_RTC
printf("date [YYYY-MM-DD]\n");
#endif
} else if (0==strcmp(word,"DCF77")) {
word = strtok(NULL,delimiter);
if (!word) {
goto error;
} else if (0==strcmp(word,"on")) {
rtc_dcf77_on(); // switch DCF77 on
printf("DCF77 receiver switched on\n"); // notify user
} else if (0==strcmp(word,"off")) {
rtc_dcf77_off(); // switch DCF77 off
printf("DCF77 receiver switched off\n"); // notify user
} else {
goto error;
}
} else if (0==strcmp(word,"time")) {
word = strtok(NULL,delimiter);
if (!word) {
@ -438,10 +452,15 @@ int main(void)
rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds"
nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt
#endif
rtc_dcf77_setup(); // setup DCF77 module
rtc_dcf77_on(); // switch on DCF77 module to get correct time
printf("OK\n");
// setup DCF77
printf("setup DCF77 receiver: ");
rtc_dcf77_setup(); // setup DCF77 module
printf("OK\n");
rtc_dcf77_on(); // switch DCF77 on to get correct time
printf("DCF77 receiver switched on\n"); // notify user
// setup WS2812B LEDs
printf("setup LEDs: ");
for (uint16_t i=0; i<LENGTH(gamma_correction_lut); i++) { // generate gamma correction table
@ -565,6 +584,7 @@ int main(void)
#endif
printf("DCF77 time: 20%02u-%02u-%02u %02u:%02u:00\n", dcf77_time[5], dcf77_time[4], dcf77_time[2], dcf77_time[1], dcf77_time[0]); // display time
rtc_dcf77_off(); // switch DCF77 off since we have correct time
printf("DCF77 receiver switched off\n"); // notify user
} else {
printf("DCF77 time: error\n");
}
@ -589,8 +609,9 @@ int main(void)
printf("%02lu:%02lu:%02lu\n", ticks_time/ticks_hour, (ticks_time%ticks_hour)/ticks_minute, (ticks_time%ticks_minute)/ticks_second); // display external time
}
if ((ticks_time%ticks_hour)==0) { // one hours passed
rtc_dcf77_on(); // switch DCF77 on to update/correct time
clock_hours(); // show hour markers
rtc_dcf77_on(); // switch DCF77 on to update/correct time
printf("DCF77 receiver switched on\n"); // notify user
}
if (ticks_time>=ticks_midday*2) { // one day passed
#if defined(EXTERNAL_RTC) && EXTERNAL_RTC