i was never checking the return value of write
This commit is contained in:
@@ -33,17 +33,15 @@ LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
|
||||
|
||||
// clear display and set cursor home
|
||||
this->clear();
|
||||
this->close();
|
||||
log(LOG::INF, "LCDDisplay", "Opened LCD port at \"{}\"", _dev);
|
||||
}
|
||||
|
||||
LCDDisplay::~LCDDisplay() {
|
||||
this->close();
|
||||
log(LOG::INF, "LCDDisplay", "Closed LCD port");
|
||||
}
|
||||
|
||||
void LCDDisplay::open() {
|
||||
if (_lcd < 0)
|
||||
void LCDDisplay::open(bool reopen) {
|
||||
log(LOG::INF, "LCDDisplay", "Opening serial port at \"{}\"", _dev);
|
||||
if (_lcd < 0 || reopen)
|
||||
_lcd = ::open(_dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); // ::open calls the global open() instead of LCDDisplay::open()
|
||||
if (_lcd < 0) {
|
||||
log(LOG::ERR, "LCDDisplay", "Error opening serial port \"{}\"", _dev); // err
|
||||
@@ -52,15 +50,19 @@ void LCDDisplay::open() {
|
||||
}
|
||||
|
||||
void LCDDisplay::close() {
|
||||
if (_lcd >= 0)
|
||||
if (_lcd >= 0) {
|
||||
::close(_lcd);
|
||||
log(LOG::INF, "LCDDisplay", "Closed LCD port");
|
||||
}
|
||||
_lcd = -1;
|
||||
}
|
||||
|
||||
void LCDDisplay::write(const uint8_t* cmdbuf, uint8_t len) {
|
||||
this->open();
|
||||
::write(_lcd, cmdbuf, len);
|
||||
this->close();
|
||||
int rc = ::write(_lcd, cmdbuf, len);
|
||||
if(rc < 0) {
|
||||
log(LOG::ERR, "LCDDisplay::write", "failed to execute ::write, lost access to port?");
|
||||
this->open(true);
|
||||
}
|
||||
}
|
||||
|
||||
void LCDDisplay::clear() {
|
||||
|
||||
Reference in New Issue
Block a user