sensor: additional conversion functions
Add additional conversion helpers for `deci` and `centi` output units. Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
parent
2f6ac20654
commit
9286b0b9d0
2 changed files with 27 additions and 0 deletions
|
@ -163,6 +163,11 @@ New APIs and options
|
||||||
|
|
||||||
* :kconfig:option:`CONFIG_NET_SOCKETS_INET_RAW`
|
* :kconfig:option:`CONFIG_NET_SOCKETS_INET_RAW`
|
||||||
|
|
||||||
|
* Sensor
|
||||||
|
|
||||||
|
* :c:func:`sensor_value_to_deci`
|
||||||
|
* :c:func:`sensor_value_to_centi`
|
||||||
|
|
||||||
* Stepper
|
* Stepper
|
||||||
|
|
||||||
* :c:func:`stepper_stop()`
|
* :c:func:`stepper_stop()`
|
||||||
|
|
|
@ -1468,6 +1468,28 @@ struct sensor_info {
|
||||||
#define SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) \
|
#define SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) \
|
||||||
SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
|
SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper function for converting struct sensor_value to integer deci units.
|
||||||
|
*
|
||||||
|
* @param val A pointer to a sensor_value struct.
|
||||||
|
* @return The converted value.
|
||||||
|
*/
|
||||||
|
static inline int64_t sensor_value_to_deci(const struct sensor_value *val)
|
||||||
|
{
|
||||||
|
return ((int64_t)val->val1 * 10) + val->val2 / 100000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper function for converting struct sensor_value to integer centi units.
|
||||||
|
*
|
||||||
|
* @param val A pointer to a sensor_value struct.
|
||||||
|
* @return The converted value.
|
||||||
|
*/
|
||||||
|
static inline int64_t sensor_value_to_centi(const struct sensor_value *val)
|
||||||
|
{
|
||||||
|
return ((int64_t)val->val1 * 100) + val->val2 / 10000;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper function for converting struct sensor_value to integer milli units.
|
* @brief Helper function for converting struct sensor_value to integer milli units.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue