Refactor main menu functionality and state handling #205
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is my proposal how to refactor/reimplement the main menu functionality and state handling.
The aim is to simplify the code structure, avoid duplicate code and allow better extensibility. But also, to make menu flows easier to follow and isolate state handling within certain menu rather than handling all possible states at
handleButtonPress()
.Main changes:
showMenu()
andshowFastMenu()
are replaced byshowMainMenu()
andgetMenuSelection()
methods. InshowMainMenu()
we define the elements needed for the main menu and handle its flow based on the user selection.getMenuSelection()
serves as a generic method for creating menus and can be easily used for creating new submenus etc. Button inputs and menu specific timeout value are handled insidegetMenuSelection()
. In case of main menu, at timeout we get out of the menu and handle flow after inshowMainMenu()
.handleButtonPress()
isn't handling states anymore, for now we only wake up from menu button and go to main menu.Going into apps sets
APP_STATE
, which also defines how the flow after the app goes. InshowMainMenu()
we go back to main menu fromAPP_STATE
or toWATCHFACE_STATE
if going back because of timeout or back button. SinceAPP_STATE
defines the flow after the app is done, we don't have to callshowMainMenu()
every time we should go back to main menu from app.Term
menu
used in global variables is changed tomainMenu
to be more clear and not to confuse with other menus in the future.State
FW_UPDATE_STATE
is removed sinceAPP_STATE
can be used as well.Firmware update app shows example of submenu flow where button inputs inside a menu define what happens next, e.g. do we go forward within the app or go back to main menu.
RTC alarm wakeup handles only
WATCHFACE_STATE
since we never stay in the main menu because of timeout.Global
MENU_LENGTH
is removed since menu length is menu specific and has to be given togetMenuSelection()
as an argument.This is fairly big change but I haven't noticed anything being broken, any feedback is welcome! :)