shell: refactor device_name_get implementation
Several shell modules use cloned code to iterate over all devices and identify the nth instance that meets some criteria. The code was repetitive and included various errors. Abstract to a helper function that performs the check consistently. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
219a3ca96d
commit
a538dcd8f8
5 changed files with 51 additions and 43 deletions
|
@ -104,6 +104,24 @@ struct shell_static_args {
|
|||
uint8_t optional; /*!< Number of optional arguments. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get by index a device that matches .
|
||||
*
|
||||
* This can be used, for example, to identify I2C_1 as the second I2C
|
||||
* device.
|
||||
*
|
||||
* Devices that failed to initialize or do not have a non-empty name
|
||||
* are excluded from the candidates for a match.
|
||||
*
|
||||
* @param idx the device number starting from zero.
|
||||
*
|
||||
* @param prefix optional name prefix used to restrict candidate
|
||||
* devices. Indexing is done relative to devices with names that
|
||||
* start with this text. Pass null if no prefix match is required.
|
||||
*/
|
||||
struct device *shell_device_lookup(size_t idx,
|
||||
const char *prefix);
|
||||
|
||||
/**
|
||||
* @brief Shell command handler prototype.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue