cursor positioning
This commit is contained in:
parent
5c68445c4d
commit
efee152c5c
2 changed files with 11 additions and 1 deletions
10
lcd.cpp
10
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) {
|
void LCD::setCursor(int line, int position) {
|
||||||
int val = (line == 0) ? 0x80 + position : 0xC0 + position;
|
int val = (line == 0) ? 0x80 + position : 0xC0 + position;
|
||||||
sendByte(val, Mode::COMMAND);
|
sendByte(val, Mode::COMMAND);
|
||||||
|
cursor_x = line;
|
||||||
|
cursor_y = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCD::sendChar(char val) { sendByte(val, Mode::CHARACTER); }
|
void LCD::sendChar(char val) { sendByte(val, Mode::CHARACTER); }
|
||||||
|
|
||||||
void LCD::sendString(const std::string &str) {
|
void LCD::sendString(const std::string &str) {
|
||||||
for (const char &c : 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
2
lcd.h
|
@ -27,6 +27,8 @@ private:
|
||||||
uint8_t i2c_addr;
|
uint8_t i2c_addr;
|
||||||
uint8_t num_cols;
|
uint8_t num_cols;
|
||||||
uint8_t num_lines;
|
uint8_t num_lines;
|
||||||
|
uint8_t cursor_x{0};
|
||||||
|
uint8_t cursor_y{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue