vfd has how two lines

This commit is contained in:
King Kévin 2016-01-26 10:16:14 +01:00
parent 91fd87c701
commit 7661170957
1 changed files with 20 additions and 6 deletions

26
main.c
View File

@ -123,6 +123,7 @@ int main(void)
uint8_t vfd_place = 0; // the place on which the next character will be displayed on the VFD
bool vfd_flag = false; // do something with the VFD
char c = 0; // the character to display
char previous_line[VFD_DIGITS] = {0};
while (true) {
while (usart_received) { // echo every received character
c = usart_getchar();
@ -136,13 +137,26 @@ int main(void)
vfd_flag = false;
printf("%c", c); // transmit receive character
gpio_toggle(LED_PORT, LED_PIN); // toggle LED to show activity
if (c=='\r' || c=='\n') { // on newline
vfd_clear(); // clear display
vfd_place = 0; // restart from beginning
if (c=='\r' || c=='\n') { // on (new) newline
if (vfd_place>0) { // only on new newline
vfd_clear(); // clear display
vfd_place = 0; // restart from beginning
// show previous line on digits (and clear it
for (uint8_t i=0; i<LENGTH(previous_line) && i<VFD_DIGITS; i++) {
vfd_digit(i,previous_line[i]);
previous_line[i] = 0;
}
}
} else {
vfd_digit(vfd_place,c); // display character on digit
vfd_matrix(vfd_place,c); // display character on matrix
vfd_place++; // go to next place
// show typed character for current line on matrix
if (vfd_place < VFD_MATRIX) {
vfd_matrix(vfd_place,c); // display character on digit
}
// save character for the net previous line
if (vfd_place < LENGTH(previous_line)) {
previous_line[vfd_place] = c;
}
vfd_place++; // go to next place (you can overflow it and confuse the newline)
}
}
__WFI(); // go to sleep