-
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
Changes from 4 commits
aabc6e8
d73ec7c
97c1bff
1f5b4ef
95a2d36
05a5d81
369cd25
3be47f5
591af42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -145,12 +145,35 @@ config.apply_accelerometer_calibration(imu) | |||||||||||||||
|
|
||||||||||||||||
| --- | ||||||||||||||||
|
|
||||||||||||||||
| ## Boot counter | ||||||||||||||||
| Store and restore amount of boot of the card. | ||||||||||||||||
|
|
||||||||||||||||
| ### Set boot counter | ||||||||||||||||
| ```python | ||||||||||||||||
| config.set_boot_count(0) | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| ### Get boot counter | ||||||||||||||||
| ```python | ||||||||||||||||
| config.get_boot_count() | ||||||||||||||||
| print("Boot count:", count) | ||||||||||||||||
|
||||||||||||||||
| config.get_boot_count() | |
| print("Boot count:", count) | |
| count = config.get_boot_count() | |
| if count is None: | |
| print("Boot count is not set") | |
| else: | |
| print("Boot count:", count) |
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.
Fixed in 05a5d81: added count = before config.get_boot_count().
Copilot
AI
Apr 9, 2026
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.
The JSON key description for boot_count (“Count of the amount of boot”) is grammatically incorrect/unclear. Please update this table entry to something unambiguous like “Boot count (number of power cycles)”.
| | `boot_count` | Count of the amount of boot | | |
| | `boot_count` | Boot count (number of power cycles) | |
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.
Fixed in 95a2d36: key renamed to "bc" and table entry updated to "Boot counter".
| 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() | ||
|
Comment on lines
+19
to
+23
|
||
|
|
||
| # Read and display | ||
| count = config.get_boot_count() | ||
|
|
||
| print("Boot count:", count) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -338,6 +338,72 @@ tests: | |||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| # -- Mock boot counter -- | ||||||
| - name: "Set and get boot counter" | ||||||
| action: script | ||||||
| script: | | ||||||
| dev._data = {} | ||||||
| dev.set_boot_count(427) | ||||||
| result = dev.get_boot_count() == 427 | ||||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| - name: "Get boot counter returns None when not set" | ||||||
| action: script | ||||||
| script: | | ||||||
| dev._data = {} | ||||||
| result = dev.get_boot_count() is None | ||||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| - name: "Increment boot counter from empty starts at 1" | ||||||
| action: script | ||||||
| script: | | ||||||
| dev._data = {} | ||||||
| dev.increment_boot_count() | ||||||
| result = dev.get_boot_count() == 1 | ||||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| - name: "Increment boot counter increases existing value" | ||||||
| action: script | ||||||
| script: | | ||||||
| dev._data = {} | ||||||
| dev.set_boot_count(41) | ||||||
| dev.increment_boot_count() | ||||||
| result = dev.get_boot_count() == 42 | ||||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| - name: "Boot counter survives save/load" | ||||||
| action: script | ||||||
| script: | | ||||||
| dev._data = {} | ||||||
| dev.set_boot_count(427) | ||||||
| dev.save() | ||||||
| dev2 = SteamiConfig(dev._bridge) | ||||||
| dev2.load() | ||||||
| result = dev2.get_boot_count() == 427 | ||||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| - name: "Boot counter coexists with other config values" | ||||||
| action: script | ||||||
| script: | | ||||||
| dev._data = {} | ||||||
| dev.board_revision = 3 | ||||||
| dev.board_name = "STeaMi-Test" | ||||||
| dev.set_boot_count(12) | ||||||
| dev.set_accelerometer_calibration(ox=0.01, oy=-0.02, oz=0.03) | ||||||
| result = ( | ||||||
| dev.board_revision == 3 | ||||||
| and dev.board_name == "STeaMi-Test" | ||||||
| and dev.get_boot_count() == 12 | ||||||
| and dev.get_accelerometer_calibration()["ox"] == 0.01 | ||||||
| ) | ||||||
| expect_true: true | ||||||
| mode: [mock] | ||||||
|
|
||||||
| # ----- Hardware ----- | ||||||
|
|
||||||
| - name: "Save and load config on hardware" | ||||||
|
|
@@ -541,3 +607,84 @@ tests: | |||||
| ) | ||||||
| expect_true: true | ||||||
| mode: [hardware] | ||||||
|
|
||||||
| # -- Hardware Boot Counter -- | ||||||
|
||||||
| # -- Hardware Boot Counter -- | |
| # -- Hardware Boot Counter -- |
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.
Fixed in 591af42: comment realigned from 4 spaces to 2 spaces, consistent with all other section headers.
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.
The new Boot counter section wording is unclear/incorrect (“amount of boot of the card”) and has trailing spaces in headings. Please rephrase to clearly describe the board boot count (e.g., “number of board boots/power cycles”) and remove the trailing whitespace.
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.
Fixed in 369cd25: reworded to "Track how many times the board has booted." and removed trailing spaces.