main: Fix scale handling in IIO drivers
Our code expects 256 to corresponds to 1G acceleration. IIO drivers give out a value that, when multiplied by the scale, gives an acceleration in m/s². Do the math to transform the IIO sensor's value to the scale we use internally.
This commit is contained in:
@@ -14,6 +14,10 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* 1G (9.81m/s²) corresponds to "256"
|
||||
* value x scale is in m/s² */
|
||||
#define SCALE_TO_FF(scale) (scale * 256 / 9.81)
|
||||
|
||||
/**
|
||||
* iio_channel_info - information about a given channel
|
||||
* @name: channel name
|
||||
@@ -507,7 +511,7 @@ process_scan_1 (char *data,
|
||||
*ch_val = (int) val;
|
||||
*ch_present = TRUE;
|
||||
}
|
||||
*ch_val *= channels[k]->scale;
|
||||
*ch_val *= SCALE_TO_FF(channels[k]->scale);
|
||||
break;
|
||||
case 2:
|
||||
case 8:
|
||||
|
@@ -14,6 +14,10 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* 1G (9.81m/s²) corresponds to "256"
|
||||
* value x scale is in m/s² */
|
||||
#define SCALE_TO_FF(scale) (scale * 256 / 9.81)
|
||||
|
||||
typedef struct DrvData {
|
||||
guint timeout_id;
|
||||
ReadingsUpdateFunc callback_func;
|
||||
@@ -61,7 +65,7 @@ iio_poll_accel_open (GUdevDevice *device,
|
||||
|
||||
drv_data->callback_func = callback_func;
|
||||
drv_data->user_data = user_data;
|
||||
drv_data->scale = g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale");
|
||||
drv_data->scale = SCALE_TO_FF(g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale"));
|
||||
if (drv_data->scale == 0.0)
|
||||
drv_data->scale = 1.0;
|
||||
|
||||
|
Reference in New Issue
Block a user