TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
menu.h
Go to the documentation of this file.
1
8
9#ifndef INCLUDE_MENU_H
10#define INCLUDE_MENU_H
11
12#include "io.h"
13#include <avr/io.h>
14#include <stdint.h>
15
28
29// Represents a menu item in the menu system. Each menu item can either:
30// - perform an action (start a game, show high scores, open settings etc)
31// - open a submenu (chid menu) that has additional menu items
35struct menu_item {
36 const char *name;
40};
41
42// Represents the current menu configuration and state.
43// Each menu configuration struct pointes to an OLED device and contains
44// information about the current menu state. The current menu state may then
45// change on navigation and selection of menu items.
49struct menu_cfg {
51
52 struct menu_item *items;
53 uint8_t length;
54 int8_t cursor_pos;
56
57 // Root (main) menu reference for returning back to main menu from submenus
59 uint8_t root_length;
60
61 // Parent menu reference for returning back to parent menu from submenus
63 uint8_t parent_length;
64};
65
71int menu_init(struct menu_cfg *menu);
72
78int page_dispatch(struct menu_cfg *menu);
79
80/* Individual page display functions */
81int welcome_display(struct menu_cfg *menu);
84int settings_display(struct menu_cfg *menu);
88
89/* Cursor functions */
90int draw_cursor(struct menu_cfg *menu);
91int cursor_update(struct menu_cfg *menu, struct io_avr_buttons *btn);
92int page_select(struct menu_cfg *menu, struct io_avr_buttons *btn);
93int set_page(struct menu_cfg *menu, enum page_id page);
94int page_dispatch(struct menu_cfg *menu);
95int page_back(struct menu_cfg *menu, struct io_avr_buttons *btn);
96
103int menu_handler(struct menu_cfg *menu, struct io_avr_buttons *btn);
104
105#endif // INCLUDE_MENU_H
106
int menu_init(struct menu_cfg *menu)
Initializes menu and OLED display.
Definition menu.c:16
int cursor_update(struct menu_cfg *menu, struct io_avr_buttons *btn)
Updates the cursor position based on nav button from the IO board. Wraps around if going out of bound...
Definition menu.c:178
int menu_handler(struct menu_cfg *menu, struct io_avr_buttons *btn)
Handles menu logic (navigation, selection, page timers).
Definition menu.c:340
int draw_cursor(struct menu_cfg *menu)
Draws the cursor (">") at the current cursor position in the menu.
Definition menu.c:154
int high_scores_display(struct menu_cfg *menu)
Displays the high scores page.
Definition menu.c:75
int welcome_display(struct menu_cfg *menu)
Displays the welcome page.
Definition menu.c:30
int game_over_display(struct menu_cfg *menu)
Definition menu.c:136
page_id
Menu page identifiers.
Definition menu.h:19
int set_page(struct menu_cfg *menu, enum page_id page)
Sets the current page field in the menu struct to a specified page and calls the page_dispatch functi...
Definition menu.c:257
int page_back(struct menu_cfg *menu, struct io_avr_buttons *btn)
Definition menu.c:302
int play_game_display(struct menu_cfg *menu)
Displays the play game page.
Definition menu.c:59
int brightness_display(struct menu_cfg *menu)
Definition menu.c:114
int page_select(struct menu_cfg *menu, struct io_avr_buttons *btn)
Selects the current menu item based on nav button from the IO board.
Definition menu.c:216
int page_dispatch(struct menu_cfg *menu)
Dispatches to the current page display function.
Definition menu.c:276
int calibrate_joystick_display(struct menu_cfg *menu)
Definition menu.c:125
int settings_display(struct menu_cfg *menu)
Displays the settings page.
Definition menu.c:91
@ PAGE_PLAY_GAME
Definition menu.h:21
@ PAGE_HIGH_SCORES
Definition menu.h:22
@ PAGE_SETTINGS
Definition menu.h:23
@ PAGE_ADJUST_BRIGHTNESS
Definition menu.h:24
@ PAGE_GAME_OVER
Definition menu.h:26
@ PAGE_WELCOME
Definition menu.h:20
@ PAGE_CALIBRATE_JOYSTICK
Definition menu.h:25
Driver for joystick, buttons, and OLED.
struct io_avr_buttons btn
Definition main.c:59
struct menu_cfg menu
Definition main.c:76
Represents an OLED display device controlled via SPI.
Definition io.h:46
Menu configuration and state.
Definition menu.h:49
struct menu_item * parent_menu
Definition menu.h:62
uint8_t parent_length
Definition menu.h:63
int8_t cursor_pos
Definition menu.h:54
uint8_t length
Definition menu.h:53
enum page_id current_page
Definition menu.h:55
struct menu_item * root_items
Definition menu.h:58
struct menu_item * items
Definition menu.h:52
uint8_t root_length
Definition menu.h:59
struct io_oled_device * oled
Definition menu.h:50
Menu item struct.
Definition menu.h:35
uint8_t submenu_length
Definition menu.h:39
struct menu_item * submenu
Definition menu.h:38
enum page_id target_page
Definition menu.h:37
const char * name
Definition menu.h:36