forked from Archive/PX4-Autopilot
i2c drivers: add '-k' flag for keep_running directly to BusCLIArguments
This commit is contained in:
parent
1bf030e8ba
commit
5fdff6a0e4
|
@ -151,6 +151,12 @@ class ModuleDocumentation(object):
|
|||
self._handle_usage_param_int(['\'a\'', args[0], '0', '0xff', "\"I2C address\"", 'true'])
|
||||
self._paring_implicit_options = False
|
||||
|
||||
def _handle_usage_params_i2c_keep_running_flag(self, args):
|
||||
assert(len(args) == 0)
|
||||
self._paring_implicit_options = True
|
||||
self._handle_usage_param_flag(['\'k\'', "\"if initialization (probing) fails, keep retrying periodically\"", 'true'])
|
||||
self._paring_implicit_options = False
|
||||
|
||||
def _handle_usage_param_flag(self, args):
|
||||
assert(len(args) == 3) # option_char, description, is_optional
|
||||
option_char = self._get_option_char(args[0])
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
board_adc start
|
||||
|
||||
# Start Digital power monitors
|
||||
voxlpm -X -b 3 -K -T VBATT start
|
||||
voxlpm -X -b 3 -k -T VBATT start
|
||||
voxlpm -X -b 3 -T P5VDC start
|
||||
|
||||
# Internal SPI bus ICM-20602
|
||||
|
|
|
@ -84,6 +84,10 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options)
|
|||
*(p++) = 'm'; *(p++) = ':'; // spi mode
|
||||
}
|
||||
|
||||
if (support_keep_running) {
|
||||
*(p++) = 'k';
|
||||
}
|
||||
|
||||
*(p++) = 'b'; *(p++) = ':'; // bus
|
||||
*(p++) = 'f'; *(p++) = ':'; // frequency
|
||||
*(p++) = 'q'; // quiet flag
|
||||
|
@ -163,6 +167,14 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options)
|
|||
quiet_start = true;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
if (!support_keep_running) {
|
||||
return ch;
|
||||
}
|
||||
|
||||
keep_running = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ch == '?') {
|
||||
// abort further parsing on unknown arguments
|
||||
|
|
|
@ -110,6 +110,7 @@ public:
|
|||
spi_mode_e spi_mode{SPIDEV_MODE3};
|
||||
uint8_t i2c_address{0}; ///< optional I2C address: a driver can set this to allow configuring the I2C address
|
||||
bool quiet_start{false}; ///< do not print a message when startup fails
|
||||
bool keep_running{false}; ///< keep driver running even if no device is detected on startup
|
||||
|
||||
uint8_t orientation{0}; ///< distance_sensor_s::ROTATION_*
|
||||
|
||||
|
@ -121,6 +122,8 @@ public:
|
|||
int default_spi_frequency{-1}; ///< default spi bus frequency (driver needs to set this) [Hz]
|
||||
int default_i2c_frequency{-1}; ///< default i2c bus frequency (driver needs to set this) [Hz]
|
||||
|
||||
bool support_keep_running{false}; ///< true if keep_running (see above) is supported
|
||||
|
||||
private:
|
||||
bool validateConfiguration();
|
||||
|
||||
|
|
|
@ -513,6 +513,11 @@ __EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(bool i2c_support, bool sp
|
|||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address);
|
||||
|
||||
/**
|
||||
* -k flag
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(void);
|
||||
|
||||
/** @note Each of the PRINT_MODULE_USAGE_PARAM_* methods apply to the previous PRINT_MODULE_USAGE_COMMAND_DESCR(). */
|
||||
|
||||
/**
|
||||
|
|
|
@ -119,6 +119,11 @@ void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address)
|
|||
PRINT_MODULE_USAGE_PARAM_INT('a', default_address, 0, 0xff, "I2C address", true);
|
||||
}
|
||||
|
||||
void PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG()
|
||||
{
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('k', "if initialization (probing) fails, keep retrying periodically", true);
|
||||
}
|
||||
|
||||
void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val, int max_val,
|
||||
const char *description, bool is_optional)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue