accel: Actually apply the mount-matrix

We did set up ourselves to do this, but never went to the point
where we applied the mount-matrix.

Spotted by Carlos Garnacho.
This commit is contained in:
Bastien Nocera
2016-12-03 13:03:25 +01:00
parent 93b80fb624
commit daf40b6d25
3 changed files with 34 additions and 9 deletions

View File

@@ -38,6 +38,7 @@ process_scan (IIOSensorData data, DrvData *or_data)
gdouble scale;
gboolean present_x, present_y, present_z;
AccelReadings readings;
AccelVec3 tmp;
if (data.read_size < 0) {
g_warning ("Couldn't read from device '%s': %s", or_data->name, g_strerror (errno));
@@ -60,10 +61,17 @@ process_scan (IIOSensorData data, DrvData *or_data)
g_debug ("Accel read from IIO on '%s': %d, %d, %d (scale %lf)", or_data->name, accel_x, accel_y, accel_z, scale);
tmp.x = accel_x;
tmp.y = accel_y;
tmp.z = accel_z;
if (!apply_mount_matrix (or_data->mount_matrix, &tmp))
g_warning ("Could not apply mount matrix");
//FIXME report errors
readings.accel_x = accel_x;
readings.accel_y = accel_y;
readings.accel_z = accel_z;
readings.accel_x = tmp.x;
readings.accel_y = tmp.y;
readings.accel_z = tmp.z;
readings.scale = scale;
or_data->callback_func (&iio_buffer_accel, (gpointer) &readings, or_data->user_data);

View File

@@ -54,6 +54,7 @@ poll_orientation (gpointer user_data)
DrvData *data = user_data;
int accel_x, accel_y, accel_z;
AccelReadings readings;
AccelVec3 tmp;
accel_x = sysfs_get_int (data->dev, "in_accel_x_raw");
accel_y = sysfs_get_int (data->dev, "in_accel_y_raw");
@@ -63,10 +64,17 @@ poll_orientation (gpointer user_data)
g_debug ("Accel read from IIO on '%s': %d, %d, %d (scale %lf)", data->name,
accel_x, accel_y, accel_z, readings.scale);
tmp.x = accel_x;
tmp.y = accel_y;
tmp.z = accel_z;
if (!apply_mount_matrix (drv_data->mount_matrix, &tmp))
g_warning ("Could not apply mount matrix");
//FIXME report errors
readings.accel_x = accel_x;
readings.accel_y = accel_y;
readings.accel_z = accel_z;
readings.accel_x = tmp.x;
readings.accel_y = tmp.y;
readings.accel_z = tmp.z;
drv_data->callback_func (&iio_poll_accel, (gpointer) &readings, drv_data->user_data);

View File

@@ -62,6 +62,7 @@ accelerometer_changed (void)
int accel_x = 0, accel_y = 0, accel_z = 0;
int fd, r;
AccelReadings readings;
AccelVec3 tmp;
fd = open (drv_data->dev_path, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
@@ -76,14 +77,22 @@ accelerometer_changed (void)
close (fd);
readings.accel_x = accel_x;
readings.accel_y = accel_y;
readings.accel_z = accel_z;
/* Scale from 1G ~= 256 to a value in m/s² */
readings.scale = 1.0 / 256 * 9.81;
g_debug ("Accel read from input on '%s': %d, %d, %d (scale %lf)", drv_data->name, accel_x, accel_y, accel_z, readings.scale);
tmp.x = accel_x;
tmp.y = accel_y;
tmp.z = accel_z;
if (!apply_mount_matrix (drv_data->mount_matrix, &tmp))
g_warning ("Could not apply mount matrix");
readings.accel_x = tmp.x;
readings.accel_y = tmp.y;
readings.accel_z = tmp.z;
drv_data->callback_func (&input_accel, (gpointer) &readings, drv_data->user_data);
}