aboutsummaryrefslogtreecommitdiff
path: root/include/lcdlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/lcdlib.c')
-rw-r--r--include/lcdlib.c44
1 files changed, 29 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);