improve newline support
This commit is contained in:
parent
0a12fc9cf0
commit
dde027c858
12
main.c
12
main.c
@ -108,7 +108,7 @@ int _write(int file, char *ptr, int len)
|
||||
|
||||
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (ptr[i] == '\r' || ptr[i] == '\n') { // send CR+LF newline for any carriage return and line feed combination
|
||||
if (ptr[i] == '\r' || ptr[i] == '\n') { // send CR+LF newline for most carriage return and line feed combination
|
||||
if (newline==0 || (newline==ptr[i])) { // newline has already been detected
|
||||
usart_putchar_nonblocking('\r'); // send newline over USART
|
||||
usart_putchar_nonblocking('\n'); // send newline over USART
|
||||
@ -116,8 +116,11 @@ int _write(int file, char *ptr, int len)
|
||||
cdcacm_putchar('\n'); // send newline over USB
|
||||
newline = ptr[i]; // remember the newline
|
||||
}
|
||||
if (ptr[i] == '\n') { // line feed are always considered to end a line (the LF+CR combination is not supported to better support the others)
|
||||
newline = 0; // clear new line
|
||||
}
|
||||
} else { // non-newline character
|
||||
usart_putchar_nonblocking(ptr[i]); // send byte over USART
|
||||
usart_putchar_nonblocking(ptr[i]); // send byte over USART
|
||||
cdcacm_putchar(ptr[i]); // send byte over USB
|
||||
newline = 0; // clear new line
|
||||
}
|
||||
@ -424,6 +427,10 @@ int main(void)
|
||||
printf("/!\\ RTC oscillator is disabled: the battery may be empty\n");
|
||||
}
|
||||
|
||||
// variables to measure the RTC drift
|
||||
uint32_t rtc_internal_start = rtc_get_counter_val();
|
||||
uint32_t rtc_external_start = rtc_ticks;
|
||||
|
||||
// get date and time
|
||||
printf("current time: %02lu:%02lu:%02lu\n", rtc_get_counter_val()/ticks_hour, (rtc_get_counter_val()%ticks_hour)/ticks_minute, (rtc_get_counter_val()%ticks_minute)/ticks_second); // display time
|
||||
clock_animate_time(rtc_get_counter_val()); // set time with animation
|
||||
@ -484,6 +491,7 @@ int main(void)
|
||||
}
|
||||
if ((rtc_ticks%ticks_minute)==0) { // one minute passed
|
||||
printf("%02lu:%02lu:%02lu\n", rtc_get_counter_val()/ticks_hour, (rtc_get_counter_val()%ticks_hour)/ticks_minute, (rtc_get_counter_val()%ticks_minute)/ticks_second); // display time
|
||||
printf("internal RTC drift: %f%%\n", 1-((double)(rtc_ticks-rtc_external_start))/(double)(rtc_get_counter_val()-rtc_internal_start));
|
||||
}
|
||||
if ((rtc_ticks%ticks_hour)==0) { // one hours passed
|
||||
clock_hours(); // show hour markers
|
||||
|
Loading…
Reference in New Issue
Block a user