From 399d90f1b94717aa0ca5abb1dc43bdb6f4160d13 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Sun, 31 Jan 2021 15:33:30 -0500 Subject: Fairly important bug fixes to lcdlib, LCD now echoes input! Input polling without line-buffering is done using ncurses, so the buildroot configuration had to change accordingly to include that library. The Makefile changed to accommodate stand-alone building of ct1986 and to include -lcurses where appropriate. There were also some typos about copying ct1986 and ctaklm to the correct directories. --- include/lcdlib.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'include/lcdlib.c') diff --git a/include/lcdlib.c b/include/lcdlib.c index c956d5c..7f10e33 100644 --- a/include/lcdlib.c +++ b/include/lcdlib.c @@ -26,8 +26,6 @@ int lcd_begin(void) { lcd = fopen("/dev/lcd", "w"); if (lcd == NULL) return EXIT_FAILURE; - fprintf(lcd, "%sB", esc); - fflush(lcd); lcd_clear(); return EXIT_SUCCESS; } @@ -37,6 +35,18 @@ lcd_end(void) { fclose(lcd); } +void +lcd_set_blink(void) { + fprintf(lcd, "%sB", esc); + fflush(lcd); +} + +void +lcd_stop_blink(void) { + fprintf(lcd, "%sb", esc); + fflush(lcd); +} + void lcd_clear(void) { line_idx = 0; @@ -49,34 +59,38 @@ lcd_clear(void) { void lcd_put_line(const enum LCD_WRITE_MODE mode, const char *line) { - if (mode == L_SCROLL && line_idx == LCD_HEIGHT) { - // If we're at the bottom, ``shift'' everything up - for (int y = 1; y < LCD_HEIGHT; y++) { - // Go to the start of row y, clear the line, and print the - // previous string there - fprintf(lcd, "%sy%dx0;%sk%s", esc, y-1, esc, previous_lines[y]); - // Overwrite the stored previous line with the next - strncpy(previous_lines[y-1], previous_lines[y], 17); + char last_line = 0; + if (line_idx == LCD_HEIGHT) { + if (mode == L_SCROLL) { + // If we're at the bottom, ``shift'' everything up + for (int y = 1; y < LCD_HEIGHT; y++) { + // Go to the start of row y, clear the line, and print the + // previous string there + fprintf(lcd, "%sy%dx0;%sk%s", esc, y-1, esc, previous_lines[y]); + // Overwrite the stored previous line with the next + strncpy(previous_lines[y-1], previous_lines[y], LCD_WIDTH+1); + } } - line_idx--; + last_line = 1; } // Go to the correct line, clear it, and write the input. fprintf(lcd, "%sy%dx0;%sk%s", esc, line_idx, esc, line); fflush(lcd); // Store this line, null-terminate! - strncpy(previous_lines[line_idx], line, 16); - previous_lines[line_idx][16] = 0; + if (last_line) line_idx--; + strncpy(previous_lines[line_idx], line, LCD_WIDTH+1); + previous_lines[line_idx][LCD_WIDTH] = 0; if (mode == L_SCROLL && line_idx < LCD_HEIGHT) line_idx++; } void lcd_printf_line(const enum LCD_WRITE_MODE mode, const char *format, ...) { - char buf[16]; + char buf[LCD_WIDTH+1]; va_list(args); va_start(args, format); - vsnprintf(buf, 16, format, args); + vsnprintf(buf, LCD_WIDTH+1, format, args); va_end(args); lcd_put_line(mode, buf); -- cgit v1.2.3