drivers: sensor: Add sensor_value_from_double
Add helper function to convert double to struct sensor_value. Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
This commit is contained in:
parent
73e3cd5f44
commit
3c36cd4242
1 changed files with 12 additions and 0 deletions
|
@ -648,6 +648,18 @@ static inline double sensor_value_to_double(struct sensor_value *val)
|
|||
return (double)val->val1 + (double)val->val2 / 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function for converting double to struct sensor_value.
|
||||
*
|
||||
* @param val A pointer to a sensor_value struct.
|
||||
* @param inp The converted value.
|
||||
*/
|
||||
static inline void sensor_value_from_double(struct sensor_value *val, double inp)
|
||||
{
|
||||
val->val1 = (int32_t) inp;
|
||||
val->val2 = (int32_t)(inp * 1000000) % 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue