Browse Source

ms5525_airspeed: add -a flag to scan all i2c busses during start

sbg
DanielePettenuzzo 7 years ago committed by Beat Küng
parent
commit
fd675084cc
  1. 18
      src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp
  2. 63
      src/drivers/differential_pressure/ms5525/MS5525_main.cpp

18
src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp

@ -394,11 +394,13 @@ int stop(); @@ -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() @@ -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)
{

63
src/drivers/differential_pressure/ms5525/MS5525_main.cpp

@ -43,15 +43,53 @@ namespace ms5525_airspeed @@ -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() @@ -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[]) @@ -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[]) @@ -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);
}
}
/*

Loading…
Cancel
Save