set time on UART entry
This commit is contained in:
parent
bc30ef0daa
commit
b5134bb498
79
main.c
79
main.c
|
@ -223,6 +223,33 @@ static void leds_set(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief set the time on the LEDs
|
||||||
|
* @details this will have an animation where time is incremented until it reaches the provided time
|
||||||
|
* @param[in] time time to set
|
||||||
|
*/
|
||||||
|
static void clock_set_time(uint32_t time)
|
||||||
|
{
|
||||||
|
static uint32_t display_time = 0; // the time to display
|
||||||
|
while (display_time<time) {
|
||||||
|
if (display_time+ticks_hour<=time) { // first set hours
|
||||||
|
display_time += ticks_hour; // increment hours
|
||||||
|
} else if (display_time+ticks_minute<=time) { // second set minutes
|
||||||
|
display_time += ticks_minute; // increment minutes
|
||||||
|
} else if (display_time+ticks_second<=time) { // third set seconds
|
||||||
|
display_time += ticks_second; // increment seconds
|
||||||
|
} else { // finally set time
|
||||||
|
display_time = time;
|
||||||
|
}
|
||||||
|
clock_show_time(display_time); // set time (progress)
|
||||||
|
leds_set(); // set the colors of all LEDs
|
||||||
|
ws2812b_transmit(); // transmit set color
|
||||||
|
// delay some time for the animation
|
||||||
|
for (uint32_t i=0; i<400000; i++) {
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief program entry point
|
/** @brief program entry point
|
||||||
* this is the firmware function started by the micro-controller
|
* this is the firmware function started by the micro-controller
|
||||||
*/
|
*/
|
||||||
|
@ -265,46 +292,24 @@ int main(void)
|
||||||
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
||||||
led_on(); // switch on LED to indicate setup completed
|
led_on(); // switch on LED to indicate setup completed
|
||||||
|
|
||||||
|
// verify is RTC is running
|
||||||
uint16_t* rtc_time = rtc_read_time(); // get current date
|
|
||||||
printf("current date: %04d-%02d-%02d %02d:%02d:%02d\n", rtc_time[6], rtc_time[5], rtc_time[4], rtc_time[2], rtc_time[1], rtc_time[0]);
|
|
||||||
uint32_t display_time = 0; // the time to display
|
|
||||||
uint32_t current_time = rtc_time[2]*ticks_hour+rtc_time[1]*ticks_minute+rtc_time[0]*ticks_second; // the current time
|
|
||||||
printf("setting current time\n");
|
|
||||||
while (display_time<current_time) {
|
|
||||||
if (display_time+ticks_hour<=current_time) { // first set hours
|
|
||||||
display_time += ticks_hour; // increment hours
|
|
||||||
} else if (display_time+ticks_minute<=current_time) { // second set minutes
|
|
||||||
display_time += ticks_minute; // increment minutes
|
|
||||||
} else if (display_time+ticks_minute<=current_time) { // third set seconds
|
|
||||||
display_time += ticks_second; // increment seconds
|
|
||||||
} else { // finally set time
|
|
||||||
display_time = current_time;
|
|
||||||
}
|
|
||||||
clock_show_time(display_time); // set time (progress)
|
|
||||||
leds_set(); // set the colors of all LEDs
|
|
||||||
ws2812b_transmit(); // transmit set color
|
|
||||||
// delay some time
|
|
||||||
for (uint32_t i=0; i<400000; i++) {
|
|
||||||
__asm__("nop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("it is now %02lu:%02lu:%02lu\n", display_time/ticks_hour, (display_time%ticks_hour)/ticks_minute, (display_time%ticks_minute)/ticks_second);
|
|
||||||
// test RTC
|
|
||||||
printf("RTC oscillator: ");
|
|
||||||
if (rtc_oscillator_disabled()) {
|
if (rtc_oscillator_disabled()) {
|
||||||
printf("disbaled\n");
|
printf("/!\\ RTC oscillator is disabled\n");
|
||||||
} else {
|
|
||||||
printf("enabled\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get date
|
||||||
|
uint16_t* rtc_time = rtc_read_time(); // get RTC time/date
|
||||||
|
uint32_t current_time = rtc_time[2]*ticks_hour+rtc_time[1]*ticks_minute+rtc_time[0]*ticks_second; // the current time
|
||||||
|
printf("current date: %04d-%02d-%02d %02d:%02d:%02d\n", rtc_time[6], rtc_time[5], rtc_time[4], rtc_time[2], rtc_time[1], rtc_time[0]);
|
||||||
|
|
||||||
//rtc_write_time(0,52,9,4,23,3,2016);
|
//rtc_write_time(0,52,9,4,23,3,2016);
|
||||||
//rtc_oscillator_enable();
|
//rtc_oscillator_enable();
|
||||||
|
|
||||||
printf("input commands\n");
|
printf("input commands\n");
|
||||||
bool action = false; // if an action has been performed don't go to sleep
|
bool action = false; // if an action has been performed don't go to sleep
|
||||||
button_flag = false; // reset button flag
|
button_flag = false; // reset button flag
|
||||||
char c; // to store received character
|
char c = ' '; // to store received character
|
||||||
bool char_flag = false; // a new character has been received
|
bool char_flag = true; // a new character has been received
|
||||||
/* toggle the LED with every transmitted character */
|
/* toggle the LED with every transmitted character */
|
||||||
while (true) { // infinite loop
|
while (true) { // infinite loop
|
||||||
while (usart_received) { // echo every received character
|
while (usart_received) { // echo every received character
|
||||||
|
@ -323,12 +328,10 @@ int main(void)
|
||||||
char_flag = false; // reset flag
|
char_flag = false; // reset flag
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
printf("%c",c); // echo receive character
|
printf("%c",c); // echo receive character
|
||||||
|
rtc_time = rtc_read_time(); // get RTC time/date
|
||||||
printf("%02lu:%02lu\n", display_time/ticks_hour, (display_time%ticks_hour)/ticks_minute);
|
current_time = rtc_time[2]*ticks_hour+rtc_time[1]*ticks_minute+rtc_time[0]*ticks_second; // calculate current time
|
||||||
clock_show_time(display_time); // set time
|
clock_set_time(current_time); // set time
|
||||||
display_time += ticks_minute; // increment time
|
printf("it is now %02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||||
leds_set(); // set the colors of all LEDs
|
|
||||||
ws2812b_transmit(); // transmit set color
|
|
||||||
}
|
}
|
||||||
while (button_flag) {
|
while (button_flag) {
|
||||||
button_flag = false; // reset flag
|
button_flag = false; // reset flag
|
||||||
|
|
Loading…
Reference in New Issue