Skip to content

Commit a9b1e06

Browse files
committed
Implement WriteMessage for CharLCD
1 parent f06ac06 commit a9b1e06

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/components/i2c/drivers/drvOutCharLcd.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,43 @@ class drvOutCharLcd : public drvOutputBase {
7878
_enable_backlight = enable_backlight;
7979
}
8080

81+
/*!
82+
@brief Writes a message to the LCD.
83+
@param message
84+
The message to be displayed.
85+
*/
86+
void WriteMessageCharLCD(const char *message) override {
87+
if (_lcd == nullptr)
88+
return;
89+
90+
// Before writing, let's clear the display
91+
_lcd->clear();
92+
93+
size_t message_length = strlen(message);
94+
size_t cur_idx = 0; // Current index in the message
95+
96+
// Write each row until it hits: \n, or the end of the message, or the last
97+
// column/row position
98+
for (int cur_row = 0; cur_row < _rows && cur_idx < message_length;
99+
cur_row++) {
100+
// Write each row out at the beginning of the row
101+
_lcd->setCursor(0, cur_row);
102+
for (int cur_col = 0; cur_col < _cols && cur_idx < message_length;
103+
cur_col++) {
104+
char c = message[cur_idx];
105+
if (c == '\n') {
106+
cur_idx++;
107+
break;
108+
}
109+
_lcd->write(c);
110+
cur_idx++;
111+
}
112+
}
113+
}
114+
81115
protected:
82-
Adafruit_LiquidCrystal
83-
*_lcd; ///< Pointer to the Adafruit_LiquidCrystal object
116+
Adafruit_LiquidCrystal *_lcd =
117+
nullptr; ///< Pointer to the Adafruit_LiquidCrystal object
84118
uint8_t _rows = 2; ///< Number of rows in the display
85119
uint8_t _cols = 16; ///< Number of columns in the display
86120
bool _enable_backlight; ///< Flag to enable/disable backlight

src/components/i2c/drivers/drvOutputBase.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ class drvOutputBase : public drvBase {
101101
// noop
102102
}
103103

104+
/*!
105+
@brief Writes a message to the LCD.
106+
@param message
107+
The message to be displayed.
108+
*/
109+
virtual void WriteMessageCharLCD(const char *message) override {
110+
// noop
111+
}
112+
104113
/*!
105114
@brief Sets the brightness of the LED backpack.
106115
@param b

0 commit comments

Comments
 (0)