sensor: update drivers to not return double values

Update drivers to return INT_PLUS_MICRO values instead of doubles.

This hides the fact that the drivers use floating point operations and
doesn't force the application to use them as well.

Change-Id: I14c6faecb35331c2fdbdab41bc624d751de984b8
Signed-off-by: Bogdan Davidoaia <bogdan.m.davidoaia@intel.com>
This commit is contained in:
Bogdan Davidoaia 2016-12-09 12:57:20 +02:00 committed by Anas Nashif
commit de4727ba3f
5 changed files with 43 additions and 17 deletions

View file

@ -44,7 +44,7 @@ static int gls_channel_get(struct device *dev,
{
struct gls_data *drv_data = dev->driver_data;
uint16_t analog_val;
double ldr_val;
double ldr_val, dval;
/* rescale sample from 12bit (Zephyr) to 10bit (Grove) */
analog_val = ((uint16_t)drv_data->adc_buffer[1] << 8) |
@ -57,8 +57,11 @@ static int gls_channel_get(struct device *dev,
* https://github.com/intel-iot-devkit/upm/blob/master/src/grove/grove.cxx#L161
*/
ldr_val = (1023.0 - analog_val) * 10.0 / analog_val;
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = 10000.0 / pow(ldr_val * 15.0, 4.0/3.0);
dval = 10000.0 / pow(ldr_val * 15.0, 4.0/3.0);
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
return 0;
}

View file

@ -51,6 +51,7 @@ static int gts_channel_get(struct device *dev,
{
struct gts_data *drv_data = dev->driver_data;
uint16_t analog_val;
double dval;
/* rescale sample from 12bit (Zephyr) to 10bit (Grove) */
analog_val = ((uint16_t)drv_data->adc_buffer[1] << 8) |
@ -62,9 +63,12 @@ static int gts_channel_get(struct device *dev,
* is taken from the sensor reference page:
* http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor
*/
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = 1 / (log(1023.0 / analog_val - 1.0) / B_CONST +
1 / 298.15) - 273.15;
dval = 1 / (log(1023.0 / analog_val - 1.0) / B_CONST +
1 / 298.15) - 273.15;
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
return 0;
}

View file

@ -248,8 +248,12 @@ static int lsm6ds0_sample_fetch(struct device *dev, enum sensor_channel chan)
static inline void lsm6ds0_accel_convert(struct sensor_value *val, int raw_val,
float scale)
{
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = (double)(raw_val) * scale / 32767.0;
double dval;
dval = (double)(raw_val) * scale / 32767.0;
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
}
static inline int lsm6ds0_accel_get_channel(enum sensor_channel chan,
@ -302,9 +306,12 @@ static int lsm6ds0_accel_channel_get(enum sensor_channel chan,
static inline void lsm6ds0_gyro_convert(struct sensor_value *val, int raw_val,
float numerator)
{
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = (double)(raw_val) * numerator / 1000.0 *
SENSOR_DEG2RAD_DOUBLE;
double dval;
dval = (double)(raw_val) * numerator / 1000.0 * SENSOR_DEG2RAD_DOUBLE;
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
}
static inline int lsm6ds0_gyro_get_channel(enum sensor_channel chan,

View file

@ -162,8 +162,12 @@ static int lsm9ds0_gyro_sample_fetch(struct device *dev,
static inline void lsm9ds0_gyro_convert(struct sensor_value *val, int raw_val,
float numerator)
{
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = (double)(raw_val) * numerator / 1000.0 * DEG2RAD;
double dval;
dval = (double)(raw_val) * numerator / 1000.0 * DEG2RAD;
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
}
static inline int lsm9ds0_gyro_get_channel(enum sensor_channel chan,

View file

@ -398,8 +398,12 @@ static inline void lsm9ds0_mfd_convert_accel(struct sensor_value *val,
int raw_val,
float scale)
{
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = (double)(raw_val) * scale;
double dval;
dval = (double)(raw_val) * scale;
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
}
static inline int lsm9ds0_mfd_get_accel_channel(enum sensor_channel chan,
@ -481,8 +485,12 @@ static inline void lsm9ds0_mfd_convert_magn(struct sensor_value *val,
int raw_val,
float scale)
{
val->type = SENSOR_VALUE_TYPE_DOUBLE;
val->dval = (double)(raw_val) * scale;
double dval;
dval = (double)(raw_val) * scale;
val->type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val->val1 = (int32_t)dval;
val->val2 = ((int32_t)(dval * 1000000)) % 1000000;
}
static inline int lsm9ds0_mfd_get_magn_channel(enum sensor_channel chan,