diff --git a/docs/Blackbox.md b/docs/Blackbox.md index d770955497d..54c79d4afc1 100644 --- a/docs/Blackbox.md +++ b/docs/Blackbox.md @@ -185,6 +185,7 @@ Available debug modes include: - `POS_EST` - Position estimation debugging - `GPS` - GPS debugging - `ALTITUDE` - Altitude estimation debugging +- `MAG` - Raw, uncalibrated magnetometer samples (useful for external compass calibration) - And 20+ other modes for specific subsystems To use debug mode logging: diff --git a/docs/Settings.md b/docs/Settings.md index 0b8e699ad5b..0ffaf63a6a7 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -796,10 +796,12 @@ Defines debug values exposed in debug variables (developer / debugging setting) | LULU | | | SBUS2 | | | OSD_REFRESH | | +| MAG_CALIB | | | VTOL_TRANSITION | | | VTOL_MC_PROTECT | | | TERRAIN_NAV | | | ESC | | +| MAG | | --- diff --git a/src/main/build/debug.h b/src/main/build/debug.h index 6f4d2af6a01..9551cd9d5de 100644 --- a/src/main/build/debug.h +++ b/src/main/build/debug.h @@ -85,6 +85,7 @@ typedef enum { DEBUG_VTOL_MC_PROTECT, DEBUG_TERRAIN_NAV, DEBUG_ESC, + DEBUG_MAG, DEBUG_COUNT // also update debugModeNames in cli.c } debugType_e; diff --git a/src/main/drivers/compass/compass_mlx90393.c b/src/main/drivers/compass/compass_mlx90393.c index c9318761431..607d2bf6d35 100644 --- a/src/main/drivers/compass/compass_mlx90393.c +++ b/src/main/drivers/compass/compass_mlx90393.c @@ -105,7 +105,9 @@ static bool mlx90393Read(magDev_t * mag) uint8_t buf[7] = {0}; - busReadBuf(mag->busDev, MLX90393_READ_MEASUREMENT | MLX90393_MEASURE_3D, buf, 7); + if (!busReadBuf(mag->busDev, MLX90393_READ_MEASUREMENT | MLX90393_MEASURE_3D, buf, sizeof(buf))) { + return false; + } mag->magADCRaw[X] = ((short)(buf[1] << 8 | buf[2])); mag->magADCRaw[Y] = ((short)(buf[3] << 8 | buf[4])); diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index f2e446077c0..2325037126b 100644 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -235,7 +235,8 @@ static const char *debugModeNames[DEBUG_COUNT] = { "VTOL_TRANSITION", "VTOL_MC_PROTECT", "TERRAIN_NAV", - "ESC" + "ESC", + "MAG" }; /* Sensor names (used in lookup tables for *_hardware settings and in status diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 4bf8c0b8c6e..28cd42ba2e7 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -84,7 +84,8 @@ tables: "VIBE", "CRUISE", "REM_FLIGHT_TIME", "SMARTAUDIO", "ACC", "NAV_YAW", "PCF8574", "DYN_GYRO_LPF", "AUTOLEVEL", "ALTITUDE", "AUTOTRIM", "AUTOTUNE", "RATE_DYNAMICS", "LANDING", "POS_EST", - "ADAPTIVE_FILTER", "HEADTRACKER", "GPS", "LULU", "SBUS2", "OSD_REFRESH", "VTOL_TRANSITION", "VTOL_MC_PROTECT", "TERRAIN_NAV", "ESC"] + "ADAPTIVE_FILTER", "HEADTRACKER", "GPS", "LULU", "SBUS2", "OSD_REFRESH", + "MAG_CALIB", "VTOL_TRANSITION", "VTOL_MC_PROTECT", "TERRAIN_NAV", "ESC", "MAG"] - name: vtol_mc_protection_mode values: ["OFF", "NAV", "NAV_AND_STABILIZED"] - name: aux_operator diff --git a/src/main/sensors/compass.c b/src/main/sensors/compass.c index 601cc98a01f..79bcf167bbc 100644 --- a/src/main/sensors/compass.c +++ b/src/main/sensors/compass.c @@ -467,6 +467,7 @@ void compassUpdate(timeUs_t currentTimeUs) for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) { mag.magADC[axis] = mag.dev.magADCRaw[axis]; // int32_t copy to work with + DEBUG_SET(DEBUG_MAG, axis, mag.dev.magADCRaw[axis]); } if (STATE(CALIBRATE_MAG)) {