9 static const char *
const TAG =
"lcd";
12 static const uint8_t LCD_DISPLAY_COMMAND_CLEAR_DISPLAY = 0x01;
13 static const uint8_t LCD_DISPLAY_COMMAND_RETURN_HOME = 0x02;
14 static const uint8_t LCD_DISPLAY_COMMAND_ENTRY_MODE_SET = 0x04;
15 static const uint8_t LCD_DISPLAY_COMMAND_DISPLAY_CONTROL = 0x08;
16 static const uint8_t LCD_DISPLAY_COMMAND_CURSOR_SHIFT = 0x10;
17 static const uint8_t LCD_DISPLAY_COMMAND_FUNCTION_SET = 0x20;
18 static const uint8_t LCD_DISPLAY_COMMAND_SET_CGRAM_ADDR = 0x40;
19 static const uint8_t LCD_DISPLAY_COMMAND_SET_DDRAM_ADDR = 0x80;
21 static const uint8_t LCD_DISPLAY_ENTRY_SHIFT_INCREMENT = 0x01;
22 static const uint8_t LCD_DISPLAY_ENTRY_LEFT = 0x02;
24 static const uint8_t LCD_DISPLAY_DISPLAY_BLINK_ON = 0x01;
25 static const uint8_t LCD_DISPLAY_DISPLAY_CURSOR_ON = 0x02;
26 static const uint8_t LCD_DISPLAY_DISPLAY_ON = 0x04;
28 static const uint8_t LCD_DISPLAY_FUNCTION_8_BIT_MODE = 0x10;
29 static const uint8_t LCD_DISPLAY_FUNCTION_2_LINE = 0x08;
30 static const uint8_t LCD_DISPLAY_FUNCTION_5X10_DOTS = 0x04;
37 uint8_t display_function = 0;
40 display_function |= LCD_DISPLAY_FUNCTION_8_BIT_MODE;
43 display_function |= LCD_DISPLAY_FUNCTION_2_LINE;
48 const uint8_t now =
millis();
61 this->
command_(LCD_DISPLAY_COMMAND_FUNCTION_SET | display_function);
63 this->
command_(LCD_DISPLAY_COMMAND_FUNCTION_SET | display_function);
65 this->
command_(LCD_DISPLAY_COMMAND_FUNCTION_SET | display_function);
70 this->
command_(LCD_DISPLAY_COMMAND_SET_CGRAM_ADDR | (user_defined_char.first << 3));
71 for (
auto data : user_defined_char.second)
72 this->
send(data,
true);
75 this->
command_(LCD_DISPLAY_COMMAND_FUNCTION_SET | display_function);
76 uint8_t display_control = LCD_DISPLAY_DISPLAY_ON;
77 this->
command_(LCD_DISPLAY_COMMAND_DISPLAY_CONTROL | display_control);
80 this->
command_(LCD_DISPLAY_COMMAND_CLEAR_DISPLAY);
83 uint8_t entry_mode = LCD_DISPLAY_ENTRY_LEFT;
84 this->
command_(LCD_DISPLAY_COMMAND_ENTRY_MODE_SET | entry_mode);
86 this->
command_(LCD_DISPLAY_COMMAND_RETURN_HOME);
92 this->
command_(LCD_DISPLAY_COMMAND_SET_DDRAM_ADDR | 0);
94 for (uint8_t i = 0; i < this->
columns_; i++)
97 if (this->
rows_ >= 3) {
98 for (uint8_t i = 0; i < this->
columns_; i++)
99 this->
send(this->
buffer_[this->columns_ * 2 + i],
true);
102 if (this->
rows_ >= 1) {
103 this->
command_(LCD_DISPLAY_COMMAND_SET_DDRAM_ADDR | 0x40);
105 for (uint8_t i = 0; i < this->
columns_; i++)
106 this->
send(this->
buffer_[this->columns_ + i],
true);
108 if (this->
rows_ >= 4) {
109 for (uint8_t i = 0; i < this->
columns_; i++)
110 this->
send(this->
buffer_[this->columns_ * 3 + i],
true);
121 uint8_t pos = column + row * this->
columns_;
122 for (; *str !=
'\0'; str++) {
127 if (pos >= this->
rows_ * this->columns_) {
128 ESP_LOGW(TAG,
"LCDDisplay writing out of range!");
132 this->
buffer_[pos] = *
reinterpret_cast<const uint8_t *
>(str);
141 va_start(arg, format);
143 int ret = vsnprintf(buffer,
sizeof(buffer), format, arg);
146 this->
print(column, row, buffer);
150 va_start(arg, format);
152 int ret = vsnprintf(buffer,
sizeof(buffer), format, arg);
155 this->
print(0, 0, buffer);
163 size_t ret = time.
strftime(buffer,
sizeof(buffer), format);
165 this->
print(column, row, buffer);
170 this->
command_(LCD_DISPLAY_COMMAND_SET_CGRAM_ADDR | (location << 3));
171 for (
int i = 0; i < 8; i++) {
172 this->
send(charmap[i],
true);
size_t strftime(char *buffer, size_t buffer_len, const char *format)
Convert this ESPTime struct to a null-terminated c string buffer as specified by the format argument...
A more user-friendly version of struct tm from time.h.
virtual void send(uint8_t value, bool rs)=0
void void void void void loadchar(uint8_t location, uint8_t charmap[])
Load custom char to given location.
uint32_t IRAM_ATTR HOT millis()
virtual void write_n_bits(uint8_t value, uint8_t n)=0
virtual void call_writer()=0
std::map< uint8_t, std::vector< uint8_t > > user_defined_chars_
void printf(uint8_t column, uint8_t row, const char *format,...) __attribute__((format(printf
Evaluate the printf-format and print the text at the specified column and row.
const float PROCESSOR
For components that use data from sensors like displays.
void print(uint8_t column, uint8_t row, const char *str)
Print the given text at the specified column and row.
float get_setup_priority() const override
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
virtual bool is_four_bit_mode()=0
void void void strftime(uint8_t column, uint8_t row, const char *format, ESPTime time) __attribute__((format(strftime
Evaluate the strftime-format and print the text at the specified column and row.
void command_(uint8_t value)
void IRAM_ATTR HOT delay(uint32_t ms)