forked from Archive/PX4-Autopilot
ets_airspeed: add -a flag to scan all i2c busses during start
This commit is contained in:
parent
649d4be185
commit
9d878c719d
|
@ -239,19 +239,55 @@ namespace ets_airspeed
|
||||||
|
|
||||||
ETSAirspeed *g_dev;
|
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 stop();
|
||||||
int reset();
|
int reset();
|
||||||
int info();
|
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
|
* This function only returns if the sensor is up and running
|
||||||
* or could not be detected successfully.
|
* or could not be detected successfully.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
start(int i2c_bus)
|
start_bus(int i2c_bus)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
@ -349,6 +385,7 @@ ets_airspeed_usage()
|
||||||
PX4_INFO("usage: ets_airspeed command [options]");
|
PX4_INFO("usage: ets_airspeed command [options]");
|
||||||
PX4_INFO("options:");
|
PX4_INFO("options:");
|
||||||
PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT);
|
PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT);
|
||||||
|
PX4_INFO("\t-a --all");
|
||||||
PX4_INFO("command:");
|
PX4_INFO("command:");
|
||||||
PX4_INFO("\tstart|stop|reset|info");
|
PX4_INFO("\tstart|stop|reset|info");
|
||||||
}
|
}
|
||||||
|
@ -361,13 +398,18 @@ ets_airspeed_main(int argc, char *argv[])
|
||||||
int myoptind = 1;
|
int myoptind = 1;
|
||||||
int ch;
|
int ch;
|
||||||
const char *myoptarg = nullptr;
|
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) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
i2c_bus = atoi(myoptarg);
|
i2c_bus = atoi(myoptarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
start_all = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ets_airspeed_usage();
|
ets_airspeed_usage();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -383,7 +425,12 @@ ets_airspeed_main(int argc, char *argv[])
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[myoptind], "start")) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue