add some return values to some shit so it shuts down elegantly on crash
This commit is contained in:
@@ -13,11 +13,22 @@
|
||||
/* lcd size hardcoded to 4x40 idgaf */
|
||||
LCDDisplay::LCDDisplay(const std::string& dev, const uint32_t baud) {
|
||||
_dev = dev;
|
||||
this->open(); // calls this (LCDDisplay) open() function, LCDDisplay::open()
|
||||
_baud = baud;
|
||||
}
|
||||
|
||||
LCDDisplay::~LCDDisplay() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
int LCDDisplay::Init() {
|
||||
if (const int ret = this->open(); ret < 0) {
|
||||
this->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct termios term{};
|
||||
// Setup the serial port 8 data bits, no parity, 1 stopbit, no flow control
|
||||
term.c_cflag = baud | CS8 | CSTOPB | CLOCAL | CREAD;
|
||||
term.c_cflag = _baud | CS8 | CSTOPB | CLOCAL | CREAD;
|
||||
term.c_iflag = 0;
|
||||
term.c_oflag = 0;
|
||||
term.c_lflag = 0;
|
||||
@@ -33,20 +44,18 @@ LCDDisplay::LCDDisplay(const std::string& dev, const uint32_t baud) {
|
||||
|
||||
// clear display and set cursor home
|
||||
this->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
LCDDisplay::~LCDDisplay() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
void LCDDisplay::open(const bool reopen) {
|
||||
int LCDDisplay::open(const bool reopen) {
|
||||
applog(LOG::INF, "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) {
|
||||
applog(LOG::ERR, "Error opening serial port \"{}\"", _dev); // err
|
||||
exit(_lcd);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LCDDisplay::close() {
|
||||
|
||||
Reference in New Issue
Block a user