Added toggle switch widget.

This commit is contained in:
Dylan Smith
2026-01-16 16:28:00 -05:00
parent fd46ea65ca
commit 3ef5bd9240
7 changed files with 62 additions and 61 deletions

View File

@@ -7,8 +7,8 @@
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);
void ui_draw_toggle_led1_switch(const menu_entry_size_t *const menu_entry_size, void *const args);
void ui_draw_toggle_led2_switch(const menu_entry_size_t *const menu_entry_size, void *const args);
/******************* */
/* Menu declarations */
@@ -36,13 +36,15 @@ static graphical_menu_t main_menu = {
.disabled = true,
.selected_callback_function = ui_toggle_led1,
.selected_callback_function_args = 0,
.extra_draw_function = ui_toggle_led1_switch,
.extra_draw_function = add_toggle_switch_to_menu_entry,
.extra_draw_function_args = (void *)&led1_state,
},
{
.title = "Toggle LED2",
.selected_callback_function = ui_toggle_led2,
.selected_callback_function_args = 0,
.extra_draw_function = ui_toggle_led2_switch,
.extra_draw_function = add_toggle_switch_to_menu_entry,
.extra_draw_function_args = (void *)&led2_state,
}
}
};
@@ -87,40 +89,6 @@ void ui_toggle_led2(void *const args)
ui_request_redraw();
}
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 / 2) + width_padding);
const uint16_t y = menu_entry_size->y + height_padding;
const toggle_switch_t toggle_switch = {
.x = x,
.y = y,
.inner_padding_pixels = 3,
.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 / 2) + width_padding);
const uint16_t y = menu_entry_size->y + height_padding;
const toggle_switch_t toggle_switch = {
.x = x,
.y = y,
.inner_padding_pixels = 3,
.value = HAL_GPIO_ReadPin(LD4_GPIO_Port, LD4_Pin) == GPIO_PIN_SET,
};
draw_toggle_switch(next_framebuffer, &toggle_switch);
}
/************************* */
/* UI function definitions */
/************************* */
@@ -143,15 +111,9 @@ void ui_exit_submenu(void)
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);