114 lines
2.3 KiB
C++
114 lines
2.3 KiB
C++
#include "char_lcd.h"
|
|
|
|
#include "./i2c_lcd_pcf8574.h"
|
|
#include <esp_log.h>
|
|
|
|
i2c_lcd_pcf8574_handle_t lcd;
|
|
|
|
static const char *TAG = "char_lcd";
|
|
|
|
/// Initializes the 2004 Character LCD
|
|
void init_char_lcd(void) {
|
|
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
|
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
|
|
|
lcd_set_backlight(&lcd, 255);
|
|
|
|
ESP_LOGI(TAG, "LCD initialized");
|
|
}
|
|
|
|
|
|
/// Clear the LCD
|
|
void lcd_clear() {
|
|
lcd_clear(&lcd);
|
|
}
|
|
|
|
/// Move cursor to home position
|
|
void lcd_cursor_home() {
|
|
lcd_home(&lcd);
|
|
}
|
|
|
|
/// Set cursor position
|
|
void lcd_set_cursor_pos(uint8_t col, uint8_t row) {
|
|
lcd_set_cursor(&lcd, col, row);
|
|
}
|
|
|
|
/// Turn the display on/off
|
|
void lcd_set_display(bool display) {
|
|
if (display) {
|
|
lcd_display(&lcd);
|
|
} else {
|
|
lcd_no_display(&lcd);
|
|
}
|
|
}
|
|
|
|
/// Turn the cursor's visibility on/off
|
|
void lcd_set_cursor_vis(bool cursor) {
|
|
if (cursor) {
|
|
lcd_cursor(&lcd);
|
|
} else {
|
|
lcd_no_cursor(&lcd);
|
|
}
|
|
}
|
|
|
|
/// Turn blinking cursor on/off
|
|
void lcd_set_cursor_blink(bool blink) {
|
|
if (blink) {
|
|
lcd_blink(&lcd);
|
|
} else {
|
|
lcd_no_blink(&lcd);
|
|
}
|
|
}
|
|
|
|
/// Scroll the display left
|
|
void lcd_scroll_display_left() {
|
|
lcd_scroll_display_left(&lcd);
|
|
}
|
|
/// Scroll the display right
|
|
void lcd_scroll_display_right() {
|
|
lcd_scroll_display_right(&lcd);
|
|
}
|
|
|
|
/// Set the text to flows automatically left to right
|
|
void lcd_left_to_right() {
|
|
lcd_left_to_right(&lcd);
|
|
}
|
|
/// Set the text to flows automatically right to left
|
|
void lcd_right_to_left() {
|
|
lcd_right_to_left(&lcd);
|
|
}
|
|
|
|
// Turn on/off autoscroll
|
|
void lcd_set_autoscroll(bool autoscroll) {
|
|
if (autoscroll) {
|
|
lcd_autoscroll(&lcd);
|
|
} else {
|
|
lcd_no_autoscroll(&lcd);
|
|
}
|
|
}
|
|
|
|
// Set backlight brightness
|
|
void lcd_set_backlight(uint8_t brightness) {
|
|
lcd_set_backlight(&lcd, brightness);
|
|
}
|
|
|
|
// Create a custom character
|
|
void lcd_create_char(uint8_t location, uint8_t charmap[]) {
|
|
lcd_create_char(&lcd, location, charmap);
|
|
}
|
|
|
|
// Write a character to the LCD
|
|
void lcd_write(uint8_t value) {
|
|
lcd_write(&lcd, value);
|
|
}
|
|
|
|
// Print a string to the LCD
|
|
void lcd_print(const char* str) {
|
|
lcd_print(&lcd, str);
|
|
}
|
|
|
|
// Print a string to the LCD at a given pos
|
|
void lcd_print(uint8_t col, uint8_t row, const char* str) {
|
|
lcd_set_cursor_pos(col, row);
|
|
lcd_print(&lcd, str);
|
|
} |