peroper backlight set func

This commit is contained in:
2026-09-28 21:25:21 +02:00
parent ab4674f6f4
commit 84b8207531
2 changed files with 10 additions and 2 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;
}
}