-
Notifications
You must be signed in to change notification settings - Fork 1
steami_config: Add boot counter. #352
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aabc6e8
feat(steami_config): add boot counter functionality
Charly-sketch d73ec7c
feat(steami_config): add boot counter example
Charly-sketch 97c1bff
docs(steami_config): add boot counter to readme
Charly-sketch 1f5b4ef
test(steami_config): add boot counter mock and hardware tests
Charly-sketch 95a2d36
fix(steami_config): Shorten boot counter JSON key to "bc" for consist…
nedseb 05a5d81
fix(steami_config): Fix missing variable assignment in README boot co…
nedseb 369cd25
docs(steami_config): Improve boot counter section wording in README.
nedseb 3be47f5
style(steami_config): Remove trailing spaces in README.
nedseb 591af42
style(steami_config): Fix comment indentation in boot counter tests.
nedseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """ | ||
| Boot counter example. | ||
| Each time the board boots, | ||
| it increments the boot count | ||
| and saves it to non-volatile storage. | ||
| """ | ||
|
|
||
| from daplink_bridge import DaplinkBridge | ||
| from machine import I2C | ||
| from steami_config import SteamiConfig | ||
|
|
||
| # --- Hardware init --- | ||
| i2c = I2C(1) | ||
| bridge = DaplinkBridge(i2c) | ||
|
|
||
| config = SteamiConfig(bridge) | ||
| config.load() | ||
|
|
||
| # --- Boot counter logic --- | ||
| config.increment_boot_count() | ||
|
|
||
| # Save updated value | ||
| config.save() | ||
|
|
||
| # Read and display | ||
| count = config.get_boot_count() | ||
|
|
||
| print("Boot count:", count) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
This example increments the counter and immediately calls
config.save(). SinceSteamiConfig.save()erases the config zone (bridge.clear_config()) before rewriting JSON, doing this on every boot can significantly increase flash erase/write cycles (and is especially risky in reboot loops). Consider adding a note about flash wear / optionally persisting less frequently (e.g., only every N boots or on graceful shutdown).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.
Valid point about flash wear. However, this is a pedagogical example — simplicity is the priority. The STeaMi DAPLink config zone uses a dedicated EEPROM-like region, not the main flash, so the write endurance is higher. Adding wear-leveling logic to a 28-line example would obscure the intent. A comment warning about frequent writes could be added, but it's not blocking.