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

This commit is contained in:
Beat Küng
2020-09-18 10:18:40 +02:00
committed by Daniel Agar
parent 1bf030e8ba
commit 5fdff6a0e4
10 changed files with 48 additions and 39 deletions
+12
View File
@@ -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(). */
/**
+5
View File
@@ -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)
{