Menu work

This commit is contained in:
Dylan Smith
2026-01-15 15:53:02 -05:00
parent 66cb2436c7
commit b48cb11197
9 changed files with 248 additions and 63 deletions

View File

@@ -16,8 +16,8 @@ extern lv_font_t roboto_bold_large_font;
extern lv_font_t runescape_font;
#endif
uint16_t draw_character(pixel_t *framebuffer, const lv_font_t *font, const uint16_t x_loc, const uint16_t y_loc, const uint8_t character, pixel_t color);
uint16_t draw_character(pixel_t *framebuffer, const lv_font_t *font, const uint16_t x_loc, const uint16_t y_loc, const char character, pixel_t color);
void draw_string(pixel_t *framebuffer, const lv_font_t *font, const uint16_t x_loc, const uint16_t y_loc, const uint8_t *string, pixel_t color);
void draw_string(pixel_t *framebuffer, const lv_font_t *font, const uint16_t x_loc, const uint16_t y_loc, const char *string, pixel_t color);
#endif

View File

@@ -5,28 +5,46 @@
#include "stdbool.h"
typedef void (*menu_callback_t)(void *args);
typedef struct _graphical_menu_layout_t graphical_menu_layout_t;
typedef struct _graphical_menu_t graphical_menu_t;
// TODO
// typedef struct {
// uint16_t x;
// uint16_t y;
// uint16_t width;
// uint16_t height;
// } graphical_menu_position_t;
typedef struct
{
uint8_t *title;
bool enabled; // not enabled = grayed out, unhighlightable
menu_callback_t highlighted_callback_function;
void *highlighted_callback_function_args;
menu_callback_t selected_callback_function;
void *selected_callback_function_args;
const char *const title;
const bool enabled; // not enabled = grayed out, unhighlightable
const menu_callback_t highlighted_callback_function;
void *const highlighted_callback_function_args;
const menu_callback_t selected_callback_function;
void *const selected_callback_function_args;
} graphical_menu_entry_t;
typedef struct _graphical_menu_t graphical_menu_t;
struct _graphical_menu_t {
graphical_menu_t *parent_menu;
uint8_t num_entries;
graphical_menu_entry_t *entries;
struct _graphical_menu_layout_t {
graphical_menu_t *const parent_menu;
const uint8_t num_entries;
const graphical_menu_entry_t *const entries;
};
struct _graphical_menu_t {
const graphical_menu_layout_t *const layout;
uint8_t selected_entry_idx;
};
void draw_menu(const graphical_menu_t *const menu);
void select_menu_entry(const graphical_menu_t *const menu);
void select_menu_entry(graphical_menu_t *const menu);
uint8_t get_selected_menu_entry_idx(void);
void set_selected_menu_entry_idx(const graphical_menu_t *const menu, uint8_t idx);
void set_selected_menu_entry_idx(graphical_menu_t *const menu, int8_t idx);
void decrement_selected_menu_entry_idx(graphical_menu_t *const menu);
void increment_selected_menu_entry_idx(graphical_menu_t *const menu);
#endif

View File

@@ -374,6 +374,16 @@ void Error_Handler(void);
/* Size of read registers */
#define LCD_READ_ID4_SIZE 3 /* Size of Read ID4 */
/******************** */
/* Button definitions */
#define DOWN_BUTTON_PRESSED() (HAL_GPIO_ReadPin(BUTTON2_GPIO_Port, BUTTON2_Pin) == GPIO_PIN_RESET)
#define RIGHT_BUTTON_PRESSED() (HAL_GPIO_ReadPin(BUTTON3_GPIO_Port, BUTTON3_Pin) == GPIO_PIN_RESET)
#define LEFT_BUTTON_PRESSED() (HAL_GPIO_ReadPin(BUTTON1_GPIO_Port, BUTTON1_Pin) == GPIO_PIN_RESET)
#define OK_BUTTON_PRESSED() (HAL_GPIO_ReadPin(BUTTON4_GPIO_Port, BUTTON4_Pin) == GPIO_PIN_RESET)
#define UP_BUTTON_PRESSED() (HAL_GPIO_ReadPin(BUTTON5_GPIO_Port, BUTTON5_Pin) == GPIO_PIN_RESET)
/* USER CODE END Private defines */
#ifdef __cplusplus

16
Core/Inc/ui.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef UI_H
#define UI_H
#include "stdint.h"
#include "stdbool.h"
void ui_left_button_pressed(void);
void ui_right_button_pressed(void);
void ui_up_button_pressed(void);
void ui_down_button_pressed(void);
void ui_ok_button_pressed(void);
void ui_request_redraw(void);
void ui_task(void);
#endif