mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-18 19:59:13 +08:00
[components][drivers] added sensor device lookup function
This commit is contained in:
parent
a92f971267
commit
4c9d3be98a
@ -398,6 +398,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
|
|||||||
const char *name,
|
const char *name,
|
||||||
rt_uint32_t flag,
|
rt_uint32_t flag,
|
||||||
void *data);
|
void *data);
|
||||||
|
rt_sensor_t rt_sensor_device_find(const char *name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@ static char *const sensor_name_str[] =
|
|||||||
"sp-", /* SpO2 sensor */
|
"sp-", /* SpO2 sensor */
|
||||||
"ia-", /* IAQ sensor */
|
"ia-", /* IAQ sensor */
|
||||||
"et-", /* EtOH sensor */
|
"et-", /* EtOH sensor */
|
||||||
"bp-" /* Blood Pressure */
|
"bp-", /* Blood Pressure */
|
||||||
|
RT_NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* sensor interrupt handler function */
|
/* sensor interrupt handler function */
|
||||||
@ -519,3 +520,23 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
|
|||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rt_sensor_t rt_sensor_device_find(const char *name)
|
||||||
|
{
|
||||||
|
rt_uint8_t index;
|
||||||
|
char device_name[RT_NAME_MAX];
|
||||||
|
rt_device_t device;
|
||||||
|
|
||||||
|
for (index = 0; sensor_name_str[index] != RT_NULL; index++)
|
||||||
|
{
|
||||||
|
rt_memset(device_name, 0, sizeof(device_name));
|
||||||
|
rt_snprintf(device_name, sizeof(device_name), "%s%s", sensor_name_str[index], name);
|
||||||
|
device = rt_device_find(device_name);
|
||||||
|
if (device != RT_NULL)
|
||||||
|
{
|
||||||
|
return (rt_sensor_t)device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RT_NULL;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user