AP_Compass: Do not panic if compass is not found

Copter uses 2 compasses for linux configuration, but one of them may not
be available. Do not panic if a AK8963 isn't found.
This commit is contained in:
Lucas De Marchi 2015-03-18 02:05:48 -03:00 committed by Andrew Tridgell
parent be67b019a7
commit 996739df12
2 changed files with 20 additions and 7 deletions

View File

@ -105,13 +105,6 @@ extern const AP_HAL::HAL& hal;
AK8963_MPU9250_SPI_Backend::AK8963_MPU9250_SPI_Backend()
{
_spi = hal.spi->device(AP_HAL::SPIDevice_MPU9250);
if (_spi == NULL) {
hal.scheduler->panic(PSTR("Cannot get SPIDevice_MPU9250"));
}
_spi_sem = _spi->get_semaphore();
}
bool AK8963_MPU9250_SPI_Backend::sem_take_blocking()
@ -148,6 +141,19 @@ bool AK8963_MPU9250_SPI_Backend::sem_take_nonblocking()
return got;
}
bool AK8963_MPU9250_SPI_Backend::init()
{
_spi = hal.spi->device(AP_HAL::SPIDevice_MPU9250);
if (_spi == NULL) {
hal.console->println_P(PSTR("Cannot get SPIDevice_MPU9250"));
return false;
}
_spi_sem = _spi->get_semaphore();
return true;
}
void AK8963_MPU9250_SPI_Backend::read(uint8_t address, uint8_t *buf, uint32_t count)
{
ASSERT(count < 10);
@ -226,6 +232,11 @@ bool AP_Compass_AK8963_MPU9250::init()
if (_backend == NULL) {
hal.scheduler->panic(PSTR("_backend coudln't be allocated"));
}
if (!_backend->init()) {
delete _backend;
_backend = NULL;
return false;
}
return AP_Compass_AK8963::init();
#else
#error Wrong backend for AK8963 is selected

View File

@ -18,6 +18,7 @@ class AK8963_Backend
virtual bool sem_take_nonblocking() = 0;
virtual bool sem_take_blocking() = 0;
virtual bool sem_give() = 0;
virtual bool init() = 0;
virtual uint8_t read(uint8_t address)
{
uint8_t value;
@ -93,6 +94,7 @@ class AK8963_MPU9250_SPI_Backend: public AK8963_Backend
bool sem_take_nonblocking();
bool sem_take_blocking();
bool sem_give();
bool init() ;
~AK8963_MPU9250_SPI_Backend() {}
private: