add a mutex for the char_lcd
This commit is contained in:
parent
202b926eb7
commit
92d448020c
@ -9,6 +9,7 @@
|
|||||||
#include "game_info.h"
|
#include "game_info.h"
|
||||||
|
|
||||||
i2c_lcd_pcf8574_handle_t lcd;
|
i2c_lcd_pcf8574_handle_t lcd;
|
||||||
|
SemaphoreHandle_t lcd_mutex;
|
||||||
|
|
||||||
static volatile bool header_enabled = false;
|
static volatile bool header_enabled = false;
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ static const char* EMPTY_ROW = " ";
|
|||||||
|
|
||||||
static char buf[65];
|
static char buf[65];
|
||||||
|
|
||||||
|
// TODO: move this to power.cpp
|
||||||
static void monitor_battery_task(void* _arg) {
|
static void monitor_battery_task(void* _arg) {
|
||||||
(void) _arg;
|
(void) _arg;
|
||||||
|
|
||||||
@ -29,53 +31,35 @@ static void monitor_battery_task(void* _arg) {
|
|||||||
static bool replay_handler(const char* event, char* arg) {
|
static bool replay_handler(const char* event, char* arg) {
|
||||||
if (strcmp(event, "LCD_CLEAR") == 0) {
|
if (strcmp(event, "LCD_CLEAR") == 0) {
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CURSOR") == 0) {
|
else if (strcmp(event, "LCD_SET_DISPLAY") == 0) {
|
||||||
char* col_str = strtok(arg, ",");
|
|
||||||
char* row_str = strtok(NULL, ",");
|
|
||||||
uint32_t col = atoi(col_str);
|
|
||||||
uint32_t row = atoi(row_str);
|
|
||||||
lcd_set_cursor_pos(col, row);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (strcmp(event, "LCD_SET_DISPLAY") == 0) {
|
|
||||||
lcd_set_display(strcmp(arg, "true") == 0);
|
lcd_set_display(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CURSOR_VIS") == 0) {
|
else if (strcmp(event, "LCD_CURSOR_VIS") == 0) {
|
||||||
lcd_set_cursor_vis(strcmp(arg, "true") == 0);
|
lcd_set_cursor_vis(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CURSOR_BLINK") == 0) {
|
else if (strcmp(event, "LCD_CURSOR_BLINK") == 0) {
|
||||||
lcd_set_cursor_blink(strcmp(arg, "true") == 0);
|
lcd_set_cursor_blink(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_SCROLL_DISPLAY_LEFT") == 0) {
|
else if (strcmp(event, "LCD_SCROLL_DISPLAY_LEFT") == 0) {
|
||||||
lcd_scroll_display_left();
|
lcd_scroll_display_left();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_SCROLL_DISPLAY_RIGHT") == 0) {
|
else if (strcmp(event, "LCD_SCROLL_DISPLAY_RIGHT") == 0) {
|
||||||
lcd_scroll_display_right();
|
lcd_scroll_display_right();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_LEFT_TO_RIGHT") == 0) {
|
else if (strcmp(event, "LCD_LEFT_TO_RIGHT") == 0) {
|
||||||
lcd_left_to_right();
|
lcd_left_to_right();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_RIGHT_TO_LEFT") == 0) {
|
else if (strcmp(event, "LCD_RIGHT_TO_LEFT") == 0) {
|
||||||
lcd_right_to_left();
|
lcd_right_to_left();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_AUTOSCROLL") == 0) {
|
else if (strcmp(event, "LCD_AUTOSCROLL") == 0) {
|
||||||
lcd_set_autoscroll(strcmp(arg, "true") == 0);
|
lcd_set_autoscroll(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_BACKLIGHT") == 0) {
|
else if (strcmp(event, "LCD_BACKLIGHT") == 0) {
|
||||||
lcd_set_backlight(strcmp(arg, "true") == 0);
|
lcd_set_backlight(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CREATE_CHAR") == 0) {
|
else if (strcmp(event, "LCD_CREATE_CHAR") == 0) {
|
||||||
char* location_str = strtok(arg, ",");
|
char* location_str = strtok(arg, ",");
|
||||||
uint8_t location = atoi(location_str);
|
uint8_t location = atoi(location_str);
|
||||||
|
|
||||||
@ -86,24 +70,33 @@ static bool replay_handler(const char* event, char* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lcd_create_char(location, charmap);
|
lcd_create_char(location, charmap);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_PRINT") == 0) {
|
else if (strcmp(event, "LCD_PRINT") == 0) {
|
||||||
|
char* str = strtok(arg, ",");
|
||||||
|
uint8_t col = atoi(str);
|
||||||
|
str = strtok(NULL, ",");
|
||||||
|
uint8_t row = atoi(str);
|
||||||
|
// get remaining part of string.
|
||||||
|
str = strtok(NULL, "");
|
||||||
|
|
||||||
// TODO: handle \r and \n
|
// TODO: handle \r and \n
|
||||||
lcd_print(&lcd, arg);
|
lcd_print(col, row, str);
|
||||||
return true;
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_lcd() {
|
void init_lcd() {
|
||||||
ESP_LOGI(TAG, "Initializing LCD...");
|
ESP_LOGI(TAG, "Initializing LCD...");
|
||||||
|
|
||||||
|
lcd_mutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
||||||
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
||||||
|
|
||||||
lcd_set_backlight(&lcd, 255);
|
lcd_set_backlight(&lcd, true);
|
||||||
|
|
||||||
register_replay_fn(replay_handler);
|
register_replay_fn(replay_handler);
|
||||||
|
|
||||||
@ -112,115 +105,122 @@ void init_lcd() {
|
|||||||
ESP_LOGI(TAG, "LCD initialized!");
|
ESP_LOGI(TAG, "LCD initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_clear() {
|
void lcd_clear(bool no_lock) {
|
||||||
if (!header_enabled) {
|
if (!header_enabled) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_clear(&lcd);
|
lcd_clear(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_CLEAR", NULL);
|
event_occured("LCD_CLEAR", NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lcd_print(0, 1, EMPTY_ROW);
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_print(0, 2, EMPTY_ROW);
|
lcd_print(0, 1, EMPTY_ROW, true);
|
||||||
lcd_print(0, 3, EMPTY_ROW);
|
lcd_print(0, 2, EMPTY_ROW, true);
|
||||||
|
lcd_print(0, 3, EMPTY_ROW, true);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rm
|
void lcd_set_display(bool display, bool no_lock) {
|
||||||
void lcd_cursor_home() {
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_set_cursor_pos(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: with print requiring you to set a pos every time, this function is not helpful
|
|
||||||
void lcd_set_cursor_pos(uint8_t col, uint8_t row) {
|
|
||||||
lcd_set_cursor(&lcd, col, row);
|
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
|
||||||
sprintf(buf, "%d,%d", col, row);
|
|
||||||
event_occured("LCD_CURSOR", buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcd_set_display(bool display) {
|
|
||||||
if (display) {
|
if (display) {
|
||||||
lcd_display(&lcd);
|
lcd_display(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_display(&lcd);
|
lcd_no_display(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_SET_DISPLAY", display ? "true" : "false");
|
event_occured("LCD_SET_DISPLAY", display ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_cursor_vis(bool cursor) {
|
void lcd_set_cursor_vis(bool cursor, bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
lcd_cursor(&lcd);
|
lcd_cursor(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_cursor(&lcd);
|
lcd_no_cursor(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_CURSOR_VIS", cursor ? "true" : "false");
|
event_occured("LCD_CURSOR_VIS", cursor ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_cursor_blink(bool blink) {
|
void lcd_set_cursor_blink(bool blink, bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
if (blink) {
|
if (blink) {
|
||||||
lcd_blink(&lcd);
|
lcd_blink(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_blink(&lcd);
|
lcd_no_blink(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_CURSOR_BLINK", blink ? "true" : "false");
|
event_occured("LCD_CURSOR_BLINK", blink ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_scroll_display_left() {
|
void lcd_scroll_display_left(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_scroll_display_left(&lcd);
|
lcd_scroll_display_left(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_SCROLL_DISPLAY_LEFT", NULL);
|
event_occured("LCD_SCROLL_DISPLAY_LEFT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void lcd_scroll_display_right() {
|
void lcd_scroll_display_right(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_scroll_display_right(&lcd);
|
lcd_scroll_display_right(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_SCROLL_DISPLAY_RIGHT", NULL);
|
event_occured("LCD_SCROLL_DISPLAY_RIGHT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_left_to_right() {
|
void lcd_left_to_right(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_left_to_right(&lcd);
|
lcd_left_to_right(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_LEFT_TO_RIGHT", NULL);
|
event_occured("LCD_LEFT_TO_RIGHT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void lcd_right_to_left() {
|
void lcd_right_to_left(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_right_to_left(&lcd);
|
lcd_right_to_left(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_RIGHT_TO_LEFT", NULL);
|
event_occured("LCD_RIGHT_TO_LEFT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_autoscroll(bool autoscroll) {
|
void lcd_set_autoscroll(bool autoscroll, bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
if (autoscroll) {
|
if (autoscroll) {
|
||||||
lcd_autoscroll(&lcd);
|
lcd_autoscroll(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_autoscroll(&lcd);
|
lcd_no_autoscroll(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_AUTOSCROLL", autoscroll ? "true" : "false");
|
event_occured("LCD_AUTOSCROLL", autoscroll ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_backlight(bool backlight) {
|
void lcd_set_backlight(bool backlight, bool no_lock) {
|
||||||
lcd_set_backlight(&lcd, backlight);
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
|
lcd_set_backlight_to(&lcd, backlight);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
sprintf(buf, "%d", backlight);
|
sprintf(buf, "%d", backlight);
|
||||||
@ -228,8 +228,10 @@ void lcd_set_backlight(bool backlight) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_create_char(uint8_t location, const uint8_t charmap[]) {
|
void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_create_char(&lcd, location, charmap);
|
lcd_create_char(&lcd, location, charmap);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
snprintf(buf, 65,
|
snprintf(buf, 65,
|
||||||
@ -241,13 +243,16 @@ void lcd_create_char(uint8_t location, const uint8_t charmap[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: switch to row, col
|
// TODO: switch to row, col
|
||||||
void lcd_print(uint8_t col, uint8_t row, const char* str) {
|
void lcd_print(uint8_t col, uint8_t row, const char* str, bool no_lock) {
|
||||||
lcd_set_cursor_pos(col, row);
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
|
lcd_set_cursor(&lcd, col, row);
|
||||||
lcd_print(&lcd, str);
|
lcd_print(&lcd, str);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
// TODO: handle \r and \n
|
// TODO: handle \r and \n and others
|
||||||
event_occured("LCD_PRINT", str);
|
snprintf(buf, sizeof(buf), "%d,%d,%s", col, row, str);
|
||||||
|
event_occured("LCD_PRINT", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,13 +289,15 @@ void lcd_do_splash() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: make the lcd_lib somehow support the custom character 0 which would otherwise be a null terminator
|
// TODO: make the lcd_lib somehow support the custom character 0 which would otherwise be a null terminator
|
||||||
lcd_create_char(1, custom_char[0]);
|
xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_create_char(2, custom_char[1]);
|
lcd_create_char(1, custom_char[0], true);
|
||||||
lcd_create_char(3, custom_char[2]);
|
lcd_create_char(2, custom_char[1], true);
|
||||||
lcd_create_char(4, custom_char[3]);
|
lcd_create_char(3, custom_char[2], true);
|
||||||
lcd_create_char(5, custom_char[4]);
|
lcd_create_char(4, custom_char[3], true);
|
||||||
lcd_create_char(6, custom_char[5]);
|
lcd_create_char(5, custom_char[4], true);
|
||||||
|
lcd_create_char(6, custom_char[5], true);
|
||||||
|
|
||||||
lcd_print(6, 1, "\x01\x02Marino");
|
lcd_print(6, 1, "\x01\x02Marino", true);
|
||||||
lcd_print(5, 2, "\x03\x04\x05\x06""DEV");
|
lcd_print(5, 2, "\x03\x04\x05\x06""DEV", true);
|
||||||
|
xSemaphoreGive(lcd_mutex);
|
||||||
}
|
}
|
||||||
@ -9,51 +9,50 @@
|
|||||||
#define LCD_COLS 20
|
#define LCD_COLS 20
|
||||||
#define LCD_ROWS 4
|
#define LCD_ROWS 4
|
||||||
|
|
||||||
/// Initializes the 2004 Character LCD
|
/// @brief Initializes the 2004 Character LCD
|
||||||
void init_lcd();
|
void init_lcd();
|
||||||
|
|
||||||
/// Clear the LCD
|
/// @brief Clear the LCD
|
||||||
void lcd_clear();
|
void lcd_clear(bool no_lock = false);
|
||||||
|
|
||||||
/// Move cursor to home position
|
/// @brief Move cursor to home position
|
||||||
void lcd_cursor_home();
|
void lcd_cursor_home(bool no_lock = false);
|
||||||
|
|
||||||
/// Set cursor position
|
/// @brief Turn the display on/off
|
||||||
void lcd_set_cursor_pos(uint8_t col, uint8_t row);
|
void lcd_set_display(bool display, bool no_lock = false);
|
||||||
|
|
||||||
/// Turn the display on/off
|
/// @brief Turn the cursor's visibility on/off
|
||||||
void lcd_set_display(bool display);
|
void lcd_set_cursor_vis(bool cursor, bool no_lock = false);
|
||||||
|
|
||||||
/// Turn the cursor's visibility on/off
|
/// @brief Turn blinking cursor on/off
|
||||||
void lcd_set_cursor_vis(bool cursor);
|
void lcd_set_cursor_blink(bool blink, bool no_lock = false);
|
||||||
|
|
||||||
/// Turn blinking cursor on/off
|
/// @brief Scroll the display left
|
||||||
void lcd_set_cursor_blink(bool blink);
|
void lcd_scroll_display_left(bool no_lock = false);
|
||||||
|
/// @brief Scroll the display right
|
||||||
|
void lcd_scroll_display_right(bool no_lock = false);
|
||||||
|
|
||||||
/// Scroll the display left
|
/// @brief Set the text to flows automatically left to right
|
||||||
void lcd_scroll_display_left();
|
void lcd_left_to_right(bool no_lock = false);
|
||||||
/// Scroll the display right
|
/// @brief Set the text to flows automatically right to left
|
||||||
void lcd_scroll_display_right();
|
void lcd_right_to_left(bool no_lock = false);
|
||||||
|
|
||||||
/// Set the text to flows automatically left to right
|
/// @brief Turn on/off autoscroll
|
||||||
void lcd_left_to_right();
|
void lcd_set_autoscroll(bool autoscroll, bool no_lock = false);
|
||||||
/// Set the text to flows automatically right to left
|
|
||||||
void lcd_right_to_left();
|
|
||||||
|
|
||||||
// Turn on/off autoscroll
|
/// @brief Set backlight brightness
|
||||||
void lcd_set_autoscroll(bool autoscroll);
|
void lcd_set_backlight(bool backlight, bool no_lock = false);
|
||||||
|
|
||||||
// Set backlight brightness
|
/// @brief Create a custom character. You get 8 custom characters.
|
||||||
void lcd_set_backlight(bool backlight);
|
/// You can print custom characters by using escape characters in strings:
|
||||||
|
/// use '\x01' - '\x07' for custom characters 1-7. Use '\x08' for custom char 0.
|
||||||
// Create a custom character
|
void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock = false);
|
||||||
void lcd_create_char(uint8_t location, const uint8_t charmap[]);
|
|
||||||
|
|
||||||
/// @brief Print a string to the LCD at a given pos.
|
/// @brief Print a string to the LCD at a given pos.
|
||||||
/// @param col the column to print the string at.
|
/// @param col the column to print the string at.
|
||||||
/// @param row the row the print the string at.
|
/// @param row the row the print the string at.
|
||||||
/// @param str the string to print.
|
/// @param str the string to print.
|
||||||
void lcd_print(uint8_t col, uint8_t row, const char* str);
|
void lcd_print(uint8_t col, uint8_t row, const char* str, bool no_lock = false);
|
||||||
|
|
||||||
/// @brief Enables or disables the header on the LCD.
|
/// @brief Enables or disables the header on the LCD.
|
||||||
/// @param enable `true` to enable the header, `false` to disable.
|
/// @param enable `true` to enable the header, `false` to disable.
|
||||||
@ -69,4 +68,13 @@ void lcd_print_header();
|
|||||||
/// @brief Prints the splash screen for the BLK_BOX.
|
/// @brief Prints the splash screen for the BLK_BOX.
|
||||||
void lcd_do_splash();
|
void lcd_do_splash();
|
||||||
|
|
||||||
|
/// @brief Locks the LCD to allow chaining multiple commands without interuptions.
|
||||||
|
///
|
||||||
|
/// Commands you call while you lock the LCD, you must call with the `no_lock` flag set to true.
|
||||||
|
void lcd_lock();
|
||||||
|
|
||||||
|
/// @brief Unlocks the LCD to give away the mutex access to it.
|
||||||
|
void lcd_unlock();
|
||||||
|
|
||||||
|
|
||||||
#endif /* CHAR_LCD_H */
|
#endif /* CHAR_LCD_H */
|
||||||
@ -233,7 +233,7 @@ void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd) {
|
|||||||
|
|
||||||
// Setting the backlight: It can only be turn on or off.
|
// Setting the backlight: It can only be turn on or off.
|
||||||
// Current backlight value is saved in the i2c_lcd_pcf8574_handle_t struct for further data transfers
|
// Current backlight value is saved in the i2c_lcd_pcf8574_handle_t struct for further data transfers
|
||||||
void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness) {
|
void lcd_set_backlight_to(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness) {
|
||||||
// Place the backlight value in the lcd struct
|
// Place the backlight value in the lcd struct
|
||||||
lcd->backlight = brightness;
|
lcd->backlight = brightness;
|
||||||
// Send no data
|
// Send no data
|
||||||
@ -258,7 +258,12 @@ void lcd_write(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value) {
|
|||||||
// Print characters to the LCD: cursor set or clear instruction must preceded this instruction, or it will write on the current text.
|
// Print characters to the LCD: cursor set or clear instruction must preceded this instruction, or it will write on the current text.
|
||||||
void lcd_print(i2c_lcd_pcf8574_handle_t* lcd, const char* str) {
|
void lcd_print(i2c_lcd_pcf8574_handle_t* lcd, const char* str) {
|
||||||
while (*str) {
|
while (*str) {
|
||||||
lcd_write(lcd, *str++);
|
if (*str == '\x08') {
|
||||||
|
lcd_write(lcd, '\x00');
|
||||||
|
*str++;
|
||||||
|
} else {
|
||||||
|
lcd_write(lcd, *str++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // lcd_print()
|
} // lcd_print()
|
||||||
|
|
||||||
@ -296,18 +301,17 @@ void lcd_print_number(i2c_lcd_pcf8574_handle_t* lcd, uint8_t col, uint8_t row, u
|
|||||||
|
|
||||||
// Private functions: derived from the esp32 i2c_master driver
|
// Private functions: derived from the esp32 i2c_master driver
|
||||||
|
|
||||||
|
|
||||||
static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data) {
|
static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data) {
|
||||||
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
i2c_master_start(cmd);
|
i2c_master_start(cmd);
|
||||||
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
lcd_write_nibble(lcd, (value >> 4 & 0x0F), is_data, cmd);
|
lcd_write_nibble(lcd, (value >> 4 & 0x0F), is_data, cmd);
|
||||||
lcd_write_nibble(lcd, (value & 0x0F), is_data, cmd);
|
lcd_write_nibble(lcd, (value & 0x0F), is_data, cmd);
|
||||||
i2c_master_stop(cmd);
|
i2c_master_stop(cmd);
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
||||||
i2c_cmd_link_delete(cmd);
|
|
||||||
xSemaphoreGive(main_i2c_mutex);
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send data to LCD: %s", esp_err_to_name(ret));
|
ESP_LOGE(TAG, "Failed to send data to LCD: %s", esp_err_to_name(ret));
|
||||||
@ -330,8 +334,10 @@ static void lcd_write_nibble(i2c_lcd_pcf8574_handle_t* lcd, uint8_t half_byte, b
|
|||||||
if (half_byte & 0x04) data |= lcd->data_mask[2];
|
if (half_byte & 0x04) data |= lcd->data_mask[2];
|
||||||
if (half_byte & 0x08) data |= lcd->data_mask[3];
|
if (half_byte & 0x08) data |= lcd->data_mask[3];
|
||||||
|
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
i2c_master_write_byte(cmd, data | lcd->enable_mask, true);
|
i2c_master_write_byte(cmd, data | lcd->enable_mask, true);
|
||||||
i2c_master_write_byte(cmd, data, true);
|
i2c_master_write_byte(cmd, data, true);
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
} // lcd_write_nibble()
|
} // lcd_write_nibble()
|
||||||
|
|
||||||
// Private function to change the PCF8574 pins to the given value.
|
// Private function to change the PCF8574 pins to the given value.
|
||||||
@ -346,15 +352,15 @@ static void lcd_write_i2c(i2c_lcd_pcf8574_handle_t* lcd, uint8_t data, bool is_d
|
|||||||
data |= lcd->backlight_mask;
|
data |= lcd->backlight_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
i2c_master_start(cmd);
|
i2c_master_start(cmd);
|
||||||
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
i2c_master_write_byte(cmd, data, true);
|
i2c_master_write_byte(cmd, data, true);
|
||||||
i2c_master_stop(cmd);
|
i2c_master_stop(cmd);
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
||||||
i2c_cmd_link_delete(cmd);
|
|
||||||
xSemaphoreGive(main_i2c_mutex);
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to write to LCD: %s", esp_err_to_name(ret));
|
ESP_LOGE(TAG, "Failed to write to LCD: %s", esp_err_to_name(ret));
|
||||||
|
|||||||
@ -91,7 +91,7 @@ void lcd_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
|
|||||||
void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
|
void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
|
||||||
|
|
||||||
// Set backlight brightness
|
// Set backlight brightness
|
||||||
void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness);
|
void lcd_set_backlight_to(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness);
|
||||||
|
|
||||||
// Create a custom character
|
// Create a custom character
|
||||||
void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, const uint8_t charmap[]);
|
void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, const uint8_t charmap[]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user