hmc5883: fixed use of onboard I2C compass

This commit is contained in:
Andrew Tridgell 2013-05-04 18:44:37 +10:00
parent aa9275c29c
commit d0122dccfc
1 changed files with 10 additions and 4 deletions

View File

@ -1225,19 +1225,25 @@ start()
/* create the driver, attempt expansion bus first */ /* create the driver, attempt expansion bus first */
g_dev = new HMC5883(PX4_I2C_BUS_EXPANSION); g_dev = new HMC5883(PX4_I2C_BUS_EXPANSION);
if (g_dev != nullptr && OK != g_dev->init()) {
delete g_dev;
g_dev = nullptr;
}
#ifdef PX4_I2C_BUS_ONBOARD #ifdef PX4_I2C_BUS_ONBOARD
/* if this failed, attempt onboard sensor */ /* if this failed, attempt onboard sensor */
if (g_dev == nullptr) if (g_dev == nullptr) {
g_dev = new HMC5883(PX4_I2C_BUS_ONBOARD); g_dev = new HMC5883(PX4_I2C_BUS_ONBOARD);
if (g_dev != nullptr && OK != g_dev->init()) {
goto fail;
}
}
#endif #endif
if (g_dev == nullptr) if (g_dev == nullptr)
goto fail; goto fail;
if (OK != g_dev->init())
goto fail;
/* set the poll rate to default, starts automatic data collection */ /* set the poll rate to default, starts automatic data collection */
fd = open(MAG_DEVICE_PATH, O_RDONLY); fd = open(MAG_DEVICE_PATH, O_RDONLY);