Issue #28: Start GUI for Temp Profile execution
This commit is contained in:
		@@ -36,6 +36,7 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
#include <reflow-controller/oven-driver.h>
 | 
			
		||||
#include <fatfs/ff.h>
 | 
			
		||||
 | 
			
		||||
static char IN_SECTION(.ccm.bss) display_buffer[4][21] = {0};
 | 
			
		||||
static struct lcd_menu IN_SECTION(.ccm.bss) reflow_menu;
 | 
			
		||||
@@ -198,7 +199,7 @@ static void gui_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry ent
 | 
			
		||||
			uptime_secs = new_uptime_secs;
 | 
			
		||||
			menu_lcd_output(menu, 0, "Uptime:");
 | 
			
		||||
			menu_lcd_outputf(menu, 1, "%lu day%s %02lu:%02lu:%02lu",
 | 
			
		||||
				 uptime_days, (uptime_days == 1 ? "" : "s"), uptime_hours, uptime_mins, uptime_secs);
 | 
			
		||||
					 uptime_days, (uptime_days == 1 ? "" : "s"), uptime_hours, uptime_mins, uptime_secs);
 | 
			
		||||
			menu_lcd_output(menu, 3, "Page 5/5");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -215,7 +216,7 @@ static void gui_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry ent
 | 
			
		||||
		button_ready = true;
 | 
			
		||||
 | 
			
		||||
	if (button_ready &&
 | 
			
		||||
		(push_button == BUTTON_SHORT_RELEASED || push_button == BUTTON_LONG)) {
 | 
			
		||||
			(push_button == BUTTON_SHORT_RELEASED || push_button == BUTTON_LONG)) {
 | 
			
		||||
		menu_entry_dropback(menu, my_parent);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -372,6 +373,98 @@ static void gui_menu_constant_temperature_driver(struct lcd_menu *menu, enum men
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief load_temperature_file_list_from_sdcard
 | 
			
		||||
 * @return -1 File error, 0 successful
 | 
			
		||||
 */
 | 
			
		||||
static int load_temperature_file_list_from_sdcard(char (*list)[17], uint32_t len)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t i, j;
 | 
			
		||||
	DIR directory;
 | 
			
		||||
	FILINFO finfo;
 | 
			
		||||
	FRESULT fres;
 | 
			
		||||
 | 
			
		||||
	if (!list)
 | 
			
		||||
		return -1001;
 | 
			
		||||
 | 
			
		||||
	/* Zero out the list */
 | 
			
		||||
	for (i = 0; i < len; i++) {
 | 
			
		||||
		for (j = 0; j < sizeof(*list); j++) {
 | 
			
		||||
			list[i][j] = 0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* find the frist file */
 | 
			
		||||
	fres = f_findfirst(&directory, &finfo, "/", "*.tpr");
 | 
			
		||||
	i = 0;
 | 
			
		||||
	while (fres == FR_OK && finfo.fname[0]) {
 | 
			
		||||
		strncpy(list[i], finfo.fname, sizeof(*list));
 | 
			
		||||
		fres = f_findnext(&directory, &finfo);
 | 
			
		||||
		i++;
 | 
			
		||||
		if (i >= len)
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (fres != FR_OK) {
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (int)i;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
 | 
			
		||||
{
 | 
			
		||||
	static void *my_parent;
 | 
			
		||||
	static char profile_list[10][17];
 | 
			
		||||
	static bool file_error = false;
 | 
			
		||||
	static uint8_t currently_selected = 0U;
 | 
			
		||||
	static uint8_t current_scroll_offset = 0U;
 | 
			
		||||
	static uint8_t loaded;
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	if (entry_type == MENU_ENTRY_FIRST_ENTER) {
 | 
			
		||||
		menu_display_clear(menu);
 | 
			
		||||
		my_parent = parent;
 | 
			
		||||
		res = load_temperature_file_list_from_sdcard(profile_list, 10);
 | 
			
		||||
		file_error = false;
 | 
			
		||||
		loaded = 0;
 | 
			
		||||
		if (res < 0) {
 | 
			
		||||
			file_error = true;
 | 
			
		||||
		}
 | 
			
		||||
		current_scroll_offset = 0u;
 | 
			
		||||
		currently_selected = 0u;
 | 
			
		||||
		loaded = (uint32_t)res;
 | 
			
		||||
		menu_lcd_outputf(menu, 0, "Select:");
 | 
			
		||||
	} else if (entry_type == MENU_ENTRY_DROPBACK) {
 | 
			
		||||
		menu_entry_dropback(menu, my_parent);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (menu_get_button_ready_state(menu)) {
 | 
			
		||||
		if (menu_get_button_state(menu) == BUTTON_LONG) {
 | 
			
		||||
			menu_entry_dropback(menu, my_parent);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (file_error) {
 | 
			
		||||
			menu_lcd_outputf(menu, 0, "Disk Error");
 | 
			
		||||
			menu_lcd_outputf(menu, 1, "SD inserted?");
 | 
			
		||||
			if (menu_get_button_state(menu) == BUTTON_SHORT_RELEASED)
 | 
			
		||||
				menu_entry_dropback(menu, my_parent);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (loaded == 0) {
 | 
			
		||||
			menu_lcd_outputf(menu, 0, "No profiles");
 | 
			
		||||
			menu_lcd_outputf(menu, 1, "found");
 | 
			
		||||
			if (menu_get_button_state(menu) == BUTTON_SHORT_RELEASED)
 | 
			
		||||
				menu_entry_dropback(menu, my_parent);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void gui_menu_constant_temperature_driver_setup(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
 | 
			
		||||
{
 | 
			
		||||
	static void IN_SECTION(.ccm.bss) *my_parent;
 | 
			
		||||
@@ -412,6 +505,7 @@ static void gui_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_entr
 | 
			
		||||
	bool menu_changed = false;
 | 
			
		||||
	static const char * const root_entry_names[] = {
 | 
			
		||||
		"Constant Temp",
 | 
			
		||||
		"Temp Profile",
 | 
			
		||||
		"Monitoring",
 | 
			
		||||
		"Error Flags",
 | 
			
		||||
		"About",
 | 
			
		||||
@@ -419,6 +513,7 @@ static void gui_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_entr
 | 
			
		||||
	};
 | 
			
		||||
	static const menu_func_t root_entry_funcs[] = {
 | 
			
		||||
		gui_menu_constant_temperature_driver_setup,
 | 
			
		||||
		gui_menu_temp_profile_select,
 | 
			
		||||
		gui_menu_monitor,
 | 
			
		||||
		gui_menu_err_flags,
 | 
			
		||||
		gui_menu_about,
 | 
			
		||||
 
 | 
			
		||||
@@ -273,3 +273,10 @@ void menu_display_clear(struct lcd_menu *menu)
 | 
			
		||||
	for (i = 0; i < 4; i++)
 | 
			
		||||
		menu->update_display(i, "");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t menu_list_get_currently_selected(struct menu_list *list)
 | 
			
		||||
{
 | 
			
		||||
	if (!list)
 | 
			
		||||
		return 0;
 | 
			
		||||
	return list->currently_selected;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user