From 84b8207531f442acb9fc81fed44d875f36ef3cfc Mon Sep 17 00:00:00 2001 From: Drath Date: Mon, 28 Sep 2026 21:25:21 +0200 Subject: [PATCH] peroper backlight set func --- include/lcd.h | 3 ++- src/lcd.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/lcd.h b/include/lcd.h index 15eef14..a63911b 100644 --- a/include/lcd.h +++ b/include/lcd.h @@ -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 \ No newline at end of file +#endif diff --git a/src/lcd.c b/src/lcd.c index ea924a9..ba6aabc 100644 --- a/src/lcd.c +++ b/src/lcd.c @@ -2,6 +2,7 @@ #include "log.h" #include #include +#include #include #include #include @@ -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; -} \ No newline at end of file +}