add some return values to some shit so it shuts down elegantly on crash
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
|
||||
class LCDDisplay {
|
||||
private:
|
||||
int _lcd = -1;
|
||||
uint32_t _baud = 0;
|
||||
std::string _dev;
|
||||
int lcd = -1;
|
||||
uint32_t baud = 0;
|
||||
std::string dev;
|
||||
std::array<char, LCD_LINES * LCD_COLS + 8> writebuf{}; // 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
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
/* lcd size hardcoded to 4x40 idgaf */
|
||||
LCDDisplay::LCDDisplay(const std::string& dev, const uint32_t baud) {
|
||||
_dev = dev;
|
||||
_baud = baud;
|
||||
this->dev = dev;
|
||||
this->baud = baud;
|
||||
}
|
||||
|
||||
LCDDisplay::~LCDDisplay() {
|
||||
@@ -28,19 +28,19 @@ int LCDDisplay::Init() {
|
||||
|
||||
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;
|
||||
tcflush(_lcd, TCIFLUSH);
|
||||
tcsetattr(_lcd, TCSANOW, &term);
|
||||
tcflush(lcd, TCIFLUSH);
|
||||
tcsetattr(lcd, TCSANOW, &term);
|
||||
|
||||
// init linebuf to spaces
|
||||
this->clearBuf();
|
||||
|
||||
// disable underline and block cursor
|
||||
constexpr uint8_t cmdbuf[] = {254, 75, 254, 84};
|
||||
::write(_lcd, &cmdbuf, sizeof(cmdbuf));
|
||||
::write(lcd, &cmdbuf, sizeof(cmdbuf));
|
||||
|
||||
// clear display and set cursor home
|
||||
this->clear();
|
||||
@@ -48,26 +48,26 @@ int LCDDisplay::Init() {
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LCDDisplay::close() {
|
||||
if (_lcd >= 0) {
|
||||
::close(_lcd);
|
||||
if (lcd >= 0) {
|
||||
::close(lcd);
|
||||
applog(LOG::INF, "LCD port closed");
|
||||
}
|
||||
_lcd = -1;
|
||||
lcd = -1;
|
||||
}
|
||||
|
||||
void LCDDisplay::write(const uint8_t* cmdbuf, const uint8_t len) {
|
||||
if (::write(_lcd, cmdbuf, len) != len) {
|
||||
if (::write(lcd, cmdbuf, len) != len) {
|
||||
applog(LOG::ERR, "failed to execute ::write, lost access to port?");
|
||||
this->open(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user