sys/saul_reg: add saul_reg_find_type_and_name

This commit is contained in:
Bas Stottelaar 2021-01-18 22:25:19 +01:00
parent 672a9affc7
commit 9bc7dd04e6
2 changed files with 28 additions and 4 deletions

View File

@ -90,7 +90,7 @@ int saul_reg_add(saul_reg_t *dev);
int saul_reg_rm(saul_reg_t *dev); int saul_reg_rm(saul_reg_t *dev);
/** /**
* @brief Find a device by it's position in the registry * @brief Find a device by its position in the registry
* *
* @param[in] pos position to look up * @param[in] pos position to look up
* *
@ -100,9 +100,9 @@ int saul_reg_rm(saul_reg_t *dev);
saul_reg_t *saul_reg_find_nth(int pos); saul_reg_t *saul_reg_find_nth(int pos);
/** /**
* @brief Find the first device of the given type in the registry * @brief Find the first device by its type in the registry
* *
* @param[in] type device type to look for * @param[in] type the device type to look for
* *
* @return pointer to the first device matching the given type * @return pointer to the first device matching the given type
* @return NULL if no device of that type could be found * @return NULL if no device of that type could be found
@ -110,7 +110,7 @@ saul_reg_t *saul_reg_find_nth(int pos);
saul_reg_t *saul_reg_find_type(uint8_t type); saul_reg_t *saul_reg_find_type(uint8_t type);
/** /**
* @brief Find a device by its name * @brief Find the first device by its name in the registry
* *
* @param[in] name the name to look for * @param[in] name the name to look for
* *
@ -119,6 +119,17 @@ saul_reg_t *saul_reg_find_type(uint8_t type);
*/ */
saul_reg_t *saul_reg_find_name(const char *name); saul_reg_t *saul_reg_find_name(const char *name);
/**
* @brief Find the first device by its type and name in the registry
*
* @param[in] type the device type to look for
* @param[in] name the name to look for
*
* @return pointer to the first device matching the given type and name
* @return NULL if no device with that type and name could be found
*/
saul_reg_t *saul_reg_find_type_and_name(uint8_t type, const char *name);
/** /**
* @brief Read data from the given device * @brief Read data from the given device
* *

View File

@ -113,6 +113,19 @@ saul_reg_t *saul_reg_find_name(const char *name)
return NULL; return NULL;
} }
saul_reg_t *saul_reg_find_type_and_name(uint8_t type, const char *name)
{
saul_reg_t *tmp = saul_reg;
while (tmp) {
if (tmp->driver->type == type && strcmp(tmp->name, name) == 0) {
return tmp;
}
tmp = tmp->next;
}
return NULL;
}
int saul_reg_read(saul_reg_t *dev, phydat_t *res) int saul_reg_read(saul_reg_t *dev, phydat_t *res)
{ {
if (dev == NULL) { if (dev == NULL) {