ak09916: fail if device is not found

This should fix the case where the driver initializes even though the
device is not found. The change changes the behavior to return ERROR
if the whoami call fails several times instead of returning OK.

Also, the reset() and thus probe() calls are moved before initializing
the ringbuffer and device name.
This commit is contained in:
Julian Oes 2019-04-17 13:53:59 +02:00 committed by Lorenz Meier
parent db37cd8c71
commit c78aaeb0f7
2 changed files with 13 additions and 7 deletions

View File

@ -311,6 +311,8 @@ AK09916::init()
return ret;
}
reset();
_mag_reports = new ringbuffer::RingBuffer(2, sizeof(mag_report));
if (_mag_reports == nullptr) {
@ -319,8 +321,6 @@ AK09916::init()
_mag_class_instance = register_class_devname(MAG_BASE_DEVICE_PATH);
reset();
/* advertise sensor topic, measure manually to initialize valid report */
struct mag_report mrp;
_mag_reports->get(&mrp);
@ -583,8 +583,7 @@ AK09916::write_reg(uint8_t reg, uint8_t value)
int
AK09916::reset(void)
{
// First initialize it to use the bus
int rv = setup();
int rv = probe();
if (rv == OK) {
// Now reset the mag
@ -598,7 +597,7 @@ AK09916::reset(void)
}
int
AK09916::setup(void)
AK09916::probe(void)
{
int retries = 10;
@ -608,12 +607,18 @@ AK09916::setup(void)
uint8_t id = 0;
if (check_id(id)) {
break;
return OK;
}
retries--;
} while (retries > 0);
return PX4_ERROR;
}
int
AK09916::setup(void)
{
write_reg(AK09916REG_CNTL2, AK09916_CNTL2_CONTINOUS_MODE_100HZ);
return OK;
@ -732,4 +737,4 @@ ak09916_main(int argc, char *argv[])
ak09916::usage();
return -1;
}
}

View File

@ -139,6 +139,7 @@ public:
void read_block(uint8_t reg, uint8_t *val, uint8_t count);
int reset(void);
int probe(void);
int setup(void);
void print_info(void);
int setup_master_i2c(void);