|
4 | 4 | from machine import I2C |
5 | 5 | from steami_config import SteamiConfig |
6 | 6 |
|
| 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 | + |
7 | 62 | i2c = I2C(1) |
8 | 63 | bridge = DaplinkBridge(i2c) |
9 | 64 | config = SteamiConfig(bridge) |
10 | 65 | config.load() |
11 | 66 |
|
| 67 | +# populate_all_config(config) |
| 68 | + |
12 | 69 | print("=== STeaMi Configuration ===") |
13 | 70 | print() |
14 | 71 |
|
| 72 | +# -------------------------------------------------- |
| 73 | +# Board info |
| 74 | +# -------------------------------------------------- |
| 75 | + |
| 76 | +print_section("Board info") |
15 | 77 | rev = config.board_revision |
16 | 78 | 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)") |
19 | 79 |
|
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)") |
21 | 82 | 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 |
24 | 92 | for sensor in sensors: |
25 | 93 | cal = config.get_temperature_calibration(sensor) |
26 | 94 | 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: |
32 | 144 | 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 | +# -------------------------------------------------- |
33 | 158 |
|
| 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)")) |
34 | 162 | 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