lps33hw: refactor and add -k flag to keep running even if no sensor found

This commit is contained in:
Beat Küng
2020-09-18 09:45:06 -04:00
committed by Daniel Agar
parent 24adf36097
commit 1bf030e8ba
3 changed files with 121 additions and 77 deletions
+12 -2
View File
@@ -52,6 +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_DEFAULT_COMMANDS();
}
@@ -78,7 +79,7 @@ I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInst
return nullptr;
}
LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface);
LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface, cli.custom1 == 1);
if (dev == nullptr) {
delete interface;
@@ -95,13 +96,22 @@ 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;
const char *verb = cli.parseDefaultArguments(argc, argv);
while ((ch = cli.getopt(argc, argv, "k")) != EOF) {
switch (ch) {
case 'k': // keep retrying
cli.custom1 = 1;
break;
}
}
const char *verb = cli.optarg();
if (!verb) {
ThisDriver::print_usage();