Skip to content

steami_config: Add boot counter.#352

Merged
nedseb merged 9 commits intomainfrom
feat/update-show-config-example
Apr 9, 2026
Merged

steami_config: Add boot counter.#352
nedseb merged 9 commits intomainfrom
feat/update-show-config-example

Conversation

@Charly-sketch
Copy link
Copy Markdown
Contributor

@Charly-sketch Charly-sketch commented Apr 7, 2026

Summary

Closes #172

Add support for a persistent boot counter in SteamiConfig to track the number of power cycles. This is useful for diagnostics, debugging reboot loops, and usage tracking.

The boot count is stored in the config zone using a compact JSON format:

{"boot_count": 427}

Part of #166
Depends on #167 (config zone driver methods)


Changes

  • Add set_boot_count(count) method to store boot count

  • Add get_boot_count() method to retrieve boot count

  • Add increment_boot_count() helper to safely increment the counter

  • Store boot counter in config JSON under "boot_count"

  • Ensure safe behavior when value is missing (defaults to 0 on increment)

  • Add example demonstrating boot counter usage at startup

  • Add mock tests:

    • set/get boot count
    • increment from empty and existing values
    • persistence across save/load
    • coexistence with other config fields
  • Add hardware tests:

    • persistence across save/load
    • increment behavior on device
    • coexistence with other config data
==== 59 passed in 112.99s (0:01:52) ===

Checklist

  • ruff check passes
  • python -m pytest tests/ -k mock -v passes (no mock test broken)
  • Tested on hardware (if applicable)
  • README updated (if adding/changing public API)
  • Examples added/updated (if applicable)
  • Commit messages follow <scope>: <Description.> format

@Charly-sketch Charly-sketch changed the title feat(steami_config): Update show_config example with all config features. steami_config: Add boot counter. #172 Apr 7, 2026
@Charly-sketch Charly-sketch changed the title steami_config: Add boot counter. #172 steami_config: Add boot counter. Apr 7, 2026
@Charly-sketch Charly-sketch requested a review from nedseb April 7, 2026 09:07
@Charly-sketch Charly-sketch marked this pull request as ready for review April 7, 2026 09:07
@nedseb nedseb requested a review from Copilot April 9, 2026 11:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a persistent boot counter to SteamiConfig (stored in the DAPLink config zone JSON) to track device power cycles for diagnostics and usage tracking.

Changes:

  • Add set_boot_count(), get_boot_count(), and increment_boot_count() to SteamiConfig.
  • Extend mock + hardware scenario coverage for boot counter persistence/coexistence.
  • Update steami_config README and add a new boot_counter.py example.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
lib/steami_config/steami_config/device.py Implements the boot counter API on top of existing JSON persistence.
tests/scenarios/steami_config.yaml Adds mock and hardware scenario scripts for set/get/increment and persistence/coexistence.
lib/steami_config/README.md Documents the new boot counter feature and updates the JSON schema + examples list.
lib/steami_config/examples/boot_counter.py Provides a startup-time example that increments and saves the boot counter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/steami_config/README.md Outdated
Comment on lines +158 to +159
config.get_boot_count()
print("Boot count:", count)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Get boot counter” README snippet calls config.get_boot_count() but then prints count, which is never assigned. Assign the return value to count (and consider showing the None case since get_boot_count() can return None when unset).

Suggested change
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)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

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().

Comment thread lib/steami_config/README.md Outdated
Comment on lines +148 to +151
## Boot counter
Store and restore amount of boot of the card.

### Set boot counter
Copy link

Copilot AI Apr 9, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

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.

Comment thread lib/steami_config/README.md Outdated
| `cm.sx/sy/sz` | Soft-iron scale factors (X, Y, Z) |
| `ca` | Accelerometer calibration dict |
| `ca.ox/oy/oz` | Bias offsets in g (X, Y, Z) |
| `boot_count` | Count of the amount of boot |
Copy link

Copilot AI Apr 9, 2026

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)”.

Suggested change
| `boot_count` | Count of the amount of boot |
| `boot_count` | Boot count (number of power cycles) |

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

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".

Comment on lines +19 to +23
# --- Boot counter logic ---
config.increment_boot_count()

# Save updated value
config.save()
Copy link

Copilot AI Apr 9, 2026

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(). Since SteamiConfig.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).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

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.

Comment thread tests/scenarios/steami_config.yaml Outdated
expect_true: true
mode: [hardware]

# -- Hardware Boot Counter --
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Hardware Boot Counter” section header comment is indented under the previous test case (same indentation as mode:), which makes the YAML harder to scan. Align this comment with the other section headers at the list indentation level for consistency/readability.

Suggested change
# -- Hardware Boot Counter --
# -- Hardware Boot Counter --

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

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.

@nedseb
Copy link
Copy Markdown
Contributor

nedseb commented Apr 9, 2026

Review & corrections applied

What was reviewed

Good PR — code is simple, well-tested (6 mock + 4 hardware), and the example is clear. A few issues were found and corrected directly on the branch.

Corrections applied

Commit Fix
95a2d36 JSON key "boot_count""bc" — consistent with existing short keys ("tc", "cm", "ca"). Saves 8 bytes per entry in the 1 KB config zone. Public API methods unchanged. See comment on #172 for rationale.
05a5d81 README: missing count = before config.get_boot_count() — copy-paste from the README would have failed
369cd25 README: description reworded — "Store and restore amount of boot of the card" → "Track how many times the board has booted"
3be47f5 README: trailing spaces removed from section headers and separator
591af42 YAML: comment indentation# -- Hardware Boot Counter -- aligned from 4 spaces to 2 spaces, matching all other section headers

Not changed

  • Flash wear concern (Copilot comment): the example writes on every boot, which could wear the flash in a reboot loop. This is acceptable for a pedagogical example — the config zone uses a dedicated EEPROM-like region with higher endurance than main flash. Adding wear-leveling logic would obscure the example's intent.
  • Commit message points final: Charly's 4 commits don't end with a period (convention from CONTRIBUTING.md). Not fixable without rebase — noted for next time.

Status

All 5 Copilot comments addressed. 46 mock tests pass. Ready to merge (squash recommended to clean up the 9-commit history).

@nedseb nedseb merged commit 92f8795 into main Apr 9, 2026
9 checks passed
@nedseb nedseb deleted the feat/update-show-config-example branch April 9, 2026 12:21
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.12.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

steami_config: Add boot counter.

3 participants