Compare commits

...

2 Commits

Author SHA1 Message Date
106de77287 set backlight, dont disable on shutdown 2026-09-28 21:25:33 +02:00
84b8207531 peroper backlight set func 2026-09-28 21:25:21 +02:00
3 changed files with 11 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ void lcd_close(struct lcd_t *lcd);
void lcd_clear(struct lcd_t *lcd);
void lcd_set_contrast(struct lcd_t *lcd, uint8_t contrast);
void lcd_set_backlight(struct lcd_t *lcd, bool enabled);
void lcd_set_brightness(struct lcd_t *lcd, uint8_t brightness);
void lcd_set_cursor(struct lcd_t *lcd, uint8_t row, uint8_t col);
void lcd_set_custom_char(struct lcd_t *lcd, uint8_t index, const lcd_glyph_t *glyph);
void lcd_write_buf(struct lcd_t *lcd, uint8_t row, uint8_t col, const char *str);
@@ -31,4 +32,4 @@ void lcd_flush_buf(struct lcd_t *lcd);
char lcd_bar(struct lcd_t *lcd, uint8_t char_id, double value);
int lcd_init(struct lcd_t *lcd);
#endif
#endif

View File

@@ -2,6 +2,7 @@
#include "log.h"
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
@@ -58,6 +59,12 @@ void lcd_set_backlight(struct lcd_t *lcd, const bool enabled) {
lcd_write(lcd, cmdbuf, enabled ? 3 : 2);
}
void lcd_set_brightness(struct lcd_t *lcd, const uint8_t brightness) {
applog(LOG_INF, "Set backlight brightness to %d", brightness);
const uint8_t cmdbuf[] = {0xFE, 152, brightness};
lcd_write(lcd, cmdbuf, 3);
}
void lcd_set_cursor(struct lcd_t *lcd, const uint8_t row, const uint8_t col) {
const uint8_t cmdbuf[] = {0xFE, 71, col + 1, row + 1};
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
@@ -138,4 +145,4 @@ int lcd_init(struct lcd_t *lcd) {
lcd_clear(lcd);
return 0;
}
}

View File

@@ -99,6 +99,7 @@ static void *display_thread(void *arg) {
.baud = 0010002, // from termios-baud.h, B115200
};
lcd_init(&lcd);
lcd_set_brightness(&lcd, 255);
lcd_set_backlight(&lcd, true);
lcd_set_contrast(&lcd, lcd_contrast);
@@ -175,7 +176,6 @@ static void *display_thread(void *arg) {
}
lcd_write_buf(&lcd, 2, 16, "Goodbye"); // center
lcd_set_backlight(&lcd, false);
lcd_flush_buf(&lcd);
lcd_close(&lcd);
applog(LOG_WRN, "display thread stopped");