mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-23 14:47:44 +08:00
i2c drivers: add '-k' flag for keep_running directly to BusCLIArguments
This commit is contained in:
@@ -52,7 +52,7 @@ LPS33HW::print_usage()
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, true);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x5D);
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG();
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface, cli.custom1 == 1);
|
||||
LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface, cli.keep_running);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
@@ -96,22 +96,14 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst
|
||||
|
||||
extern "C" int lps33hw_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = LPS33HW;
|
||||
BusCLIArguments cli{true, true};
|
||||
cli.i2c_address = 0x5D;
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.default_spi_frequency = 10 * 1000 * 1000;
|
||||
cli.support_keep_running = true;
|
||||
|
||||
while ((ch = cli.getopt(argc, argv, "k")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'k': // keep retrying
|
||||
cli.custom1 = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = cli.optarg();
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
|
||||
if (!verb) {
|
||||
ThisDriver::print_usage();
|
||||
|
||||
@@ -39,7 +39,7 @@ I2CSPIDriverBase *SDP3X::instantiate(const BusCLIArguments &cli, const BusInstan
|
||||
int runtime_instance)
|
||||
{
|
||||
SDP3X *instance = new SDP3X(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address,
|
||||
cli.custom1 == 1);
|
||||
cli.keep_running);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
@@ -64,28 +64,20 @@ SDP3X::print_usage()
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x21);
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG();
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
int
|
||||
sdp3x_airspeed_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = SDP3X;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 100000;
|
||||
cli.i2c_address = I2C_ADDRESS_1_SDP3X;
|
||||
cli.support_keep_running = true;
|
||||
|
||||
while ((ch = cli.getopt(argc, argv, "k")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'k': // keep retrying
|
||||
cli.custom1 = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = cli.optarg();
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
|
||||
if (!verb) {
|
||||
ThisDriver::print_usage();
|
||||
|
||||
@@ -15,7 +15,7 @@ I2CSPIDriverBase *INA226::instantiate(const BusCLIArguments &cli, const BusInsta
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (cli.custom1 == 1) {
|
||||
if (cli.keep_running) {
|
||||
if (instance->force_init() != PX4_OK) {
|
||||
PX4_INFO("Failed to init INA226 on bus %d, but will try again periodically.", iterator.bus());
|
||||
}
|
||||
@@ -52,7 +52,7 @@ this flag set, the battery must be plugged in before starting the driver.
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x41);
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG();
|
||||
PRINT_MODULE_USAGE_PARAM_INT('t', 1, 1, 2, "battery index for calibration values (1 or 2)", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
@@ -65,14 +65,11 @@ ina226_main(int argc, char *argv[])
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.i2c_address = INA226_BASEADDR;
|
||||
cli.default_i2c_frequency = 100000;
|
||||
cli.support_keep_running = true;
|
||||
cli.custom2 = 1;
|
||||
|
||||
while ((ch = cli.getopt(argc, argv, "kt:")) != EOF) {
|
||||
while ((ch = cli.getopt(argc, argv, "t:")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'k': // keep retrying
|
||||
cli.custom1 = 1;
|
||||
break;
|
||||
|
||||
case 't': // battery index
|
||||
cli.custom2 = (int)strtol(cli.optarg(), NULL, 0);
|
||||
break;
|
||||
|
||||
@@ -47,7 +47,7 @@ I2CSPIDriverBase *VOXLPM::instantiate(const BusCLIArguments &cli, const BusInsta
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (cli.custom1 == 1) {
|
||||
if (cli.keep_running) {
|
||||
if (OK != instance->force_init()) {
|
||||
PX4_INFO("Failed to init voxlpm type: %d on bus: %d, but will try again periodically.", (VOXLPM_CH_TYPE)cli.type,
|
||||
iterator.bus());
|
||||
@@ -69,7 +69,7 @@ VOXLPM::print_usage()
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAM_STRING('T', "VBATT", "VBATT|P5VDC|P12VDC", "Type", true);
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('K', "if initialization (probing) fails, keep retrying periodically", true);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG();
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
@@ -81,8 +81,9 @@ voxlpm_main(int argc, char *argv[])
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.type = VOXLPM_CH_TYPE_VBATT;
|
||||
cli.support_keep_running = true;
|
||||
|
||||
while ((ch = cli.getopt(argc, argv, "KT:")) != EOF) {
|
||||
while ((ch = cli.getopt(argc, argv, "T:")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'T':
|
||||
if (strcmp(cli.optarg(), "VBATT") == 0) {
|
||||
@@ -100,10 +101,6 @@ voxlpm_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'K': // keep retrying
|
||||
cli.custom1 = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user