From fd675084ccd58f21d7e858ad91a00a12acdd4a00 Mon Sep 17 00:00:00 2001 From: DanielePettenuzzo Date: Sun, 17 Jun 2018 13:41:19 +0200 Subject: [PATCH] ms5525_airspeed: add -a flag to scan all i2c busses during start --- .../ms4525/ms4525_airspeed.cpp | 18 ++++-- .../ms5525/MS5525_main.cpp | 63 ++++++++++++++++--- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp b/src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp index 862bc4c582..acffd7ebb6 100644 --- a/src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp +++ b/src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp @@ -394,11 +394,13 @@ int stop(); int reset(); /** - * Start the driver. - * - * This function call only returns once the driver is up and running - * or failed to detect the sensor. - */ +* Attempt to start driver on all available I2C busses. +* +* This function will return as soon as the first sensor +* is detected on one of the available busses or if no +* sensors are detected. +* +*/ int start() { @@ -412,6 +414,12 @@ start() } +/** + * Start the driver on a specific bus. + * + * This function call only returns once the driver is up and running + * or failed to detect the sensor. + */ int start_bus(int i2c_bus) { diff --git a/src/drivers/differential_pressure/ms5525/MS5525_main.cpp b/src/drivers/differential_pressure/ms5525/MS5525_main.cpp index 5f17707791..58b54f3c1c 100644 --- a/src/drivers/differential_pressure/ms5525/MS5525_main.cpp +++ b/src/drivers/differential_pressure/ms5525/MS5525_main.cpp @@ -43,15 +43,53 @@ namespace ms5525_airspeed { MS5525 *g_dev = nullptr; -int start(uint8_t i2c_bus); +int bus_options[] = { +#ifdef PX4_I2C_BUS_EXPANSION + PX4_I2C_BUS_EXPANSION, +#endif +#ifdef PX4_I2C_BUS_EXPANSION1 + PX4_I2C_BUS_EXPANSION1, +#endif +#ifdef PX4_I2C_BUS_EXPANSION2 + PX4_I2C_BUS_EXPANSION2, +#endif +}; + +#define NUM_BUS_OPTIONS (sizeof(bus_options)/sizeof(bus_options[0])) + +int start(); +int start_bus(uint8_t i2c_bus); int stop(); int reset(); -// Start the driver. -// This function call only returns once the driver is up and running -// or failed to detect the sensor. +/** +* Attempt to start driver on all available I2C busses. +* +* This function will return as soon as the first sensor +* is detected on one of the available busses or if no +* sensors are detected. +* +*/ int -start(uint8_t i2c_bus) +start() +{ + for (unsigned i = 0; i < NUM_BUS_OPTIONS; i++) { + if (start_bus(bus_options[i]) == PX4_OK) { + return PX4_OK; + } + } + + return PX4_ERROR; +} + +/** + * Start the driver on a specific bus. + * + * This function call only returns once the driver is up and running + * or failed to detect the sensor. + */ +int +start_bus(uint8_t i2c_bus) { int fd = -1; @@ -144,6 +182,7 @@ ms5525_airspeed_usage() PX4_WARN("usage: ms5525_airspeed command [options]"); PX4_WARN("options:"); PX4_WARN("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT); + PX4_INFO("\t-a --all"); PX4_WARN("command:"); PX4_WARN("\tstart|stop|reset"); } @@ -156,13 +195,18 @@ ms5525_airspeed_main(int argc, char *argv[]) int myoptind = 1; int ch; const char *myoptarg = nullptr; + bool start_all = false; - while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) { + while ((ch = px4_getopt(argc, argv, "ab:", &myoptind, &myoptarg)) != EOF) { switch (ch) { case 'b': i2c_bus = atoi(myoptarg); break; + case 'a': + start_all = true; + break; + default: ms5525_airspeed_usage(); return 0; @@ -178,7 +222,12 @@ ms5525_airspeed_main(int argc, char *argv[]) * Start/load the driver. */ if (!strcmp(argv[myoptind], "start")) { - return ms5525_airspeed::start(i2c_bus); + if (start_all) { + return ms5525_airspeed::start(); + + } else { + return ms5525_airspeed::start_bus(i2c_bus); + } } /*