From aabc6e88eef4b5ecfb0ba1fcc08cb35635303f29 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Tue, 7 Apr 2026 10:28:22 +0200 Subject: [PATCH 1/9] feat(steami_config): add boot counter functionality --- lib/steami_config/steami_config/device.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/steami_config/steami_config/device.py b/lib/steami_config/steami_config/device.py index 398341c2..4fecec59 100644 --- a/lib/steami_config/steami_config/device.py +++ b/lib/steami_config/steami_config/device.py @@ -254,3 +254,22 @@ def apply_accelerometer_calibration(self, ism330dl_instance): cal["oy"], cal["oz"], ) + + # -------------------------------------------------- + # Boot counter + # -------------------------------------------------- + + def set_boot_count(self, count): + """Store the number of times the board has booted.""" + self._data["boot_count"] = int(count) + + def get_boot_count(self): + """Return the stored boot count, or None.""" + return self._data.get("boot_count") + + def increment_boot_count(self): + """Increment the stored boot count by 1.""" + count = self.get_boot_count() + if count is None: + count = 0 + self.set_boot_count(count + 1) From d73ec7ce7be33bccd6b96e03e99a29ae19251045 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Tue, 7 Apr 2026 10:28:47 +0200 Subject: [PATCH 2/9] feat(steami_config): add boot counter example --- lib/steami_config/examples/boot_counter.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/steami_config/examples/boot_counter.py diff --git a/lib/steami_config/examples/boot_counter.py b/lib/steami_config/examples/boot_counter.py new file mode 100644 index 00000000..f7807ff6 --- /dev/null +++ b/lib/steami_config/examples/boot_counter.py @@ -0,0 +1,21 @@ +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) From 97c1bffafdc49f5c93b0df2caeed567228ebdfd8 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Tue, 7 Apr 2026 10:49:50 +0200 Subject: [PATCH 3/9] docs(steami_config): add boot counter to readme --- lib/steami_config/README.md | 27 +++++++++++++++++++++- lib/steami_config/examples/boot_counter.py | 7 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/steami_config/README.md b/lib/steami_config/README.md index 5335b03f..2fe978f8 100644 --- a/lib/steami_config/README.md +++ b/lib/steami_config/README.md @@ -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) +# -> Boot count: 0 +``` + +### Increment boot counter +```python +config.increment_boot_count() +# -> boot_count = boot_count + 1 +``` + +--- + # JSON Format Data is stored as compact JSON to fit within 1 KB: ```json -{"rev":3,"name":"STeaMi-01","tc":{"hts":{"g":1.0,"o":-0.5}},"cm":{"hx":12.3,"hy":-5.1,"hz":0.8,"sx":1.01,"sy":0.98,"sz":1.0},"ca":{"ox":0.01,"oy":-0.02,"oz":0.03}} +{"rev":3,"name":"STeaMi-01","tc":{"hts":{"g":1.0,"o":-0.5}},"cm":{"hx":12.3,"hy":-5.1,"hz":0.8,"sx":1.01,"sy":0.98,"sz":1.0},"ca":{"ox":0.01,"oy":-0.02,"oz":0.03},"boot_count":0} ``` | Key | Content | @@ -165,6 +188,7 @@ Data is stored as compact JSON to fit within 1 KB: | `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 | Sensor short keys: `hts` (HTS221), `mag` (LIS2MDL), `ism` (ISM330DL), `hid` (WSEN-HIDS), `pad` (WSEN-PADS). @@ -179,6 +203,7 @@ Sensor short keys: `hts` (HTS221), `mag` (LIS2MDL), `ism` (ISM330DL), | `calibrate_temperature.py` | Calibrate all sensors against WSEN-HIDS reference | | `calibrate_magnetometer.py` | Calibrate LIS2MDL with OLED display and persistent storage | | `calibrate_accelerometer.py` | Calibrate ISM330DL accelerometer bias and persist it | +| `boot_counter.py` | Display the amount of boot and increment it | Run with mpremote: diff --git a/lib/steami_config/examples/boot_counter.py b/lib/steami_config/examples/boot_counter.py index f7807ff6..08a0b7fb 100644 --- a/lib/steami_config/examples/boot_counter.py +++ b/lib/steami_config/examples/boot_counter.py @@ -1,3 +1,10 @@ +""" +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 From 1f5b4ef0ed364a20a087ce7a80780fa121e4cff6 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Tue, 7 Apr 2026 10:59:17 +0200 Subject: [PATCH 4/9] test(steami_config): add boot counter mock and hardware tests --- tests/scenarios/steami_config.yaml | 147 +++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/tests/scenarios/steami_config.yaml b/tests/scenarios/steami_config.yaml index 60210166..7590eef8 100644 --- a/tests/scenarios/steami_config.yaml +++ b/tests/scenarios/steami_config.yaml @@ -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 -- + - name: "Save and load boot counter on hardware" + action: script + script: | + from time import sleep_ms + dev._bridge.clear_config() + dev._data = {} + dev.set_boot_count(427) + dev.save() + sleep_ms(200) + dev2 = SteamiConfig(dev._bridge) + dev2.load() + result = dev2.get_boot_count() == 427 + expect_true: true + mode: [hardware] + + - name: "Increment boot counter on hardware" + action: script + script: | + from time import sleep_ms + dev._bridge.clear_config() + dev._data = {} + dev.set_boot_count(5) + dev.save() + sleep_ms(200) + + dev2 = SteamiConfig(dev._bridge) + dev2.load() + dev2.increment_boot_count() + dev2.save() + sleep_ms(200) + + dev3 = SteamiConfig(dev._bridge) + dev3.load() + result = dev3.get_boot_count() == 6 + expect_true: true + mode: [hardware] + + - name: "Boot counter survives clear_flash" + action: script + script: | + from time import sleep_ms + from daplink_flash import DaplinkFlash + dev._bridge.clear_config() + dev._data = {} + dev.set_boot_count(99) + dev.save() + sleep_ms(200) + + flash = DaplinkFlash(dev._bridge) + flash.clear_flash() + sleep_ms(500) + + dev2 = SteamiConfig(dev._bridge) + dev2.load() + result = dev2.get_boot_count() == 99 + expect_true: true + mode: [hardware] + + - name: "Boot counter coexists with temperature calibration on hardware" + action: script + script: | + from time import sleep_ms + dev._bridge.clear_config() + dev._data = {} + dev.set_boot_count(12) + dev.set_temperature_calibration("hts221", gain=1.05, offset=-0.3) + dev.save() + sleep_ms(200) + + dev2 = SteamiConfig(dev._bridge) + dev2.load() + tc = dev2.get_temperature_calibration("hts221") + result = ( + dev2.get_boot_count() == 12 + and tc["gain"] == 1.05 + and tc["offset"] == -0.3 + ) + expect_true: true + mode: [hardware] From 95a2d366615f9a961ba381d14a8a95b071f05c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:02:48 +0200 Subject: [PATCH 5/9] fix(steami_config): Shorten boot counter JSON key to "bc" for consistency. --- lib/steami_config/README.md | 4 ++-- lib/steami_config/steami_config/device.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/steami_config/README.md b/lib/steami_config/README.md index 2fe978f8..33611001 100644 --- a/lib/steami_config/README.md +++ b/lib/steami_config/README.md @@ -173,7 +173,7 @@ config.increment_boot_count() Data is stored as compact JSON to fit within 1 KB: ```json -{"rev":3,"name":"STeaMi-01","tc":{"hts":{"g":1.0,"o":-0.5}},"cm":{"hx":12.3,"hy":-5.1,"hz":0.8,"sx":1.01,"sy":0.98,"sz":1.0},"ca":{"ox":0.01,"oy":-0.02,"oz":0.03},"boot_count":0} +{"rev":3,"name":"STeaMi-01","tc":{"hts":{"g":1.0,"o":-0.5}},"cm":{"hx":12.3,"hy":-5.1,"hz":0.8,"sx":1.01,"sy":0.98,"sz":1.0},"ca":{"ox":0.01,"oy":-0.02,"oz":0.03},"bc":0} ``` | Key | Content | @@ -188,7 +188,7 @@ Data is stored as compact JSON to fit within 1 KB: | `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 | +| `bc` | Boot counter | Sensor short keys: `hts` (HTS221), `mag` (LIS2MDL), `ism` (ISM330DL), `hid` (WSEN-HIDS), `pad` (WSEN-PADS). diff --git a/lib/steami_config/steami_config/device.py b/lib/steami_config/steami_config/device.py index 4fecec59..47eb36f6 100644 --- a/lib/steami_config/steami_config/device.py +++ b/lib/steami_config/steami_config/device.py @@ -261,11 +261,11 @@ def apply_accelerometer_calibration(self, ism330dl_instance): def set_boot_count(self, count): """Store the number of times the board has booted.""" - self._data["boot_count"] = int(count) + self._data["bc"] = int(count) def get_boot_count(self): """Return the stored boot count, or None.""" - return self._data.get("boot_count") + return self._data.get("bc") def increment_boot_count(self): """Increment the stored boot count by 1.""" From 05a5d814bf04ef3e17ed3946f1b275d8c4421876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:05:06 +0200 Subject: [PATCH 6/9] fix(steami_config): Fix missing variable assignment in README boot counter. --- lib/steami_config/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/steami_config/README.md b/lib/steami_config/README.md index 33611001..941dc3e0 100644 --- a/lib/steami_config/README.md +++ b/lib/steami_config/README.md @@ -153,9 +153,9 @@ Store and restore amount of boot of the card. config.set_boot_count(0) ``` -### Get boot counter +### Get boot counter ```python -config.get_boot_count() +count = config.get_boot_count() print("Boot count:", count) # -> Boot count: 0 ``` From 369cd2518247275a22b96a8d56100687f2a4998f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:05:49 +0200 Subject: [PATCH 7/9] docs(steami_config): Improve boot counter section wording in README. --- lib/steami_config/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/steami_config/README.md b/lib/steami_config/README.md index 941dc3e0..cf0def34 100644 --- a/lib/steami_config/README.md +++ b/lib/steami_config/README.md @@ -145,8 +145,9 @@ config.apply_accelerometer_calibration(imu) --- -## Boot counter -Store and restore amount of boot of the card. +## Boot Counter + +Track how many times the board has booted. ### Set boot counter ```python From 3be47f513e1450fd00ae6d4c5659f79666a23a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:07:11 +0200 Subject: [PATCH 8/9] style(steami_config): Remove trailing spaces in README. --- lib/steami_config/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/steami_config/README.md b/lib/steami_config/README.md index cf0def34..f0986101 100644 --- a/lib/steami_config/README.md +++ b/lib/steami_config/README.md @@ -149,7 +149,7 @@ config.apply_accelerometer_calibration(imu) Track how many times the board has booted. -### Set boot counter +### Set boot counter ```python config.set_boot_count(0) ``` @@ -167,7 +167,7 @@ config.increment_boot_count() # -> boot_count = boot_count + 1 ``` ---- +--- # JSON Format From 591af4202aee97db4e68c83da975e8e207205ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:08:15 +0200 Subject: [PATCH 9/9] style(steami_config): Fix comment indentation in boot counter tests. --- tests/scenarios/steami_config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scenarios/steami_config.yaml b/tests/scenarios/steami_config.yaml index 7590eef8..6dcfb0cb 100644 --- a/tests/scenarios/steami_config.yaml +++ b/tests/scenarios/steami_config.yaml @@ -608,7 +608,7 @@ tests: expect_true: true mode: [hardware] - # -- Hardware Boot Counter -- + # -- Hardware Boot Counter -- - name: "Save and load boot counter on hardware" action: script script: |