Add LCD output to shell function 'Emulate UI'
This commit is contained in:
		@@ -22,6 +22,7 @@
 | 
				
			|||||||
#define _GUI_H_
 | 
					#define _GUI_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					#include <stddef.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @brief Handle the reflow controller's LCD Menu
 | 
					 * @brief Handle the reflow controller's LCD Menu
 | 
				
			||||||
@@ -29,10 +30,39 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
int gui_handle(void);
 | 
					int gui_handle(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @brief Initialize the GUI (LCD, button, and rotary encoder)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
void gui_init(void);
 | 
					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);
 | 
					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);
 | 
					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_ */
 | 
					#endif /* _GUI_H_ */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,7 @@
 | 
				
			|||||||
#include <reflow-controller/updater/updater.h>
 | 
					#include <reflow-controller/updater/updater.h>
 | 
				
			||||||
#include <reflow-controller/main-cycle-counter.h>
 | 
					#include <reflow-controller/main-cycle-counter.h>
 | 
				
			||||||
#include <stm-periph/option-bytes.h>
 | 
					#include <stm-periph/option-bytes.h>
 | 
				
			||||||
 | 
					#include <reflow-controller/ui/gui.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -481,6 +482,11 @@ static shellmatta_retCode_t shell_cmd_ui_emulation(const shellmatta_handle_t han
 | 
				
			|||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
	uint32_t len;
 | 
						uint32_t len;
 | 
				
			||||||
	char *buff;
 | 
						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);
 | 
						shellmatta_read(handle, &buff, &len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -509,6 +515,34 @@ static shellmatta_retCode_t shell_cmd_ui_emulation(const shellmatta_handle_t han
 | 
				
			|||||||
		case 'R':
 | 
							case 'R':
 | 
				
			||||||
			button_override_event(BUTTON_LONG_RELEASED);
 | 
								button_override_event(BUTTON_LONG_RELEASED);
 | 
				
			||||||
			break;
 | 
								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]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -815,10 +815,16 @@ int gui_handle(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void gui_init(void)
 | 
					void gui_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						/** - Setup the rotary encoder input */
 | 
				
			||||||
	rotary_encoder_setup();
 | 
						rotary_encoder_setup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** - Setup the push button */
 | 
				
			||||||
	button_init();
 | 
						button_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** - Setup the LCD */
 | 
				
			||||||
	lcd_init();
 | 
						lcd_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** - If an overlay has been previously set, clear it */
 | 
				
			||||||
	if (overlay_heading)
 | 
						if (overlay_heading)
 | 
				
			||||||
		free(overlay_heading);
 | 
							free(overlay_heading);
 | 
				
			||||||
	if (overlay_text)
 | 
						if (overlay_text)
 | 
				
			||||||
@@ -827,6 +833,7 @@ void gui_init(void)
 | 
				
			|||||||
	overlay_heading = NULL;
 | 
						overlay_heading = NULL;
 | 
				
			||||||
	overlay_text = NULL;
 | 
						overlay_text = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** - Init the GUI menu */
 | 
				
			||||||
	menu_init(reflow_menu_ptr, gui_menu_root_entry, update_display_buffer);
 | 
						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_setcursor(0, line);
 | 
				
			||||||
	lcd_string(text);
 | 
						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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user