drivers: sensor: shell: Check sensor API type
Update sensor shell commands to filter and verify the device's API type. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
parent
a553af738d
commit
e16dece057
1 changed files with 14 additions and 9 deletions
|
@ -169,6 +169,11 @@ static int find_sensor_trigger_device(const struct device *sensor)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static bool sensor_device_check(const struct device *dev)
|
||||
{
|
||||
return DEVICE_API_IS(sensor, dev);
|
||||
}
|
||||
|
||||
/* Forward declaration */
|
||||
static void data_ready_trigger_handler(const struct device *sensor,
|
||||
const struct sensor_trigger *trigger);
|
||||
|
@ -544,8 +549,8 @@ static int cmd_get_sensor(const struct shell *sh, size_t argc, char *argv[])
|
|||
}
|
||||
|
||||
dev = device_get_binding(argv[1]);
|
||||
if (dev == NULL) {
|
||||
shell_error(sh, "Device unknown (%s)", argv[1]);
|
||||
if (dev == NULL || !sensor_device_check(dev)) {
|
||||
shell_error(sh, "Sensor device unknown (%s)", argv[1]);
|
||||
k_mutex_unlock(&cmd_get_mutex);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
@ -613,8 +618,8 @@ static int cmd_sensor_attr_set(const struct shell *shell_ptr, size_t argc, char
|
|||
int rc;
|
||||
|
||||
dev = device_get_binding(argv[1]);
|
||||
if (dev == NULL) {
|
||||
shell_error(shell_ptr, "Device unknown (%s)", argv[1]);
|
||||
if (dev == NULL || !sensor_device_check(dev)) {
|
||||
shell_error(shell_ptr, "Sensor device unknown (%s)", argv[1]);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
@ -697,8 +702,8 @@ static int cmd_sensor_attr_get(const struct shell *shell_ptr, size_t argc, char
|
|||
const struct device *dev;
|
||||
|
||||
dev = device_get_binding(argv[1]);
|
||||
if (dev == NULL) {
|
||||
shell_error(shell_ptr, "Device unknown (%s)", argv[1]);
|
||||
if (dev == NULL || !sensor_device_check(dev)) {
|
||||
shell_error(shell_ptr, "Sensor device unknown (%s)", argv[1]);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
@ -848,7 +853,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_device_name, device_name_get);
|
|||
|
||||
static void device_name_get(size_t idx, struct shell_static_entry *entry)
|
||||
{
|
||||
const struct device *dev = shell_device_lookup(idx, NULL);
|
||||
const struct device *dev = shell_device_filter(idx, sensor_device_check);
|
||||
|
||||
current_cmd_ctx = CTX_GET;
|
||||
entry->syntax = (dev != NULL) ? dev->name : NULL;
|
||||
|
@ -1047,8 +1052,8 @@ static int cmd_trig_sensor(const struct shell *sh, size_t argc, char **argv)
|
|||
|
||||
/* Parse device name */
|
||||
dev = device_get_binding(argv[1]);
|
||||
if (dev == NULL) {
|
||||
shell_error(sh, "Device unknown (%s)", argv[1]);
|
||||
if (dev == NULL || !sensor_device_check(dev)) {
|
||||
shell_error(sh, "Sensor device unknown (%s)", argv[1]);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue