mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 12:03:34 +08:00
mpu9250:mag rework the setup to veify HW first
If the setup is unsucessful fo not register the devices or allocate resources.
This commit is contained in:
committed by
Lorenz Meier
parent
aec109ac2c
commit
8bd044e80e
+23
-21
@@ -123,36 +123,38 @@ MPU9250_mag::~MPU9250_mag()
|
|||||||
int
|
int
|
||||||
MPU9250_mag::init()
|
MPU9250_mag::init()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = ak8963_setup();
|
||||||
|
|
||||||
ret = CDev::init();
|
if (ret == OK) {
|
||||||
|
|
||||||
/* if setup failed, bail now */
|
ret = CDev::init();
|
||||||
if (ret != OK) {
|
|
||||||
DEVICE_DEBUG("MPU9250 mag init failed");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
_mag_reports = new ringbuffer::RingBuffer(2, sizeof(mag_report));
|
/* if setup failed, bail now */
|
||||||
|
if (ret != OK) {
|
||||||
|
DEVICE_DEBUG("MPU9250 mag init failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (_mag_reports == nullptr) {
|
_mag_reports = new ringbuffer::RingBuffer(2, sizeof(mag_report));
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
_mag_class_instance = register_class_devname(MAG_BASE_DEVICE_PATH);
|
if (_mag_reports == nullptr) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
ak8963_setup();
|
_mag_class_instance = register_class_devname(MAG_BASE_DEVICE_PATH);
|
||||||
|
|
||||||
/* advertise sensor topic, measure manually to initialize valid report */
|
|
||||||
struct mag_report mrp;
|
|
||||||
_mag_reports->get(&mrp);
|
|
||||||
|
|
||||||
_mag_topic = orb_advertise_multi(ORB_ID(sensor_mag), &mrp,
|
/* advertise sensor topic, measure manually to initialize valid report */
|
||||||
&_mag_orb_class_instance, ORB_PRIO_LOW);
|
struct mag_report mrp;
|
||||||
// &_mag_orb_class_instance, (is_external()) ? ORB_PRIO_MAX - 1 : ORB_PRIO_HIGH - 1);
|
_mag_reports->get(&mrp);
|
||||||
|
|
||||||
if (_mag_topic == nullptr) {
|
_mag_topic = orb_advertise_multi(ORB_ID(sensor_mag), &mrp,
|
||||||
warnx("ADVERT FAIL");
|
&_mag_orb_class_instance, ORB_PRIO_LOW);
|
||||||
|
// &_mag_orb_class_instance, (is_external()) ? ORB_PRIO_MAX - 1 : ORB_PRIO_HIGH - 1);
|
||||||
|
|
||||||
|
if (_mag_topic == nullptr) {
|
||||||
|
warnx("ADVERT FAIL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|||||||
Reference in New Issue
Block a user