WIP sliders and incrimenting

This commit is contained in:
Dylan Smith
2026-01-16 14:45:38 -05:00
parent 6711b5dcc1
commit 7dc4bf493d
6 changed files with 178 additions and 73 deletions

View File

@@ -1,8 +1,14 @@
#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 */
@@ -15,40 +21,41 @@ static graphical_menu_t runescape_memes_menu;
/* Menu definitions */
/******************* */
static const graphical_menu_layout_t main_menu_layout = {
.parent_menu = 0,
.num_entries = 3,
.entries = (graphical_menu_entry_t[]){
{.title = "runescape memes", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = ui_enter_submenu, .selected_callback_function_args = &runescape_memes_menu},
{.title = "Settings", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "About", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
}
};
static const graphical_menu_layout_t runescape_memes_menu_layout = {
.parent_menu = &main_menu,
.num_entries = 7,
.entries = (graphical_menu_entry_t[]){
{.title = "where varock", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "buying gf", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
}
};
static graphical_menu_t main_menu = {
.layout = &main_menu_layout,
.selected_entry_idx = 0,
.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 = {
.layout = &runescape_memes_menu_layout,
.selected_entry_idx = 0,
.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},
}
};
@@ -64,6 +71,50 @@ 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 */
/************************* */
@@ -76,11 +127,11 @@ void ui_enter_submenu(void *const args)
void ui_exit_submenu(void)
{
if (current_menu->layout->parent_menu == 0)
if (current_menu->parent_menu == 0)
{
return;
}
current_menu = current_menu->layout->parent_menu;
current_menu = current_menu->parent_menu;
redraw_requested = true;
}