|
17 | 17 | from steami_config import SteamiConfig |
18 | 18 |
|
19 | 19 | # --- Init --- |
20 | | -print("Initializing...") |
21 | 20 |
|
22 | 21 | i2c = I2C(1) |
23 | | -print("I2C initialized.") |
24 | 22 | bridge = DaplinkBridge(i2c) |
25 | | -print("DaplinkBridge initialized.") |
26 | 23 | config = SteamiConfig(bridge) |
27 | | -print("SteamiConfig initialized.") |
28 | 24 | config.load() |
29 | 25 |
|
30 | | -print("Initialization complete.\n") |
31 | 26 | imu = ISM330DL(i2c) |
32 | 27 |
|
33 | 28 | print("=== Accelerometer Calibration ===\n") |
|
39 | 34 | samples = 100 |
40 | 35 | sx = sy = sz = 0.0 |
41 | 36 |
|
42 | | -for _i in range(samples): |
| 37 | +for _ in range(samples): |
43 | 38 | ax, ay, az = imu.acceleration_g() |
44 | 39 | sx += ax |
45 | 40 | sy += ay |
|
50 | 45 | ay = sy / samples |
51 | 46 | az = sz / samples |
52 | 47 |
|
53 | | -# Expected: (0, 0, -1g) when flat (screen up) |
| 48 | +# Expected resting orientation: flat, screen up -> (0, 0, -1g) |
54 | 49 | ox = ax |
55 | 50 | oy = ay |
56 | | -oz = az + 1.0 # compensate gravity |
| 51 | +oz = az + 1.0 |
57 | 52 |
|
58 | 53 | print("\nMeasured average:") |
59 | 54 | print(" ax = {:.3f} g".format(ax)) |
60 | 55 | print(" ay = {:.3f} g".format(ay)) |
61 | 56 | print(" az = {:.3f} g".format(az)) |
62 | 57 |
|
63 | 58 | print("\nComputed offsets:") |
64 | | -print(" ox = {:.3f}".format(ox)) |
65 | | -print(" oy = {:.3f}".format(oy)) |
66 | | -print(" oz = {:.3f}".format(oz)) |
| 59 | +print(" ox = {:.3f} g".format(ox)) |
| 60 | +print(" oy = {:.3f} g".format(oy)) |
| 61 | +print(" oz = {:.3f} g".format(oz)) |
67 | 62 |
|
68 | | -# --- Step 2: Save --- |
| 63 | +# --- Step 2: Save to config zone --- |
69 | 64 |
|
70 | 65 | config.set_accelerometer_calibration(ox=ox, oy=oy, oz=oz) |
71 | 66 | config.save() |
72 | 67 |
|
73 | 68 | print("\nCalibration saved to config zone.") |
74 | 69 |
|
75 | | -# --- Step 3: Verify --- |
| 70 | +# --- Step 3: Verify after reload --- |
76 | 71 |
|
77 | 72 | config2 = SteamiConfig(bridge) |
78 | 73 | config2.load() |
79 | 74 |
|
80 | 75 | imu2 = ISM330DL(i2c) |
81 | 76 | config2.apply_accelerometer_calibration(imu2) |
82 | 77 |
|
83 | | -print("\nVerification (5 readings):") |
| 78 | +print("\nApplied offsets after reload:") |
| 79 | +ox2, oy2, oz2 = imu2.get_accel_offset() |
| 80 | +print(" ox = {:.3f} g".format(ox2)) |
| 81 | +print(" oy = {:.3f} g".format(oy2)) |
| 82 | +print(" oz = {:.3f} g".format(oz2)) |
84 | 83 |
|
| 84 | +print("\nVerification (5 corrected readings):") |
85 | 85 | for i in range(5): |
86 | 86 | ax, ay, az = imu2.acceleration_g() |
87 | | - |
88 | | - # Apply offsets manually (driver not patched yet) |
89 | | - ox = getattr(imu2, "_accel_offset_x", 0.0) |
90 | | - oy = getattr(imu2, "_accel_offset_y", 0.0) |
91 | | - oz = getattr(imu2, "_accel_offset_z", 0.0) |
92 | | - |
93 | | - ax -= ox |
94 | | - ay -= oy |
95 | | - az -= oz |
96 | | - |
97 | 87 | print(" {}: ax={:.3f} ay={:.3f} az={:.3f}".format(i + 1, ax, ay, az)) |
98 | 88 | sleep_ms(500) |
99 | 89 |
|
100 | | -print("\nDone! Calibration will persist across reboots.") |
| 90 | +print("\nDone! Calibration is stored and will be restored at next boot.") |
0 commit comments