diff --git a/lcd.cpp b/lcd.cpp index 686ef5d..dbb1449 100644 --- a/lcd.cpp +++ b/lcd.cpp @@ -51,13 +51,21 @@ LCD::LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl, void LCD::setCursor(int line, int position) { int val = (line == 0) ? 0x80 + position : 0xC0 + position; sendByte(val, Mode::COMMAND); + cursor_x = line; + cursor_y = position; } void LCD::sendChar(char val) { sendByte(val, Mode::CHARACTER); } void LCD::sendString(const std::string &str) { for (const char &c : str) { - sendChar(c); + if (c == '\n') { + cursor_y++; + setCursor(cursor_y, 0); + } else { + sendChar(c); + cursor_x++; + } } } diff --git a/lcd.h b/lcd.h index aca2d96..df96245 100644 --- a/lcd.h +++ b/lcd.h @@ -27,6 +27,8 @@ private: uint8_t i2c_addr; uint8_t num_cols; uint8_t num_lines; + uint8_t cursor_x{0}; + uint8_t cursor_y{0}; }; #endif \ No newline at end of file