-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
BaseUI: Autosave Messages #9269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements autosave functionality for messages stored in device RAM. Previously, messages were only persisted to flash during manual shutdown/restart, resulting in data loss during unexpected power failures or reset button usage. The new feature automatically saves unsaved messages to flash at a configurable interval (intended to be 12 hours by default), with special logic to avoid unnecessary flash writes when no new messages have been received.
Changes:
- Added autosave timer mechanism that triggers periodic saves of unsaved messages
- Integrated autosave tick call into the main event loop
- Refactored message menu to consolidate delete operations into a submenu
- Added state tracking for unsaved messages and automatic persistence
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main.cpp | Added MessageStore.h include and messageStoreAutosaveTick() call in main loop |
| src/graphics/draw/MenuHandler.cpp | Refactored message response menu to use DeleteMenu enum and removed duplicate delete logic |
| src/MessageStore.h | Added messageStoreAutosaveTick() function declaration with appropriate guards |
| src/MessageStore.cpp | Implemented core autosave logic including interval calculation, state tracking, and integration with add/save/load operations |
* Autosave Messages * fix * Add logging, code cleanup, and add save on delete. * We already save as part of delete messages, no need to do it again * fix spelling errors * Updating comment --------- Co-authored-by: Jason P <[email protected]>
This PR adds message autosaving to the node.
Previously, messages were only saved to flash when the user manually shut down or restarted the device using the UI. If the node lost power or the reset button was pressed, all messages stored in RAM were lost.
With this change, messages are automatically saved to flash every 2 hours. The 2 hour interval was chosen to reduce flash wear, especially on nRF52 based devices where flash has a limited write lifespan. There is a manual overwrite to this interval that can be applied to other nodes like esp32 ex. -DMESSAGE_AUTOSAVE_INTERVAL_SEC=3600
Behavior
This ensures messages survive unexpected power loss while keeping flash writes to a minimum.