From 78f24f733830ae667259d3ab94f27cf83b79098d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 24 Oct 2021 14:47:52 +0200 Subject: [PATCH] Add LCD output to shell function 'Emulate UI' --- .../include/reflow-controller/ui/gui.h | 30 ++++++++++++++++ stm-firmware/shell.c | 34 +++++++++++++++++++ stm-firmware/ui/gui.c | 17 ++++++++++ 3 files changed, 81 insertions(+) diff --git a/stm-firmware/include/reflow-controller/ui/gui.h b/stm-firmware/include/reflow-controller/ui/gui.h index a82293a..973a7eb 100644 --- a/stm-firmware/include/reflow-controller/ui/gui.h +++ b/stm-firmware/include/reflow-controller/ui/gui.h @@ -22,6 +22,7 @@ #define _GUI_H_ #include +#include /** * @brief Handle the reflow controller's LCD Menu @@ -29,10 +30,39 @@ */ int gui_handle(void); +/** + * @brief Initialize the GUI (LCD, button, and rotary encoder) + */ void gui_init(void); +/** + * @brief Set a overlay message displayed on top of the root menu + * @param heading Heading of the overlay message (1st line) + * @param text Text of the overlay (the two bottom lines, 2 times 16 chars) + */ void gui_root_menu_message_set(const char *heading, const char *text); +/** + * @brief Directly write to the LCD + * + * This function writes directly to the LCD and doesn't use the handling FSM in the + * background. Therefore, the function will block until all data is written to the LCD. + * + * @param line line to write to. Starts at 0 + * @param text Text to write to the line + */ void gui_lcd_write_direct_blocking(uint8_t line, const char *text); +/** + * @brief Get the vertical size of the display + * @return Count of rows + */ +size_t gui_get_line_count(void); + +/** + * @brief Return the const char disp[][21] array contianing all display rows + * @note This directly returns the working buffer pointer. Do not change it! + */ +const char (*gui_get_current_display_content(void))[21]; + #endif /* _GUI_H_ */ diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 9947da8..432ea72 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -481,6 +482,11 @@ static shellmatta_retCode_t shell_cmd_ui_emulation(const shellmatta_handle_t han uint32_t i; uint32_t len; char *buff; + uint8_t row; + uint8_t col; + bool differs = false; + static char IN_SECTION(.ccm.bss) display_buffer[4][21] = {0}; + const char (*current_display)[21]; shellmatta_read(handle, &buff, &len); @@ -509,6 +515,34 @@ static shellmatta_retCode_t shell_cmd_ui_emulation(const shellmatta_handle_t han case 'R': button_override_event(BUTTON_LONG_RELEASED); break; + case '\x03': + display_buffer[0][0] = 0; + display_buffer[1][0] = 0; + display_buffer[2][0] = 0; + display_buffer[3][0] = 0; + return SHELLMATTA_OK; + break; + } + } + + current_display = gui_get_current_display_content(); + + for (row = 0; row < 4; row++) { + for (col = 0; col < 21; col++) { + if (current_display[row][col] != display_buffer[row][col]) { + display_buffer[row][col] = current_display[row][col]; + differs = true; + } + } + display_buffer[row][20] = 0; + } + + + if (differs) { + /* Clear the display */ + shellmatta_printf(handle, "\e[2J\e[H"); + for (row = 0; row < 4; row++) { + shellmatta_printf(handle, "%s\r\n", &display_buffer[row][0]); } } diff --git a/stm-firmware/ui/gui.c b/stm-firmware/ui/gui.c index 695610b..443d4e3 100644 --- a/stm-firmware/ui/gui.c +++ b/stm-firmware/ui/gui.c @@ -815,10 +815,16 @@ int gui_handle(void) void gui_init(void) { + /** - Setup the rotary encoder input */ rotary_encoder_setup(); + + /** - Setup the push button */ button_init(); + + /** - Setup the LCD */ lcd_init(); + /** - If an overlay has been previously set, clear it */ if (overlay_heading) free(overlay_heading); if (overlay_text) @@ -827,6 +833,7 @@ void gui_init(void) overlay_heading = NULL; overlay_text = NULL; + /** - Init the GUI menu */ menu_init(reflow_menu_ptr, gui_menu_root_entry, update_display_buffer); } @@ -853,3 +860,13 @@ void gui_lcd_write_direct_blocking(uint8_t line, const char *text) lcd_setcursor(0, line); lcd_string(text); } + +size_t gui_get_line_count(void) +{ + return (size_t)LCD_ROW_COUNT; +} + +const char (*gui_get_current_display_content(void))[21] +{ + return display_buffer; +}