diff --git a/src/drivers/differential_pressure/ets/ets_airspeed.cpp b/src/drivers/differential_pressure/ets/ets_airspeed.cpp index 7f7cdfea1c..058731d0fe 100644 --- a/src/drivers/differential_pressure/ets/ets_airspeed.cpp +++ b/src/drivers/differential_pressure/ets/ets_airspeed.cpp @@ -239,19 +239,55 @@ namespace ets_airspeed ETSAirspeed *g_dev; -int start(int 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(int i2c_bus); int stop(); int reset(); int info(); /** - * Start the driver. + * 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() +{ + 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 only returns if the sensor is up and running * or could not be detected successfully. */ int -start(int i2c_bus) +start_bus(int i2c_bus) { int fd; @@ -349,6 +385,7 @@ ets_airspeed_usage() PX4_INFO("usage: ets_airspeed command [options]"); PX4_INFO("options:"); PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT); + PX4_INFO("\t-a --all"); PX4_INFO("command:"); PX4_INFO("\tstart|stop|reset|info"); } @@ -361,13 +398,18 @@ ets_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: ets_airspeed_usage(); return 0; @@ -383,7 +425,12 @@ ets_airspeed_main(int argc, char *argv[]) * Start/load the driver. */ if (!strcmp(argv[myoptind], "start")) { - return ets_airspeed::start(i2c_bus); + if (start_all) { + return ets_airspeed::start(); + + } else { + return ets_airspeed::start_bus(i2c_bus); + } } /*