diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2014-11-26 18:22:18 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2014-11-26 18:22:18 +0100 |
commit | 9d986f5df3c8da646451fc865c1b1e9e2dbdea9c (patch) | |
tree | adb7bffd13160f5ebc066d84f7b2e1659fec1f26 /src/drivers/hmc5883 | |
parent | 2a9a649adbf64ba2c8c56d5a934aa8e09838bec6 (diff) | |
download | px4-firmware-9d986f5df3c8da646451fc865c1b1e9e2dbdea9c.tar.gz px4-firmware-9d986f5df3c8da646451fc865c1b1e9e2dbdea9c.tar.bz2 px4-firmware-9d986f5df3c8da646451fc865c1b1e9e2dbdea9c.zip |
HMC5883: Better status reporting
Diffstat (limited to 'src/drivers/hmc5883')
-rw-r--r-- | src/drivers/hmc5883/hmc5883.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/drivers/hmc5883/hmc5883.cpp b/src/drivers/hmc5883/hmc5883.cpp index 81f767965..d4dbf3778 100644 --- a/src/drivers/hmc5883/hmc5883.cpp +++ b/src/drivers/hmc5883/hmc5883.cpp @@ -1349,7 +1349,7 @@ HMC5883 *g_dev_ext = nullptr; void start(int bus, enum Rotation rotation); void test(int bus); void reset(int bus); -void info(int bus); +int info(int bus); int calibrate(int bus); void usage(); @@ -1595,17 +1595,23 @@ reset(int bus) /** * Print a little info about the driver. */ -void +int info(int bus) { - HMC5883 *g_dev = (bus == PX4_I2C_BUS_ONBOARD?g_dev_int:g_dev_ext); - if (g_dev == nullptr) - errx(1, "driver not running"); + int ret = 1; + + HMC5883 *g_dev = (bus == PX4_I2C_BUS_ONBOARD ? g_dev_int : g_dev_ext); + if (g_dev == nullptr) { + warnx("not running on bus %d", bus); + } else { - printf("state @ %p\n", g_dev); - g_dev->print_info(); + warnx("running on bus: %d (%s)\n", bus, ((PX4_I2C_BUS_ONBOARD) ? "onboard" : "offboard")); - exit(0); + g_dev->print_info(); + ret = 0; + } + + return ret; } void @@ -1685,8 +1691,21 @@ hmc5883_main(int argc, char *argv[]) /* * Print driver information. */ - if (!strcmp(verb, "info") || !strcmp(verb, "status")) - hmc5883::info(bus); + if (!strcmp(verb, "info") || !strcmp(verb, "status")) { + if (bus == -1) { + int ret = 0; + if (hmc5883::info(PX4_I2C_BUS_ONBOARD)) { + ret = 1; + } + + if (hmc5883::info(PX4_I2C_BUS_EXPANSION)) { + ret = 1; + } + exit(ret); + } else { + exit(hmc5883::info(bus)); + } + } /* * Autocalibrate the scaling |