From fe60fbe9069d373e07449ba128ebe791f5f96d74 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Tue, 7 Apr 2026 16:30:26 +0200 Subject: [PATCH 1/5] feat(steami_config): display all config fields in show_config.py --- lib/steami_config/examples/show_config.py | 156 ++++++++++++++++++++-- 1 file changed, 145 insertions(+), 11 deletions(-) diff --git a/lib/steami_config/examples/show_config.py b/lib/steami_config/examples/show_config.py index a4972575..6f1b98a9 100644 --- a/lib/steami_config/examples/show_config.py +++ b/lib/steami_config/examples/show_config.py @@ -4,32 +4,166 @@ from machine import I2C from steami_config import SteamiConfig + +def populate_all_config(config): + """Fill all configuration fields with example values.""" + + # -------------------------------------------------- + # Board info + # -------------------------------------------------- + config.board_revision = 3 + config.board_name = "STeaMi Demo Board" + + # -------------------------------------------------- + # Temperature calibration (example values) + # -------------------------------------------------- + config.set_temperature_calibration("hts221", gain=1.01, offset=-0.5) + config.set_temperature_calibration("lis2mdl", gain=0.99, offset=+0.2) + config.set_temperature_calibration("ism330dl", gain=1.00, offset=0.0) + config.set_temperature_calibration("wsen_hids", gain=1.02, offset=-0.3) + config.set_temperature_calibration("wsen_pads", gain=0.98, offset=+0.4) + + # -------------------------------------------------- + # Magnetometer calibration + # -------------------------------------------------- + config.set_magnetometer_calibration( + hard_iron_x=+10.5, + hard_iron_y=-3.2, + hard_iron_z=+1.7, + soft_iron_x=1.02, + soft_iron_y=0.97, + soft_iron_z=1.05, + ) + + # -------------------------------------------------- + # Accelerometer calibration + # -------------------------------------------------- + config.set_accelerometer_calibration( + ox=+0.01, + oy=-0.02, + oz=+0.03, + ) + + # -------------------------------------------------- + # Boot counter + # -------------------------------------------------- + config.set_boot_count(42) + + # Save everything + config.save() + +def print_section(title): + print(title) + print("-" * len(title)) + +def print_kv(label, value): + print("{:<16} {}".format(label + ":", value)) + i2c = I2C(1) bridge = DaplinkBridge(i2c) config = SteamiConfig(bridge) config.load() +# populate_all_config(config) + print("=== STeaMi Configuration ===") print() +# -------------------------------------------------- +# Board info +# -------------------------------------------------- + +print_section("Board info") rev = config.board_revision name = config.board_name -print("Board revision:", rev if rev is not None else "(not set)") -print("Board name: ", name if name is not None else "(not set)") -sensors = ["hts221", "lis2mdl", "ism330dl", "wsen_hids", "wsen_pads"] +print_kv("Board revision", rev if rev is not None else "(not set)") +print_kv("Board name", name if name is not None else "(not set)") print() -print("Temperature calibration:") -has_cal = False + +# -------------------------------------------------- +# Temperature calibration +# -------------------------------------------------- + +print_section("Temperature calibration") +sensors = ["hts221", "lis2mdl", "ism330dl", "wsen_hids", "wsen_pads"] + +has_temp_cal = False for sensor in sensors: cal = config.get_temperature_calibration(sensor) if cal is not None: - has_cal = True - print(" {:10s} gain={:.4f} offset={:+.2f} C".format( - sensor, cal["gain"], cal["offset"], - )) -if not has_cal: + has_temp_cal = True + print( + " {:10s} gain={:.4f} offset={:+.2f} C".format( + sensor, + cal["gain"], + cal["offset"], + ) + ) + +if not has_temp_cal: + print(" (none)") +print() + +# -------------------------------------------------- +# Magnetometer calibration +# -------------------------------------------------- + +print_section("Magnetometer calibration") +mag_cal = config.get_magnetometer_calibration() + +if mag_cal is None: + print(" (none)") +else: + print(" Hard iron offsets:") + print( + " x={:+.4f} y={:+.4f} z={:+.4f}".format( + mag_cal["hard_iron_x"], + mag_cal["hard_iron_y"], + mag_cal["hard_iron_z"], + ) + ) + print(" Soft iron scales:") + print( + " x={:.4f} y={:.4f} z={:.4f}".format( + mag_cal["soft_iron_x"], + mag_cal["soft_iron_y"], + mag_cal["soft_iron_z"], + ) + ) +print() + +# -------------------------------------------------- +# Accelerometer calibration +# -------------------------------------------------- + +print_section("Accelerometer calibration") +accel_cal = config.get_accelerometer_calibration() + +if accel_cal is None: print(" (none)") +else: + print( + " Offsets (g): x={:+.4f} y={:+.4f} z={:+.4f}".format( + accel_cal["ox"], + accel_cal["oy"], + accel_cal["oz"], + ) + ) +print() + +# -------------------------------------------------- +# Boot counter +# -------------------------------------------------- +print_section("Boot counter") +boot_count = config.get_boot_count() +print(" {}".format(boot_count if boot_count is not None else "(not set)")) print() -print("Raw JSON:", config._data) + +# -------------------------------------------------- +# Raw JSON +# -------------------------------------------------- + +print_section("Raw JSON") +print(config._data) From c41f8109861df62c3537d73e50261fd3b413e87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:40:24 +0200 Subject: [PATCH 2/5] style(steami_config): Add blank lines between functions in show_config. --- lib/steami_config/examples/show_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/steami_config/examples/show_config.py b/lib/steami_config/examples/show_config.py index 6f1b98a9..bda75787 100644 --- a/lib/steami_config/examples/show_config.py +++ b/lib/steami_config/examples/show_config.py @@ -52,10 +52,12 @@ def populate_all_config(config): # Save everything config.save() + def print_section(title): print(title) print("-" * len(title)) + def print_kv(label, value): print("{:<16} {}".format(label + ":", value)) From a1e90bd5a8207cf0d8cba23289f21386a996b512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 14:46:24 +0200 Subject: [PATCH 3/5] refactor(steami_config): Extract demo data to populate_demo_config.py. --- .../examples/populate_demo_config.py | 50 ++++++++++++++++++ lib/steami_config/examples/show_config.py | 51 +------------------ 2 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 lib/steami_config/examples/populate_demo_config.py diff --git a/lib/steami_config/examples/populate_demo_config.py b/lib/steami_config/examples/populate_demo_config.py new file mode 100644 index 00000000..77d29b98 --- /dev/null +++ b/lib/steami_config/examples/populate_demo_config.py @@ -0,0 +1,50 @@ +"""Populate the config zone with demo values for testing. + +WARNING: This overwrites all persistent configuration data +(board info, calibrations, boot counter) with fictitious values. +Only use for testing or demonstration purposes. +""" + +from daplink_bridge import DaplinkBridge +from machine import I2C +from steami_config import SteamiConfig + +i2c = I2C(1) +bridge = DaplinkBridge(i2c) +config = SteamiConfig(bridge) + +# Board info +config.board_revision = 3 +config.board_name = "STeaMi Demo Board" + +# Temperature calibration (example values) +config.set_temperature_calibration("hts221", gain=1.01, offset=-0.5) +config.set_temperature_calibration("lis2mdl", gain=0.99, offset=+0.2) +config.set_temperature_calibration("ism330dl", gain=1.00, offset=0.0) +config.set_temperature_calibration("wsen_hids", gain=1.02, offset=-0.3) +config.set_temperature_calibration("wsen_pads", gain=0.98, offset=+0.4) + +# Magnetometer calibration +config.set_magnetometer_calibration( + hard_iron_x=+10.5, + hard_iron_y=-3.2, + hard_iron_z=+1.7, + soft_iron_x=1.02, + soft_iron_y=0.97, + soft_iron_z=1.05, +) + +# Accelerometer calibration +config.set_accelerometer_calibration( + ox=+0.01, + oy=-0.02, + oz=+0.03, +) + +# Boot counter +config.set_boot_count(42) + +# Save everything +config.save() + +print("Demo config written. Run show_config.py to verify.") diff --git a/lib/steami_config/examples/show_config.py b/lib/steami_config/examples/show_config.py index bda75787..e18b01b4 100644 --- a/lib/steami_config/examples/show_config.py +++ b/lib/steami_config/examples/show_config.py @@ -5,54 +5,6 @@ from steami_config import SteamiConfig -def populate_all_config(config): - """Fill all configuration fields with example values.""" - - # -------------------------------------------------- - # Board info - # -------------------------------------------------- - config.board_revision = 3 - config.board_name = "STeaMi Demo Board" - - # -------------------------------------------------- - # Temperature calibration (example values) - # -------------------------------------------------- - config.set_temperature_calibration("hts221", gain=1.01, offset=-0.5) - config.set_temperature_calibration("lis2mdl", gain=0.99, offset=+0.2) - config.set_temperature_calibration("ism330dl", gain=1.00, offset=0.0) - config.set_temperature_calibration("wsen_hids", gain=1.02, offset=-0.3) - config.set_temperature_calibration("wsen_pads", gain=0.98, offset=+0.4) - - # -------------------------------------------------- - # Magnetometer calibration - # -------------------------------------------------- - config.set_magnetometer_calibration( - hard_iron_x=+10.5, - hard_iron_y=-3.2, - hard_iron_z=+1.7, - soft_iron_x=1.02, - soft_iron_y=0.97, - soft_iron_z=1.05, - ) - - # -------------------------------------------------- - # Accelerometer calibration - # -------------------------------------------------- - config.set_accelerometer_calibration( - ox=+0.01, - oy=-0.02, - oz=+0.03, - ) - - # -------------------------------------------------- - # Boot counter - # -------------------------------------------------- - config.set_boot_count(42) - - # Save everything - config.save() - - def print_section(title): print(title) print("-" * len(title)) @@ -61,13 +13,12 @@ def print_section(title): def print_kv(label, value): print("{:<16} {}".format(label + ":", value)) + i2c = I2C(1) bridge = DaplinkBridge(i2c) config = SteamiConfig(bridge) config.load() -# populate_all_config(config) - print("=== STeaMi Configuration ===") print() From b80dd88c27aefeb6abaa05daafbf4f2f165d5198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 15:04:45 +0200 Subject: [PATCH 4/5] fix(steami_config): Rename Raw JSON section to Raw data in show_config. --- lib/steami_config/examples/show_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/steami_config/examples/show_config.py b/lib/steami_config/examples/show_config.py index e18b01b4..ffcc0b51 100644 --- a/lib/steami_config/examples/show_config.py +++ b/lib/steami_config/examples/show_config.py @@ -115,8 +115,8 @@ def print_kv(label, value): print() # -------------------------------------------------- -# Raw JSON +# Raw data # -------------------------------------------------- -print_section("Raw JSON") +print_section("Raw data") print(config._data) From d64031ea5ceb14c179d650994734addfe1d837ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 9 Apr 2026 15:05:45 +0200 Subject: [PATCH 5/5] docs(steami_config): Add populate_demo_config.py to README examples table. --- lib/steami_config/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/steami_config/README.md b/lib/steami_config/README.md index f0986101..42f0cafd 100644 --- a/lib/steami_config/README.md +++ b/lib/steami_config/README.md @@ -204,7 +204,8 @@ 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 | +| `boot_counter.py` | Increment and display the boot counter | +| `populate_demo_config.py` | **WARNING:** Overwrites all config with demo values (testing only) | Run with mpremote: