/* 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/>.
*/

#ifndef __MENU_H__
#define __MENU_H__

#include <stdint.h>
#include <reflow-controller/button.h>
#include <stdbool.h>

struct lcd_menu;

enum menu_entry_func_entry {MENU_ENTRY_FIRST_ENTER, MENU_ENTRY_CONTINUE, MENU_ENTRY_DROPBACK};

typedef void (*menu_func_t)(struct lcd_menu *menu, enum menu_entry_func_entry entry_type,
					    void *parent);

struct menu_inputs {
	int16_t rotary_encoder_delta;
	enum button_state push_button;
};

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;
	void (*update_display)(uint8_t row, const char *data);
};

struct menu_list {
	void (*update_display)(uint8_t row, const char *data);
	const char * const * entry_names;
	uint32_t entry_count;
	uint32_t currently_selected;
	const menu_func_t *submenu_list;
};

void menu_handle(struct lcd_menu *menu, int16_t rotary_encoder_delta, enum button_state push_button);

void menu_init(struct lcd_menu *menu, menu_func_t root_node, void (*display_update)(uint8_t row, const char *data));

void menu_ack_rotary_delta(struct lcd_menu *menu);

void menu_display_clear(struct lcd_menu *menu);

void menu_entry_dropback(struct lcd_menu *menu, menu_func_t parent_func);

void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_immediately);

void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text);

void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row);

void menu_list_compute_count(struct menu_list *list);

void menu_list_scroll_down(struct menu_list *list);

void menu_list_scroll_up(struct menu_list *list);

void menu_list_enter_selected_entry(struct menu_list *list, struct lcd_menu *menu);

#endif /* __MENU_H__ */
