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: 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 a4972575..ffcc0b51 100644 --- a/lib/steami_config/examples/show_config.py +++ b/lib/steami_config/examples/show_config.py @@ -4,6 +4,16 @@ from machine import I2C from steami_config import SteamiConfig + +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) @@ -12,24 +22,101 @@ 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 data +# -------------------------------------------------- + +print_section("Raw data") +print(config._data)