Skip to content

Commit 304f6a2

Browse files
feat(steami_config): Update show_config example with all config features. (#353)
* feat(steami_config): display all config fields in show_config.py * style(steami_config): Add blank lines between functions in show_config. * refactor(steami_config): Extract demo data to populate_demo_config.py. * fix(steami_config): Rename Raw JSON section to Raw data in show_config. * docs(steami_config): Add populate_demo_config.py to README examples table. --------- Co-authored-by: Sébastien NEDJAR <sebastien@nedjar.com>
1 parent 8998388 commit 304f6a2

3 files changed

Lines changed: 150 additions & 12 deletions

File tree

lib/steami_config/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ Sensor short keys: `hts` (HTS221), `mag` (LIS2MDL), `ism` (ISM330DL),
204204
| `calibrate_temperature.py` | Calibrate all sensors against WSEN-HIDS reference |
205205
| `calibrate_magnetometer.py` | Calibrate LIS2MDL with OLED display and persistent storage |
206206
| `calibrate_accelerometer.py` | Calibrate ISM330DL accelerometer bias and persist it |
207-
| `boot_counter.py` | Display the amount of boot and increment it |
207+
| `boot_counter.py` | Increment and display the boot counter |
208+
| `populate_demo_config.py` | **WARNING:** Overwrites all config with demo values (testing only) |
208209

209210
Run with mpremote:
210211

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Populate the config zone with demo values for testing.
2+
3+
WARNING: This overwrites all persistent configuration data
4+
(board info, calibrations, boot counter) with fictitious values.
5+
Only use for testing or demonstration purposes.
6+
"""
7+
8+
from daplink_bridge import DaplinkBridge
9+
from machine import I2C
10+
from steami_config import SteamiConfig
11+
12+
i2c = I2C(1)
13+
bridge = DaplinkBridge(i2c)
14+
config = SteamiConfig(bridge)
15+
16+
# Board info
17+
config.board_revision = 3
18+
config.board_name = "STeaMi Demo Board"
19+
20+
# Temperature calibration (example values)
21+
config.set_temperature_calibration("hts221", gain=1.01, offset=-0.5)
22+
config.set_temperature_calibration("lis2mdl", gain=0.99, offset=+0.2)
23+
config.set_temperature_calibration("ism330dl", gain=1.00, offset=0.0)
24+
config.set_temperature_calibration("wsen_hids", gain=1.02, offset=-0.3)
25+
config.set_temperature_calibration("wsen_pads", gain=0.98, offset=+0.4)
26+
27+
# Magnetometer calibration
28+
config.set_magnetometer_calibration(
29+
hard_iron_x=+10.5,
30+
hard_iron_y=-3.2,
31+
hard_iron_z=+1.7,
32+
soft_iron_x=1.02,
33+
soft_iron_y=0.97,
34+
soft_iron_z=1.05,
35+
)
36+
37+
# Accelerometer calibration
38+
config.set_accelerometer_calibration(
39+
ox=+0.01,
40+
oy=-0.02,
41+
oz=+0.03,
42+
)
43+
44+
# Boot counter
45+
config.set_boot_count(42)
46+
47+
# Save everything
48+
config.save()
49+
50+
print("Demo config written. Run show_config.py to verify.")

lib/steami_config/examples/show_config.py

Lines changed: 98 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
from machine import I2C
55
from steami_config import SteamiConfig
66

7+
8+
def print_section(title):
9+
print(title)
10+
print("-" * len(title))
11+
12+
13+
def print_kv(label, value):
14+
print("{:<16} {}".format(label + ":", value))
15+
16+
717
i2c = I2C(1)
818
bridge = DaplinkBridge(i2c)
919
config = SteamiConfig(bridge)
@@ -12,24 +22,101 @@
1222
print("=== STeaMi Configuration ===")
1323
print()
1424

25+
# --------------------------------------------------
26+
# Board info
27+
# --------------------------------------------------
28+
29+
print_section("Board info")
1530
rev = config.board_revision
1631
name = config.board_name
17-
print("Board revision:", rev if rev is not None else "(not set)")
18-
print("Board name: ", name if name is not None else "(not set)")
1932

20-
sensors = ["hts221", "lis2mdl", "ism330dl", "wsen_hids", "wsen_pads"]
33+
print_kv("Board revision", rev if rev is not None else "(not set)")
34+
print_kv("Board name", name if name is not None else "(not set)")
2135
print()
22-
print("Temperature calibration:")
23-
has_cal = False
36+
37+
# --------------------------------------------------
38+
# Temperature calibration
39+
# --------------------------------------------------
40+
41+
print_section("Temperature calibration")
42+
sensors = ["hts221", "lis2mdl", "ism330dl", "wsen_hids", "wsen_pads"]
43+
44+
has_temp_cal = False
2445
for sensor in sensors:
2546
cal = config.get_temperature_calibration(sensor)
2647
if cal is not None:
27-
has_cal = True
28-
print(" {:10s} gain={:.4f} offset={:+.2f} C".format(
29-
sensor, cal["gain"], cal["offset"],
30-
))
31-
if not has_cal:
48+
has_temp_cal = True
49+
print(
50+
" {:10s} gain={:.4f} offset={:+.2f} C".format(
51+
sensor,
52+
cal["gain"],
53+
cal["offset"],
54+
)
55+
)
56+
57+
if not has_temp_cal:
58+
print(" (none)")
59+
print()
60+
61+
# --------------------------------------------------
62+
# Magnetometer calibration
63+
# --------------------------------------------------
64+
65+
print_section("Magnetometer calibration")
66+
mag_cal = config.get_magnetometer_calibration()
67+
68+
if mag_cal is None:
3269
print(" (none)")
70+
else:
71+
print(" Hard iron offsets:")
72+
print(
73+
" x={:+.4f} y={:+.4f} z={:+.4f}".format(
74+
mag_cal["hard_iron_x"],
75+
mag_cal["hard_iron_y"],
76+
mag_cal["hard_iron_z"],
77+
)
78+
)
79+
print(" Soft iron scales:")
80+
print(
81+
" x={:.4f} y={:.4f} z={:.4f}".format(
82+
mag_cal["soft_iron_x"],
83+
mag_cal["soft_iron_y"],
84+
mag_cal["soft_iron_z"],
85+
)
86+
)
87+
print()
88+
89+
# --------------------------------------------------
90+
# Accelerometer calibration
91+
# --------------------------------------------------
92+
93+
print_section("Accelerometer calibration")
94+
accel_cal = config.get_accelerometer_calibration()
3395

96+
if accel_cal is None:
97+
print(" (none)")
98+
else:
99+
print(
100+
" Offsets (g): x={:+.4f} y={:+.4f} z={:+.4f}".format(
101+
accel_cal["ox"],
102+
accel_cal["oy"],
103+
accel_cal["oz"],
104+
)
105+
)
106+
print()
107+
108+
# --------------------------------------------------
109+
# Boot counter
110+
# --------------------------------------------------
111+
112+
print_section("Boot counter")
113+
boot_count = config.get_boot_count()
114+
print(" {}".format(boot_count if boot_count is not None else "(not set)"))
34115
print()
35-
print("Raw JSON:", config._data)
116+
117+
# --------------------------------------------------
118+
# Raw data
119+
# --------------------------------------------------
120+
121+
print_section("Raw data")
122+
print(config._data)

0 commit comments

Comments
 (0)