From 79ba6b0d39dee93be35d3bab5ebdd78429271aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 2 Aug 2018 15:26:39 +0200 Subject: [PATCH] lsm303d: improve error output --- src/drivers/imu/lsm303d/lsm303d.cpp | 32 +++++++++++------------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/drivers/imu/lsm303d/lsm303d.cpp b/src/drivers/imu/lsm303d/lsm303d.cpp index a322b1861b..7cbd553e37 100644 --- a/src/drivers/imu/lsm303d/lsm303d.cpp +++ b/src/drivers/imu/lsm303d/lsm303d.cpp @@ -608,11 +608,11 @@ LSM303D::~LSM303D() int LSM303D::init() { - int ret = PX4_ERROR; - /* do SPI init (and probe) first */ - if (SPI::init() != OK) { - warnx("SPI init failed"); + int ret = SPI::init(); + + if (ret != OK) { + PX4_ERR("SPI init failed (%i)", ret); goto out; } @@ -635,7 +635,7 @@ LSM303D::init() ret = _mag->init(); if (ret != OK) { - warnx("MAG init failed"); + PX4_ERR("MAG init failed (%i)", ret); goto out; } @@ -650,10 +650,6 @@ LSM303D::init() _mag->_mag_topic = orb_advertise_multi(ORB_ID(sensor_mag), &mrp, &_mag->_mag_orb_class_instance, ORB_PRIO_LOW); - if (_mag->_mag_topic == nullptr) { - warnx("ADVERT ERR"); - } - _accel_class_instance = register_class_devname(ACCEL_BASE_DEVICE_PATH); @@ -665,10 +661,6 @@ LSM303D::init() _accel_topic = orb_advertise_multi(ORB_ID(sensor_accel), &arp, &_accel_orb_class_instance, (external()) ? ORB_PRIO_VERY_HIGH : ORB_PRIO_DEFAULT); - if (_accel_topic == nullptr) { - warnx("ADVERT ERR"); - } - out: return ret; } @@ -1827,7 +1819,7 @@ start(bool external_bus, enum Rotation rotation, unsigned range) } if (g_dev == nullptr) { - warnx("failed instantiating LSM303D obj"); + PX4_ERR("failed instantiating LSM303D obj"); goto fail; } @@ -1917,7 +1909,7 @@ test() errx(1, "failed to get if mag is onboard or external"); } - warnx("mag device active: %s", ret ? "external" : "onboard"); + PX4_INFO("mag device active: %s", ret ? "external" : "onboard"); /* do a simple demand read */ sz = read(fd_mag, &m_report, sizeof(m_report)); @@ -1965,7 +1957,7 @@ reset() fd = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY); if (fd < 0) { - warnx("mag could not be opened, external mag might be used"); + PX4_WARN("mag could not be opened, external mag might be used"); } else { /* no need to reset the mag as well, the reset() is the same */ @@ -2029,10 +2021,10 @@ test_error() void usage() { - warnx("missing command: try 'start', 'info', 'test', 'reset', 'testerror' or 'regdump'"); - warnx("options:"); - warnx(" -X (external bus)"); - warnx(" -R rotation"); + PX4_INFO("missing command: try 'start', 'info', 'test', 'reset', 'testerror' or 'regdump'"); + PX4_INFO("options:"); + PX4_INFO(" -X (external bus)"); + PX4_INFO(" -R rotation"); } } // namespace