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:
Eug Krashtan 2021-04-29 17:43:43 +03:00 committed by Kumar Gala
commit 3c36cd4242

View file

@ -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;
}
/**
* @}
*/