Skip to content

Commit fe60fbe

Browse files
Charly-sketchnedseb
authored andcommitted
feat(steami_config): display all config fields in show_config.py
1 parent 8998388 commit fe60fbe

1 file changed

Lines changed: 145 additions & 11 deletions

File tree

lib/steami_config/examples/show_config.py

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

7+
8+
def populate_all_config(config):
9+
"""Fill all configuration fields with example values."""
10+
11+
# --------------------------------------------------
12+
# Board info
13+
# --------------------------------------------------
14+
config.board_revision = 3
15+
config.board_name = "STeaMi Demo Board"
16+
17+
# --------------------------------------------------
18+
# Temperature calibration (example values)
19+
# --------------------------------------------------
20+
config.set_temperature_calibration("hts221", gain=1.01, offset=-0.5)
21+
config.set_temperature_calibration("lis2mdl", gain=0.99, offset=+0.2)
22+
config.set_temperature_calibration("ism330dl", gain=1.00, offset=0.0)
23+
config.set_temperature_calibration("wsen_hids", gain=1.02, offset=-0.3)
24+
config.set_temperature_calibration("wsen_pads", gain=0.98, offset=+0.4)
25+
26+
# --------------------------------------------------
27+
# Magnetometer calibration
28+
# --------------------------------------------------
29+
config.set_magnetometer_calibration(
30+
hard_iron_x=+10.5,
31+
hard_iron_y=-3.2,
32+
hard_iron_z=+1.7,
33+
soft_iron_x=1.02,
34+
soft_iron_y=0.97,
35+
soft_iron_z=1.05,
36+
)
37+
38+
# --------------------------------------------------
39+
# Accelerometer calibration
40+
# --------------------------------------------------
41+
config.set_accelerometer_calibration(
42+
ox=+0.01,
43+
oy=-0.02,
44+
oz=+0.03,
45+
)
46+
47+
# --------------------------------------------------
48+
# Boot counter
49+
# --------------------------------------------------
50+
config.set_boot_count(42)
51+
52+
# Save everything
53+
config.save()
54+
55+
def print_section(title):
56+
print(title)
57+
print("-" * len(title))
58+
59+
def print_kv(label, value):
60+
print("{:<16} {}".format(label + ":", value))
61+
762
i2c = I2C(1)
863
bridge = DaplinkBridge(i2c)
964
config = SteamiConfig(bridge)
1065
config.load()
1166

67+
# populate_all_config(config)
68+
1269
print("=== STeaMi Configuration ===")
1370
print()
1471

72+
# --------------------------------------------------
73+
# Board info
74+
# --------------------------------------------------
75+
76+
print_section("Board info")
1577
rev = config.board_revision
1678
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)")
1979

20-
sensors = ["hts221", "lis2mdl", "ism330dl", "wsen_hids", "wsen_pads"]
80+
print_kv("Board revision", rev if rev is not None else "(not set)")
81+
print_kv("Board name", name if name is not None else "(not set)")
2182
print()
22-
print("Temperature calibration:")
23-
has_cal = False
83+
84+
# --------------------------------------------------
85+
# Temperature calibration
86+
# --------------------------------------------------
87+
88+
print_section("Temperature calibration")
89+
sensors = ["hts221", "lis2mdl", "ism330dl", "wsen_hids", "wsen_pads"]
90+
91+
has_temp_cal = False
2492
for sensor in sensors:
2593
cal = config.get_temperature_calibration(sensor)
2694
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:
95+
has_temp_cal = True
96+
print(
97+
" {:10s} gain={:.4f} offset={:+.2f} C".format(
98+
sensor,
99+
cal["gain"],
100+
cal["offset"],
101+
)
102+
)
103+
104+
if not has_temp_cal:
105+
print(" (none)")
106+
print()
107+
108+
# --------------------------------------------------
109+
# Magnetometer calibration
110+
# --------------------------------------------------
111+
112+
print_section("Magnetometer calibration")
113+
mag_cal = config.get_magnetometer_calibration()
114+
115+
if mag_cal is None:
116+
print(" (none)")
117+
else:
118+
print(" Hard iron offsets:")
119+
print(
120+
" x={:+.4f} y={:+.4f} z={:+.4f}".format(
121+
mag_cal["hard_iron_x"],
122+
mag_cal["hard_iron_y"],
123+
mag_cal["hard_iron_z"],
124+
)
125+
)
126+
print(" Soft iron scales:")
127+
print(
128+
" x={:.4f} y={:.4f} z={:.4f}".format(
129+
mag_cal["soft_iron_x"],
130+
mag_cal["soft_iron_y"],
131+
mag_cal["soft_iron_z"],
132+
)
133+
)
134+
print()
135+
136+
# --------------------------------------------------
137+
# Accelerometer calibration
138+
# --------------------------------------------------
139+
140+
print_section("Accelerometer calibration")
141+
accel_cal = config.get_accelerometer_calibration()
142+
143+
if accel_cal is None:
32144
print(" (none)")
145+
else:
146+
print(
147+
" Offsets (g): x={:+.4f} y={:+.4f} z={:+.4f}".format(
148+
accel_cal["ox"],
149+
accel_cal["oy"],
150+
accel_cal["oz"],
151+
)
152+
)
153+
print()
154+
155+
# --------------------------------------------------
156+
# Boot counter
157+
# --------------------------------------------------
33158

159+
print_section("Boot counter")
160+
boot_count = config.get_boot_count()
161+
print(" {}".format(boot_count if boot_count is not None else "(not set)"))
34162
print()
35-
print("Raw JSON:", config._data)
163+
164+
# --------------------------------------------------
165+
# Raw JSON
166+
# --------------------------------------------------
167+
168+
print_section("Raw JSON")
169+
print(config._data)

0 commit comments

Comments
 (0)