maybe this will reopen properly?
This commit is contained in:
25
src/lcd.c
25
src/lcd.c
@@ -16,11 +16,16 @@ void lcd_write(struct lcd_t *lcd, const uint8_t *cmdbuf, uint16_t len);
|
||||
int lcd_open(struct lcd_t *lcd, const bool reopen) {
|
||||
applog(LOG_INF, "Opening serial port at %s", lcd->port);
|
||||
if (lcd->fd <= 0 || reopen)
|
||||
lcd->fd = open(lcd->port, O_RDWR | O_NOCTTY);
|
||||
lcd->fd = open(lcd->port, O_WRONLY | O_NOCTTY);
|
||||
if (lcd->fd <= 0) {
|
||||
applog(LOG_ERR, "Error opening serial port %s", lcd->port); // err
|
||||
return -1;
|
||||
}
|
||||
struct termios term = {};
|
||||
term.c_cflag = lcd->baud | CS8 | CLOCAL | CREAD;
|
||||
tcflush(lcd->fd, TCIFLUSH);
|
||||
tcsetattr(lcd->fd, TCSANOW, &term);
|
||||
applog(LOG_DBG, "file desc is %d", lcd->fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -98,8 +103,14 @@ void lcd_writef(struct lcd_t *lcd, const uint8_t x, const uint8_t y, const char
|
||||
|
||||
inline void lcd_clear_buf(struct lcd_t *lcd) {
|
||||
memset(lcd->writebuf.text, ' ', sizeof(lcd->writebuf.text));
|
||||
// prepare commands for custom chars
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
const uint8_t charbuf[] = {254, 78, i};
|
||||
memcpy(lcd->writebuf.cchar[i], charbuf, sizeof(charbuf));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* flushes writebuffer to lcd, hyperoptmized, flushes buffer and commands in a single write operation */
|
||||
inline void lcd_flush_buf(struct lcd_t *lcd) {
|
||||
constexpr uint8_t set_disp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1
|
||||
@@ -127,18 +138,6 @@ int lcd_init(struct lcd_t *lcd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct termios term = {};
|
||||
term.c_cflag = lcd->baud | CS8 | CLOCAL | CREAD;
|
||||
|
||||
tcflush(lcd->fd, TCIFLUSH);
|
||||
tcsetattr(lcd->fd, TCSANOW, &term);
|
||||
|
||||
// zero out custom chars
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
const uint8_t charbuf[] = {254, 78, i, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
memcpy(lcd->writebuf.cchar[i], charbuf, sizeof(charbuf));
|
||||
}
|
||||
|
||||
lcd_clear_buf(lcd);
|
||||
constexpr uint8_t cmdbuf[] = {254, 75, 254, 84};
|
||||
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
||||
|
||||
Reference in New Issue
Block a user