Implement preliminary menu functions
This commit is contained in:
		@@ -31,8 +31,6 @@
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#define LCD_CHAR_WIDTH 16
 | 
			
		||||
 | 
			
		||||
static void lcd_port_clear(void)
 | 
			
		||||
{
 | 
			
		||||
	LCD_DPORT->ODR &= ~(LCD_E_MASK);
 | 
			
		||||
 
 | 
			
		||||
@@ -19,3 +19,74 @@
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include <reflow-controller/ui/menu.h>
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
 | 
			
		||||
void menu_handle(struct lcd_menu *menu, uint16_t rotary_encoder_delta, enum button_state push_button)
 | 
			
		||||
{
 | 
			
		||||
	menu_func_t tmp;
 | 
			
		||||
 | 
			
		||||
	if (!menu)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	menu->inputs.push_button = push_button;
 | 
			
		||||
	menu->inputs.rotary_encoder_delta = rotary_encoder_delta;
 | 
			
		||||
 | 
			
		||||
	tmp = menu->active_entry;
 | 
			
		||||
 | 
			
		||||
	if (menu->active_entry_type == MENU_ENTRY_FIRST_ENTER) {
 | 
			
		||||
		if (menu->active_entry)
 | 
			
		||||
			menu->active_entry(menu, menu->active_entry_type, menu->init_parent);
 | 
			
		||||
	} else {
 | 
			
		||||
		if (menu->active_entry)
 | 
			
		||||
			menu->active_entry(menu, menu->active_entry_type, NULL);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (menu->active_entry_type != MENU_ENTRY_CONTINUE && tmp == menu->active_entry) {
 | 
			
		||||
		menu->active_entry_type = MENU_ENTRY_CONTINUE;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void menu_init(struct lcd_menu *menu, menu_func_t root_node, void (*display_update)(uint8_t row, const char *data))
 | 
			
		||||
{
 | 
			
		||||
	if (!menu)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	menu->root_entry = root_node;
 | 
			
		||||
	menu->active_entry = root_node;
 | 
			
		||||
	menu->init_parent = NULL;
 | 
			
		||||
	menu->inputs.push_button = BUTTON_IDLE;
 | 
			
		||||
	menu->inputs.rotary_encoder_delta = 0;
 | 
			
		||||
	menu->active_entry_type = MENU_ENTRY_FIRST_ENTER;
 | 
			
		||||
	menu->update_display = display_update;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void menu_entry_dropback(struct lcd_menu *menu, menu_func_t parent_func)
 | 
			
		||||
{
 | 
			
		||||
	if (!menu)
 | 
			
		||||
		return;
 | 
			
		||||
	if (parent_func)
 | 
			
		||||
		menu->active_entry = parent_func;
 | 
			
		||||
	else
 | 
			
		||||
		menu->active_entry = menu->root_entry;
 | 
			
		||||
 | 
			
		||||
	menu->active_entry_type = MENU_ENTRY_DROPBACK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void menu_entry_enter(struct lcd_menu *menu, menu_func_t parent_func, bool handle_immediately)
 | 
			
		||||
{
 | 
			
		||||
	menu->init_parent = menu->active_entry;
 | 
			
		||||
	menu->active_entry_type = MENU_ENTRY_FIRST_ENTER;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text)
 | 
			
		||||
{
 | 
			
		||||
	if (!menu || !menu->update_display)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	menu->update_display(row_num, text);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void menu_list_display(struct menu_list *list, uint8_t top_row, uint8_t bottom_row)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user