mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +08:00
AP_Compass: AK8963: check bus results when calibrating
_calibrate() put the device into fuse-ROM access mode and read the three sensitivity adjustment values, but ignored the result of both transfers. It then computed _magnetometer_ASA from the buffer and returned true regardless, so a failed read left the driver calibrating from stack garbage, and a failed mode change left it calibrating from whatever the registers hold outside fuse-ROM mode. Either way its one caller was told the calibration had succeeded. Return false when either transfer fails, which the caller already handles. The driver's other two register_write() calls already propagate their result. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Barker
co-authored by
Claude Opus 5
parent
b3d9979f06
commit
712cdc7825
@@ -257,11 +257,19 @@ bool AP_Compass_AK8963::_reset()
|
||||
bool AP_Compass_AK8963::_calibrate()
|
||||
{
|
||||
/* Enable FUSE-mode in order to be able to read calibration data */
|
||||
_bus->register_write(AK8963_CNTL1, AK8963_FUSE_MODE | AK8963_16BIT_ADC);
|
||||
if (!_bus->register_write(AK8963_CNTL1, AK8963_FUSE_MODE | AK8963_16BIT_ADC)) {
|
||||
// without fuse-ROM access mode the sensitivity adjustment
|
||||
// registers do not hold the calibration data
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t response[3];
|
||||
|
||||
_bus->block_read(AK8963_ASAX, response, 3);
|
||||
if (!_bus->block_read(AK8963_ASAX, response, 3)) {
|
||||
// the sensitivity adjustment values were not read; response is
|
||||
// undefined, so do not calibrate from it
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float data = response[i];
|
||||
|
||||
Reference in New Issue
Block a user