mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 18:37:27 +08:00
ms4525_airspeed: add -a flag to scan all i2c busses during start
This commit is contained in:
committed by
Lorenz Meier
parent
e1bca8d01a
commit
9b2e32c976
@@ -81,6 +81,8 @@
|
|||||||
#define MEAS_DRIVER_FILTER_FREQ 1.2f
|
#define MEAS_DRIVER_FILTER_FREQ 1.2f
|
||||||
#define CONVERSION_INTERVAL (1000000 / MEAS_RATE) /* microseconds */
|
#define CONVERSION_INTERVAL (1000000 / MEAS_RATE) /* microseconds */
|
||||||
|
|
||||||
|
#define PX4_I2C_ALL 0xFF
|
||||||
|
|
||||||
class MEASAirspeed : public Airspeed
|
class MEASAirspeed : public Airspeed
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -373,7 +375,22 @@ namespace meas_airspeed
|
|||||||
|
|
||||||
MEASAirspeed *g_dev = nullptr;
|
MEASAirspeed *g_dev = nullptr;
|
||||||
|
|
||||||
|
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 i2c_bus);
|
int start(int i2c_bus);
|
||||||
|
bool start_bus(int i2c_bus);
|
||||||
int stop();
|
int stop();
|
||||||
int reset();
|
int reset();
|
||||||
|
|
||||||
@@ -385,6 +402,23 @@ int reset();
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
start(int i2c_bus)
|
start(int i2c_bus)
|
||||||
|
{
|
||||||
|
if (i2c_bus == PX4_I2C_ALL) {
|
||||||
|
for (unsigned i = 0; i < NUM_BUS_OPTIONS; i++) {
|
||||||
|
if (start_bus(bus_options[i]) == PX4_OK) {
|
||||||
|
return PX4_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PX4_ERROR;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return start_bus(i2c_bus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
start_bus(int i2c_bus)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@@ -483,6 +517,7 @@ meas_airspeed_usage()
|
|||||||
PX4_INFO("usage: meas_airspeed command [options]");
|
PX4_INFO("usage: meas_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");
|
PX4_INFO("\tstart|stop|reset");
|
||||||
}
|
}
|
||||||
@@ -496,12 +531,16 @@ ms4525_airspeed_main(int argc, char *argv[])
|
|||||||
int ch;
|
int ch;
|
||||||
const char *myoptarg = nullptr;
|
const char *myoptarg = nullptr;
|
||||||
|
|
||||||
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':
|
||||||
|
i2c_bus = PX4_I2C_ALL;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
meas_airspeed_usage();
|
meas_airspeed_usage();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user