feat: Auto-detect magnetometer + barometer (#24) #27
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "sl-firmware/mag-baro-detect"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Auto-detects external I2C sensors at boot and adds telemetry fields when present. Skips gracefully if hardware not connected.
Shared I2C1 bus (
i2c1.c/h)i2c1_init()initializes PB8=SCL / PB9=SDA at 100 kHz.hi2c1is a global handle used by both sensor drivers. Called once inmain()before probing.Barometer (
bmp280.c/h)bmp280_pressure_to_alt_cm()— ISA barometric formulabmp280.h(was missing from the repo)Magnetometer (
mag.c/h)Auto-detects in order:
mag_read_heading()returns heading in degrees×10 (0–3599), -1 if not ready.Telemetry JSON
Base fields unchanged. Optional fields appended when sensor present:
"hd":<n>— compass heading, degrees×10 (mag detected)"alt":<n>— altitude in cm above sea level (baro detected)No extra bytes in packet when sensors absent.
UI
HEADING and ALT stat rows are hidden until first packet containing that field. Heading shown in degrees, altitude in metres.
Test plan
altappears in JSON, ALT row visible in UIhdappears, HEADING row visible, rotates with compassCloses #24.
Flash-tested all 3 together. Gyro cal eliminates yaw drift, LEDs solid, I2C probe clean.