reflow-oven-control-sw/stm-firmware/ui/menu.c

104 lines
2.8 KiB
C
Raw Normal View History

/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/ui/menu.h>
2020-06-04 21:20:59 +02:00
#include <stddef.h>
2020-06-04 21:53:00 +02:00
void menu_handle(struct lcd_menu *menu, int16_t rotary_encoder_delta, enum button_state push_button)
2020-06-04 21:20:59 +02:00
{
menu_func_t tmp;
if (!menu)
return;
menu->inputs.push_button = push_button;
menu->inputs.rotary_encoder_delta = rotary_encoder_delta;
if (menu->active_entry == NULL)
menu->active_entry = menu->root_entry;
2020-06-04 21:20:59 +02:00
tmp = menu->active_entry;
2020-06-04 21:20:59 +02:00
if (menu->active_entry_type == MENU_ENTRY_FIRST_ENTER) {
menu->active_entry(menu, menu->active_entry_type, menu->init_parent);
} else {
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;
}
2020-06-04 21:53:00 +02:00
void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_immediately)
2020-06-04 21:20:59 +02:00
{
2020-06-04 21:53:00 +02:00
if (!menu)
return;
2020-06-04 21:20:59 +02:00
menu->init_parent = menu->active_entry;
menu->active_entry_type = MENU_ENTRY_FIRST_ENTER;
2020-06-04 21:53:00 +02:00
menu->active_entry = entry;
if (handle_immediately)
menu_handle(menu, menu->inputs.rotary_encoder_delta, menu->inputs.push_button);
2020-06-04 21:20:59 +02:00
}
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)
{
2020-06-04 21:53:00 +02:00
(void)list;
(void)top_row;
(void)bottom_row;
2020-06-04 21:20:59 +02:00
}