diff options
| author | tslil clingman <tslil@posteo.de> | 2021-01-31 15:33:30 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 399d90f1b94717aa0ca5abb1dc43bdb6f4160d13 (patch) | |
| tree | 21c954622a23fa606dacfe85552df92f6f195903 /include | |
| parent | 84ad2e3c12cb505e3c5e3dd29d05edb529b82174 (diff) | |
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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/lcdlib.c | 44 | ||||
| -rw-r--r-- | include/lcdlib.h | 3 |
2 files changed, 32 insertions, 15 deletions
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; } @@ -38,6 +36,18 @@ lcd_end(void) { } 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; for (int y = 0; y + 1 < LCD_HEIGHT; y++) { @@ -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); diff --git a/include/lcdlib.h b/include/lcdlib.h index 192b3a4..b1cfc87 100644 --- a/include/lcdlib.h +++ b/include/lcdlib.h @@ -37,6 +37,9 @@ int lcd_begin(void); void lcd_end(void); void lcd_clear(void); +void lcd_set_blink(void); +void lcd_stop_blink(void); + void lcd_put_line(const enum LCD_WRITE_MODE mode, const char *line); void lcd_printf_line(const enum LCD_WRITE_MODE mode, |
