Browse Source

AP_Compass: prevent NULL deref on enable mag while running

mission-4.1.18
Andrew Tridgell 12 years ago
parent
commit
83c942a512
  1. 7
      libraries/AP_Compass/AP_Compass_HMC5843.cpp

7
libraries/AP_Compass/AP_Compass_HMC5843.cpp

@ -116,6 +116,12 @@ bool AP_Compass_HMC5843::read_raw() @@ -116,6 +116,12 @@ bool AP_Compass_HMC5843::read_raw()
// accumulate a reading from the magnetometer
void AP_Compass_HMC5843::accumulate(void)
{
if (!_initialised) {
// someone has tried to enable a compass for the first time
// mid-flight .... we can't do that yet (especially as we won't
// have the right orientation!)
return;
}
uint32_t tnow = hal.scheduler->micros();
if (healthy && _accum_count != 0 && (tnow - _last_accum_time) < 13333) {
// the compass gets new data at 75Hz
@ -182,6 +188,7 @@ AP_Compass_HMC5843::init() @@ -182,6 +188,7 @@ AP_Compass_HMC5843::init()
}
// determine if we are using 5843 or 5883L
_base_config = 0;
if (!write_register(ConfigRegA, SampleAveraging_8<<5 | DataOutputRate_75HZ<<2 | NormalOperation) ||
!read_register(ConfigRegA, &_base_config)) {
healthy = false;

Loading…
Cancel
Save