Implement preliminary menu functions
This commit is contained in:
parent
0d44d25ec9
commit
25bb341fa4
@ -30,11 +30,11 @@ struct lcd_menu;
|
||||
|
||||
enum menu_entry_func_entry {MENU_ENTRY_FIRST_ENTER, MENU_ENTRY_CONTINUE, MENU_ENTRY_DROPBACK};
|
||||
|
||||
typedef enum menu_func_ret_t (*menu_func_t)(struct lcd_menu *menu, enum menu_entry_func_entry entry_type,
|
||||
typedef void (*menu_func_t)(struct lcd_menu *menu, enum menu_entry_func_entry entry_type,
|
||||
void *parent);
|
||||
|
||||
struct menu_inputs {
|
||||
uint16_t rotary_encoder_val;
|
||||
int16_t rotary_encoder_delta;
|
||||
enum button_state push_button;
|
||||
};
|
||||
|
||||
@ -42,8 +42,9 @@ struct lcd_menu {
|
||||
menu_func_t active_entry;
|
||||
menu_func_t root_entry;
|
||||
enum menu_entry_func_entry active_entry_type;
|
||||
menu_func_t init_parent;
|
||||
struct menu_inputs inputs;
|
||||
char lcd_buffer[LCD_ROW_COUNT][21];
|
||||
void (*update_display)(uint8_t row, const char *data);
|
||||
};
|
||||
|
||||
struct menu_list {
|
||||
@ -52,15 +53,15 @@ struct menu_list {
|
||||
const menu_func_t *submenu_list;
|
||||
};
|
||||
|
||||
void menu_handle(struct lcd_menu *menu, uint16_t rotary_encoder_value, enum button_state push_button);
|
||||
void menu_handle(struct lcd_menu *menu, uint16_t rotary_encoder_delta, enum button_state push_button);
|
||||
|
||||
void menu_init(struct lcd_menu *menu, menu_func_t root_node);
|
||||
void menu_init(struct lcd_menu *menu, menu_func_t root_node, void (*display_update)(uint8_t row, const char *data));
|
||||
|
||||
void menu_entry_dropback(struct lcd_menu *menu, menu_func_t parent_func);
|
||||
|
||||
void menu_entry_enter(struct lcd_menu *menu, menu_func_t parent_func, bool handle_immediately);
|
||||
|
||||
void menu_override_lcd_output(uint8_t row_num, char *text);
|
||||
void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text);
|
||||
|
||||
void menu_list_display(struct menu_list *list, uint8_t top_row, uint8_t bottom_row);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user