179 lines
4.9 KiB
C
179 lines
4.9 KiB
C
#include "ui.h"
|
|
#include "menu.h"
|
|
#include "display.h"
|
|
#include "main.h"
|
|
#include "graphics/graphics.h"
|
|
|
|
void ui_enter_submenu(void *const args);
|
|
void ui_toggle_led1(void *const args);
|
|
void ui_toggle_led2(void *const args);
|
|
void ui_toggle_led1_switch(const menu_entry_size_t *const menu_entry_size, void *const args);
|
|
void ui_toggle_led2_switch(const menu_entry_size_t *const menu_entry_size, void *const args);
|
|
|
|
/******************* */
|
|
/* Menu declarations */
|
|
/******************* */
|
|
|
|
static graphical_menu_t main_menu;
|
|
static graphical_menu_t runescape_memes_menu;
|
|
|
|
/******************* */
|
|
/* Menu definitions */
|
|
/******************* */
|
|
|
|
static graphical_menu_t main_menu = {
|
|
.parent_menu = 0,
|
|
.num_children = 3,
|
|
.highlighted_child_idx = 0,
|
|
.children = (graphical_menu_entry_t[]){
|
|
{
|
|
.title = "runescape memes menu",
|
|
.selected_callback_function = ui_enter_submenu,
|
|
.selected_callback_function_args = &runescape_memes_menu
|
|
},
|
|
{
|
|
.title = "Toggle LED1",
|
|
.disabled = true,
|
|
.selected_callback_function = ui_toggle_led1,
|
|
.selected_callback_function_args = 0,
|
|
.extra_draw_function = ui_toggle_led1_switch,
|
|
},
|
|
{
|
|
.title = "Toggle LED2",
|
|
.selected_callback_function = ui_toggle_led2,
|
|
.selected_callback_function_args = 0,
|
|
.extra_draw_function = ui_toggle_led2_switch,
|
|
}
|
|
}
|
|
};
|
|
|
|
static graphical_menu_t runescape_memes_menu = {
|
|
.parent_menu = &main_menu,
|
|
.num_children = 4,
|
|
.highlighted_child_idx = 0,
|
|
.children = (graphical_menu_entry_t[]){
|
|
{.title = "where varock", .disabled = false, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
|
|
{.title = "you chop the tree", .disabled = false, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
|
|
{.title = "you chop the tree", .disabled = false, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
|
|
}
|
|
};
|
|
|
|
|
|
/********************** */
|
|
/* UI state definitions */
|
|
/********************** */
|
|
|
|
enum ui_state_t {
|
|
UI_STATE_MENU,
|
|
};
|
|
|
|
static bool redraw_requested = true;
|
|
// static enum ui_state_t ui_state = UI_STATE_MENU;
|
|
static graphical_menu_t *current_menu = &main_menu;
|
|
|
|
/********************** */
|
|
/* UI callback functions */
|
|
/********************** */
|
|
|
|
void ui_toggle_led1(void *const args)
|
|
{
|
|
LED1_TOGGLE();
|
|
}
|
|
|
|
void ui_toggle_led2(void *const args)
|
|
{
|
|
LED2_TOGGLE();
|
|
}
|
|
|
|
void ui_toggle_led1_switch(const menu_entry_size_t *const menu_entry_size, void *const args)
|
|
{
|
|
const uint16_t width_padding = 10;
|
|
const uint16_t height_padding = 10;
|
|
const uint16_t x = menu_entry_size->x + (menu_entry_size->width + width_padding);
|
|
const uint16_t y = menu_entry_size->y + height_padding;
|
|
const toggle_switch_t toggle_switch = {
|
|
.x = x,
|
|
.y = y,
|
|
.value = HAL_GPIO_ReadPin(LD3_GPIO_Port, LD3_Pin) == GPIO_PIN_SET,
|
|
};
|
|
|
|
draw_toggle_switch(next_framebuffer, &toggle_switch);
|
|
}
|
|
|
|
void ui_toggle_led2_switch(const menu_entry_size_t *const menu_entry_size, void *const args)
|
|
{
|
|
const uint16_t width_padding = 10;
|
|
const uint16_t height_padding = 10;
|
|
const uint16_t x = menu_entry_size->x + (menu_entry_size->width + width_padding);
|
|
const uint16_t y = menu_entry_size->y + height_padding;
|
|
const toggle_switch_t toggle_switch = {
|
|
.x = x,
|
|
.y = y,
|
|
.value = HAL_GPIO_ReadPin(LD4_GPIO_Port, LD4_Pin) == GPIO_PIN_SET,
|
|
};
|
|
|
|
draw_toggle_switch(next_framebuffer, &toggle_switch);
|
|
}
|
|
|
|
/************************* */
|
|
/* UI function definitions */
|
|
/************************* */
|
|
|
|
void ui_enter_submenu(void *const args)
|
|
{
|
|
current_menu = (graphical_menu_t *)args;
|
|
redraw_requested = true;
|
|
}
|
|
|
|
void ui_exit_submenu(void)
|
|
{
|
|
if (current_menu->parent_menu == 0)
|
|
{
|
|
return;
|
|
}
|
|
current_menu = current_menu->parent_menu;
|
|
redraw_requested = true;
|
|
}
|
|
|
|
void ui_left_button_pressed(void)
|
|
{
|
|
// decrement_selected_menu_entry_idx(&main_menu);
|
|
ui_exit_submenu();
|
|
}
|
|
|
|
void ui_right_button_pressed(void)
|
|
{
|
|
// increment_selected_menu_entry_idx(&main_menu);
|
|
}
|
|
|
|
void ui_up_button_pressed(void)
|
|
{
|
|
decrement_selected_menu_entry_idx(next_framebuffer, current_menu);
|
|
swap_framebuffers();
|
|
}
|
|
|
|
void ui_down_button_pressed(void)
|
|
{
|
|
increment_selected_menu_entry_idx(next_framebuffer, current_menu);
|
|
swap_framebuffers();
|
|
}
|
|
|
|
void ui_ok_button_pressed(void)
|
|
{
|
|
select_menu_entry(current_menu);
|
|
}
|
|
|
|
void ui_request_redraw(void)
|
|
{
|
|
redraw_requested = true;
|
|
}
|
|
|
|
void ui_task(void)
|
|
{
|
|
if (redraw_requested)
|
|
{
|
|
redraw_requested = false;
|
|
draw_menu(next_framebuffer, current_menu);
|
|
swap_framebuffers();
|
|
}
|
|
} |