diff options
| author | tslil clingman <tslil@posteo.de> | 2021-10-05 18:22:23 -0400 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | cf175fc346f1b208766b1f55d3673a7b208f322a (patch) | |
| tree | 3dabfd672b73e7d0756d8259e59464d1f560aee6 /include/lcdlib.c | |
| parent | 640d404b3cf3324aca4424fc3da4806d4562d0e4 (diff) | |
Welcome geminict!
This is a special interface to negamax_cnn1986 which is designed to
generate output for use in a CGI tak interface to be used over gemini.
Also in this commit is a reformating of the various source files to
use the traditional tab width of 8 spaces.
Diffstat (limited to 'include/lcdlib.c')
| -rw-r--r-- | include/lcdlib.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/include/lcdlib.c b/include/lcdlib.c index 4d8c33e..69d6df0 100644 --- a/include/lcdlib.c +++ b/include/lcdlib.c @@ -1,18 +1,18 @@ /* - This file is part of ct. + This file is part of ct. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. - You should have received a copy of the GNU General Public License - along with ct. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU General Public License + along with ct. If not, see <https://www.gnu.org/licenses/>. */ #include "lcdlib.h" @@ -24,74 +24,74 @@ static int line_idx; int lcd_begin(void) { - lcd = fopen("/dev/lcd", "w"); - if (lcd == NULL) return EXIT_FAILURE; - lcd_clear(); - return EXIT_SUCCESS; + lcd = fopen("/dev/lcd", "w"); + if (lcd == NULL) return EXIT_FAILURE; + lcd_clear(); + return EXIT_SUCCESS; } void lcd_end(void) { - fclose(lcd); + fclose(lcd); } void lcd_set_blink(void) { - fprintf(lcd, "%sB", esc); - fflush(lcd); + fprintf(lcd, "%sB", esc); + fflush(lcd); } void lcd_stop_blink(void) { - fprintf(lcd, "%sb", esc); - fflush(lcd); + fprintf(lcd, "%sb", esc); + fflush(lcd); } void lcd_clear(void) { - line_idx = 0; - for (int y = 0; y + 1 < LCD_HEIGHT; y++) { - fprintf(lcd, "%sy%dx0;%sk", esc, y, esc); - previous_lines[y][0] = 0; - } - fflush(lcd); + line_idx = 0; + for (int y = 0; y + 1 < LCD_HEIGHT; y++) { + fprintf(lcd, "%sy%dx0;%sk", esc, y, esc); + previous_lines[y][0] = 0; + } + fflush(lcd); } void lcd_put_line(const enum LCD_WRITE_MODE mode, const char *line) { - 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); - } - } - 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! - 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++; + 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); + } + } + 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! + 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[LCD_WIDTH+1]; + const char *format, ...) { + char buf[LCD_WIDTH+1]; - va_list(args); - va_start(args, format); - vsnprintf(buf, LCD_WIDTH+1, format, args); - va_end(args); + va_list(args); + va_start(args, format); + vsnprintf(buf, LCD_WIDTH+1, format, args); + va_end(args); - lcd_put_line(mode, buf); + lcd_put_line(mode, buf); } |
