Swadge ESP32-S2
APIs to develop for the Magfest Swadge
Toggle main menu visibility
Loading...
Searching...
No Matches
menu.h
Go to the documentation of this file.
1
133
134
#ifndef _MENU_H_
135
#define _MENU_H_
136
137
#include <stdint.h>
138
#include <stdbool.h>
139
#include "
linked_list.h
"
140
#include "
hdw-btn.h
"
141
#include "
font.h
"
142
#include "
settingsManager.h
"
143
151
typedef
bool (*
menuCb
)(
const
char
* label,
bool
selected, uint32_t value);
152
153
typedef
struct
_menu_t
menu_t
;
154
158
typedef
struct
159
{
160
const
char
*
label
;
161
const
char
*
const
*
options
;
162
menu_t
*
subMenu
;
163
uint8_t
numOptions
;
164
int32_t
currentOpt
;
165
int32_t
minSetting
;
166
int32_t
maxSetting
;
167
const
int32_t*
settingVals
;
168
int32_t
currentSetting
;
169
}
menuItem_t
;
170
174
typedef
struct
_menu_t
175
{
176
const
char
*
title
;
177
menuCb
cbFunc
;
178
list_t
*
items
;
179
node_t
*
currentItem
;
180
menu_t
*
parentMenu
;
181
bool
showBattery
;
182
int32_t
batteryReadTimer
;
183
int
batteryLevel
;
184
uint32_t
memCaps
;
185
}
menu_t
;
186
188
extern
const
char
*
mnuBackStr
;
189
190
menu_t
*
initMenu
(
const
char
* title,
menuCb
cbFunc) __attribute__((warn_unused_result));
191
menu_t
*
initMenuRam
(
const
char
* title,
menuCb
cbFunc, uint32_t memCaps) __attribute__((warn_unused_result));
192
void
deinitMenu
(
menu_t
* menu);
193
menu_t
*
startSubMenu
(
menu_t
* menu,
const
char
* label) __attribute__((warn_unused_result));
194
menu_t
*
endSubMenu
(
menu_t
* menu) __attribute__((warn_unused_result));
195
menuItem_t
*
addSingleItemToMenu
(
menu_t
* menu,
const
char
* label);
196
menuItem_t
*
insertSingleItemToMenuAfter
(
menu_t
* menu,
const
char
* newLabel,
const
char
* afterLabel);
197
void
removeSingleItemFromMenu
(
menu_t
* menu,
const
char
* label);
198
menu_t
*
removeAllItemsFromMenu
(
menu_t
* menu);
199
void
addMultiItemToMenu
(
menu_t
* menu,
const
char
*
const
* labels, uint8_t numLabels, uint8_t currentLabel);
200
void
removeMultiItemFromMenu
(
menu_t
* menu,
const
char
*
const
* labels);
201
void
addSettingsItemToMenu
(
menu_t
* menu,
const
char
* label,
const
settingParam_t
* bounds, int32_t val);
202
void
removeSettingsItemFromMenu
(
menu_t
* menu,
const
char
* label);
203
menuItem_t
*
addSettingsOptionsItemToMenu
(
menu_t
* menu,
const
char
* settingLabel,
const
char
*
const
* optionLabels,
204
const
int32_t* optionValues, uint8_t numOptions,
const
settingParam_t
* bounds,
205
int32_t currentValue);
206
void
removeSettingsOptionsItemFromMenu
(
menu_t
* menu,
const
char
*
const
* optionLabels);
207
208
menu_t
*
menuNavigateToTopItem
(
menu_t
* menu);
209
menu_t
*
menuNavigateToItem
(
menu_t
* menu,
const
char
* label);
210
menu_t
*
menuNavigateToPrevItem
(
menu_t
* menu);
211
menu_t
*
menuNavigateToNextItem
(
menu_t
* menu);
212
menu_t
*
menuNavigateToPrevOption
(
menu_t
* menu);
213
menu_t
*
menuNavigateToNextOption
(
menu_t
* menu);
214
menu_t
*
menuSelectCurrentItem
(
menu_t
* menu);
215
menu_t
*
menuSetCurrentOption
(
menu_t
* menu, int32_t value);
216
217
menu_t
*
menuButton
(
menu_t
* menu,
buttonEvt_t
evt) __attribute__((warn_unused_result));
218
void
setShowBattery
(
menu_t
* menu,
bool
showBattery);
219
220
#endif
font.h
hdw-btn.h
buttonEvt_t
A button event containing the button that triggered the event, whether it was pressed or released,...
Definition
hdw-btn.h:83
linked_list.h
node_t
struct node node_t
A node in a doubly linked list with pointers to the previous and next values (which may be NULL),...
list_t
A doubly linked list with pointers to the first and last nodes.
Definition
linked_list.h:87
mnuBackStr
const char * mnuBackStr
A string used to return to super-menus that says "Back".
Definition
menu.c:16
menuSetCurrentOption
menu_t * menuSetCurrentOption(menu_t *menu, int32_t value)
Performs the equivalent of scrolling to the given setting value or option index for the currently sel...
Definition
menu.c:909
_menu_t::showBattery
bool showBattery
true if the battery measurement should be shown. false by default
Definition
menu.h:181
removeAllItemsFromMenu
menu_t * removeAllItemsFromMenu(menu_t *menu)
Remove all items from a menu, excluding the "Back" item.
Definition
menu.c:331
addSettingsItemToMenu
void addSettingsItemToMenu(menu_t *menu, const char *label, const settingParam_t *bounds, int32_t val)
Add a settings entry to the menu. A settings entry is left-right scrollable where an integer setting ...
Definition
menu.c:439
setShowBattery
void setShowBattery(menu_t *menu, bool showBattery)
Show or hide the battery on the menu. This should be called from the root menu after the menu is cons...
Definition
menu.c:999
menuItem_t::settingVals
const int32_t * settingVals
The setting value options for settings-options items.
Definition
menu.h:167
_menu_t::batteryLevel
int batteryLevel
The current battery measurement.
Definition
menu.h:183
menuCb
bool(* menuCb)(const char *label, bool selected, uint32_t value)
A callback which is called when a menu changes or items are selected.
Definition
menu.h:151
menuButton
menu_t * menuButton(menu_t *menu, buttonEvt_t evt)
This must be called to pass button event from the Swadge mode to the menu. If a button is passed here...
Definition
menu.c:942
menuItem_t::numOptions
uint8_t numOptions
The number of options for multi-select.
Definition
menu.h:163
removeSettingsItemFromMenu
void removeSettingsItemFromMenu(menu_t *menu, const char *label)
Remove a settings item entry from the menu. This item is removed by pointer, not by doing any string ...
Definition
menu.c:463
deinitMenu
void deinitMenu(menu_t *menu)
Deinitialize a menu and all connected menus, including submenus and parent menus. This frees memory a...
Definition
menu.c:96
menuNavigateToNextOption
menu_t * menuNavigateToNextOption(menu_t *menu)
Navigate to the next option in a menu item. This is equivalent to pressing the RIGHT button.
Definition
menu.c:795
initMenu
menu_t * initMenu(const char *title, menuCb cbFunc)
Initialize and return an empty menu. A menu is a collection of vertically scrollable rows....
Definition
menu.c:49
menuItem_t::maxSetting
int32_t maxSetting
The maximum value for settings items.
Definition
menu.h:166
removeSettingsOptionsItemFromMenu
void removeSettingsOptionsItemFromMenu(menu_t *menu, const char *const *optionLabels)
Remove a settings options item entry from the menu. This item is removed by pointer,...
Definition
menu.c:564
_menu_t::memCaps
uint32_t memCaps
Where to allocate memory.
Definition
menu.h:184
menuItem_t::minSetting
int32_t minSetting
The minimum value for settings items.
Definition
menu.h:165
menuSelectCurrentItem
menu_t * menuSelectCurrentItem(menu_t *menu)
Select the current item in a menu item. This is equivalent to pressing the A button.
Definition
menu.c:850
addSettingsOptionsItemToMenu
menuItem_t * addSettingsOptionsItemToMenu(menu_t *menu, const char *settingLabel, const char *const *optionLabels, const int32_t *optionValues, uint8_t numOptions, const settingParam_t *bounds, int32_t currentValue)
Adds a settings item entry to the menu with a specific list of options. The entry will be left-right ...
Definition
menu.c:516
menu_t
struct _menu_t menu_t
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition
menu.h:153
insertSingleItemToMenuAfter
menuItem_t * insertSingleItemToMenuAfter(menu_t *menu, const char *newLabel, const char *afterLabel)
Add a single item entry to the menu after a given label. When this item is selected,...
Definition
menu.c:259
_menu_t::items
list_t * items
A list_t of menu items to display.
Definition
menu.h:178
menuNavigateToNextItem
menu_t * menuNavigateToNextItem(menu_t *menu)
Navigate to the next item in the menu. This is equivalent to pressing the DOWN button.
Definition
menu.c:711
startSubMenu
menu_t * startSubMenu(menu_t *menu, const char *label)
Add a submenu item to the menu. When this item is select, the submenu is rendered....
Definition
menu.c:159
_menu_t::title
const char * title
The title for this menu.
Definition
menu.h:176
menuNavigateToItem
menu_t * menuNavigateToItem(menu_t *menu, const char *label)
Changes the selected item to the one with the given label, just as though it were scrolled to.
Definition
menu.c:637
initMenuRam
menu_t * initMenuRam(const char *title, menuCb cbFunc, uint32_t memCaps)
Initialize and return an empty menu. A menu is a collection of vertically scrollable rows....
Definition
menu.c:76
_menu_t::cbFunc
menuCb cbFunc
The callback function to call when menu items are selected.
Definition
menu.h:177
menuItem_t::currentSetting
int32_t currentSetting
The current value for settings items.
Definition
menu.h:168
_menu_t::currentItem
node_t * currentItem
The currently selected menu item.
Definition
menu.h:179
endSubMenu
menu_t * endSubMenu(menu_t *menu)
Finish adding items to a submenu and resume adding items to the parent menu. This will automatically ...
Definition
menu.c:200
menuItem_t::label
const char * label
The label displayed if single-select or submenu.
Definition
menu.h:160
menuNavigateToPrevOption
menu_t * menuNavigateToPrevOption(menu_t *menu)
Navigate to the previous option in a menu item. This is equivalent to pressing the LEFT button.
Definition
menu.c:738
menuNavigateToTopItem
menu_t * menuNavigateToTopItem(menu_t *menu)
Navigate to the first item in a menu, just as though it were scrolled to.
Definition
menu.c:616
menuNavigateToPrevItem
menu_t * menuNavigateToPrevItem(menu_t *menu)
Navigate to the previous item in the menu. This is equivalent to pressing the UP button.
Definition
menu.c:685
menuItem_t::options
const char *const * options
The labels displayed if multi-select.
Definition
menu.h:161
menuItem_t::currentOpt
int32_t currentOpt
The current selected option for multi-select.
Definition
menu.h:164
_menu_t::parentMenu
menu_t * parentMenu
The parent menu, may be NULL if this is not a submenu.
Definition
menu.h:180
removeMultiItemFromMenu
void removeMultiItemFromMenu(menu_t *menu, const char *const *labels)
Remove a multi item entry from the menu. This item is removed by pointer, not by doing any string com...
Definition
menu.c:396
addSingleItemToMenu
menuItem_t * addSingleItemToMenu(menu_t *menu, const char *label)
Add a single item entry to the menu. When this item is selected, the menuCb callback is called with t...
Definition
menu.c:222
addMultiItemToMenu
void addMultiItemToMenu(menu_t *menu, const char *const *labels, uint8_t numLabels, uint8_t currentLabel)
Add a multiple item entry to the menu. The multiple items exist in a single entry and are left-right ...
Definition
menu.c:372
_menu_t::batteryReadTimer
int32_t batteryReadTimer
A timer to read the battery every 10s.
Definition
menu.h:182
removeSingleItemFromMenu
void removeSingleItemFromMenu(menu_t *menu, const char *label)
Remove a single item entry from the menu. This item is removed by pointer, not by doing a string comp...
Definition
menu.c:298
menuItem_t::subMenu
menu_t * subMenu
A pointer to a submenu, maybe NULL for single-select and multi-select.
Definition
menu.h:162
_menu_t
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition
menu.h:175
menuItem_t
The underlying data for an item in a menu. The item may be a single-select, multi-select,...
Definition
menu.h:159
settingsManager.h
settingParam_t
Immutable data for a setting, including minimum, maximum, and default values, and the NVS key.
Definition
settingsManager.h:107
main
utils
menu
menu.h
Generated by
1.17.0