i was never checking the return value of write
This commit is contained in:
@@ -15,7 +15,7 @@ class LCDDisplay {
|
|||||||
char writebuf[LCD_LINES * LCD_COLS + 8]; // 4x40 chars + 2x4 setcursor commands
|
char writebuf[LCD_LINES * LCD_COLS + 8]; // 4x40 chars + 2x4 setcursor commands
|
||||||
static constexpr bool dualDisp = (LCD_LINES * LCD_COLS > 80); // is it dual display device or not, evauluated from the size at compile time
|
static constexpr bool dualDisp = (LCD_LINES * LCD_COLS > 80); // is it dual display device or not, evauluated from the size at compile time
|
||||||
|
|
||||||
void open();
|
void open(bool reopen = false);
|
||||||
void write(const uint8_t* cmdbuf, uint8_t len);
|
void write(const uint8_t* cmdbuf, uint8_t len);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
|||||||
@@ -33,17 +33,15 @@ LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
|
|||||||
|
|
||||||
// clear display and set cursor home
|
// clear display and set cursor home
|
||||||
this->clear();
|
this->clear();
|
||||||
this->close();
|
|
||||||
log(LOG::INF, "LCDDisplay", "Opened LCD port at \"{}\"", _dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LCDDisplay::~LCDDisplay() {
|
LCDDisplay::~LCDDisplay() {
|
||||||
this->close();
|
this->close();
|
||||||
log(LOG::INF, "LCDDisplay", "Closed LCD port");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCDDisplay::open() {
|
void LCDDisplay::open(bool reopen) {
|
||||||
if (_lcd < 0)
|
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()
|
_lcd = ::open(_dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); // ::open calls the global open() instead of LCDDisplay::open()
|
||||||
if (_lcd < 0) {
|
if (_lcd < 0) {
|
||||||
log(LOG::ERR, "LCDDisplay", "Error opening serial port \"{}\"", _dev); // err
|
log(LOG::ERR, "LCDDisplay", "Error opening serial port \"{}\"", _dev); // err
|
||||||
@@ -52,15 +50,19 @@ void LCDDisplay::open() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LCDDisplay::close() {
|
void LCDDisplay::close() {
|
||||||
if (_lcd >= 0)
|
if (_lcd >= 0) {
|
||||||
::close(_lcd);
|
::close(_lcd);
|
||||||
|
log(LOG::INF, "LCDDisplay", "Closed LCD port");
|
||||||
|
}
|
||||||
_lcd = -1;
|
_lcd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCDDisplay::write(const uint8_t* cmdbuf, uint8_t len) {
|
void LCDDisplay::write(const uint8_t* cmdbuf, uint8_t len) {
|
||||||
this->open();
|
int rc = ::write(_lcd, cmdbuf, len);
|
||||||
::write(_lcd, cmdbuf, len);
|
if(rc < 0) {
|
||||||
this->close();
|
log(LOG::ERR, "LCDDisplay::write", "failed to execute ::write, lost access to port?");
|
||||||
|
this->open(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCDDisplay::clear() {
|
void LCDDisplay::clear() {
|
||||||
|
|||||||
Reference in New Issue
Block a user