i2c drivers: add '-k' flag for keep_running directly to BusCLIArguments

This commit is contained in:
Beat Küng
2020-09-18 09:45:06 -04:00
committed by Daniel Agar
parent 1bf030e8ba
commit 5fdff6a0e4
10 changed files with 48 additions and 39 deletions
@@ -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;
}
}