open and close funcs
This commit is contained in:
@@ -2,23 +2,17 @@
|
||||
|
||||
/* lcd size hardcoded to 4x40 idgaf */
|
||||
LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
|
||||
log(LOG::INF, "LCDDisplay", "Opening LCD at \"{}\"", dev);
|
||||
_dev = dev;
|
||||
_open();
|
||||
|
||||
struct termios term;
|
||||
int lcd = open(dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
|
||||
if (lcd < 0) {
|
||||
log(LOG::ERR, "LCDDisplay", "Error opening serial port \"{}\"", dev); // err
|
||||
exit(lcd);
|
||||
}
|
||||
|
||||
// Setup the serial port 8 data bits, no parity, 1 stopbit, no flow control
|
||||
term.c_cflag = baud | CS8 | CSTOPB | CLOCAL | CREAD;
|
||||
term.c_iflag = 0;
|
||||
term.c_oflag = 0;
|
||||
term.c_lflag = 0;
|
||||
tcflush(lcd, TCIFLUSH);
|
||||
tcsetattr(lcd, TCSANOW, &term);
|
||||
_lcd = lcd;
|
||||
tcflush(_lcd, TCIFLUSH);
|
||||
tcsetattr(_lcd, TCSANOW, &term);
|
||||
|
||||
// init linebuf to spaces
|
||||
clearBuf();
|
||||
@@ -32,7 +26,21 @@ LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
|
||||
}
|
||||
|
||||
LCDDisplay::~LCDDisplay() {
|
||||
close(_lcd);
|
||||
_close();
|
||||
}
|
||||
|
||||
void LCDDisplay::_open() {
|
||||
_lcd = open(_dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
if (_lcd < 0) {
|
||||
log(LOG::ERR, "LCDDisplay", "Error opening serial port \"{}\"", dev); // err
|
||||
exit(_lcd);
|
||||
}
|
||||
log(LOG::INF, "LCDDisplay", "Opened LCD at \"{}\"", _dev);
|
||||
}
|
||||
|
||||
void LCDDisplay::_close() {
|
||||
if (_lcd >= 0) close(_lcd);
|
||||
_lcd = -1;
|
||||
log(LOG::INF, "LCDDisplay", "LCD port closed");
|
||||
}
|
||||
|
||||
@@ -117,7 +125,9 @@ void LCDDisplay::flushBuf() {
|
||||
std::memcpy(&writebuf[2 * LCD_COLS + 4], setDisp, 4);
|
||||
writebuf[2 * LCD_COLS + 7] = 3; // overwrite set cursor c1 l1 to c1 l3
|
||||
|
||||
_open();
|
||||
write(_lcd, writebuf, sizeof(writebuf));
|
||||
_close();
|
||||
}
|
||||
|
||||
char LCDDisplay::bar(uint8_t char_id, double value) {
|
||||
|
||||
Reference in New Issue
Block a user