cursor positioning

This commit is contained in:
Martin Brodbeck 2022-05-31 12:29:45 +02:00
parent 5c68445c4d
commit efee152c5c
2 changed files with 11 additions and 1 deletions

10
lcd.cpp
View file

@ -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++;
}
}
}

2
lcd.h
View file

@ -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