pmaports/temp/iio-sensor-proxy/292.patch
David Heidelberg 05439148e4
temp/iio-sensor-proxy: include patches for RAW devices (!888)
* First patch for getting data from RAW sensors. (Purism)
* Second patch is for mount-matrix passing. (digetx)

Useful for most Tegra devices, including AL3010 sensor.

First patch merged, second patch queued for a merge.

Ref: https://github.com/hadess/iio-sensor-proxy/pull/292
Ref: https://github.com/hadess/iio-sensor-proxy/pull/299

Signed-off-by: David Heidelberg <david@ixit.cz>
2020-01-19 19:17:40 +03:00

65 lines
2.8 KiB
Diff

From eba0aca224c18624b7e398171fb8688728baf398 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Sat, 21 Dec 2019 14:31:51 +0100
Subject: [PATCH] light: Support sensors using raw values as well
E.g. the vcnl4000 class devices reports a raw value and a scale
to calculate lux.
---
data/80-iio-sensor-proxy.rules | 1 +
src/drv-iio-poll-light.c | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/data/80-iio-sensor-proxy.rules b/data/80-iio-sensor-proxy.rules
index 06040dc..5bcb207 100644
--- a/data/80-iio-sensor-proxy.rules
+++ b/data/80-iio-sensor-proxy.rules
@@ -9,6 +9,7 @@ SUBSYSTEM=="iio", TEST=="in_accel_x_raw", TEST=="in_accel_y_raw", TEST=="in_acce
SUBSYSTEM=="iio", TEST=="scan_elements/in_accel_x_en", TEST=="scan_elements/in_accel_y_en", TEST=="scan_elements/in_accel_z_en", ENV{IIO_SENSOR_PROXY_TYPE}="iio-buffer-accel"
SUBSYSTEM=="iio", TEST=="scan_elements/in_rot_from_north_magnetic_tilt_comp_en", ENV{IIO_SENSOR_PROXY_TYPE}="iio-buffer-compass"
SUBSYSTEM=="iio", TEST=="in_illuminance_input", ENV{IIO_SENSOR_PROXY_TYPE}="iio-poll-als"
+SUBSYSTEM=="iio", TEST=="in_illuminance_raw", ENV{IIO_SENSOR_PROXY_TYPE}="iio-poll-als"
SUBSYSTEM=="iio", TEST=="scan_elements/in_intensity_both_en", ENV{IIO_SENSOR_PROXY_TYPE}="iio-buffer-als"
SUBSYSTEM=="input", ENV{ID_INPUT_ACCELEROMETER}=="1", ENV{IIO_SENSOR_PROXY_TYPE}="input-accel"
diff --git a/src/drv-iio-poll-light.c b/src/drv-iio-poll-light.c
index d0da7df..a7423c6 100644
--- a/src/drv-iio-poll-light.c
+++ b/src/drv-iio-poll-light.c
@@ -24,6 +24,8 @@ typedef struct DrvData {
char *input_path;
guint interval;
guint timeout_id;
+
+ double scale;
} DrvData;
static DrvData *drv_data = NULL;
@@ -55,8 +57,8 @@ light_changed (gpointer user_data)
g_error_free (error);
return G_SOURCE_CONTINUE;
}
-
- readings.level = level;
+ readings.level = level * drv_data->scale;
+ g_debug ("Light read from IIO: %lf, (scale %lf)", level, drv_data->scale);
/* Even though the IIO kernel API declares in_intensity* values as unitless,
* we use Microsoft's hid-sensors-usages.docx which mentions that Windows 8
@@ -125,6 +127,16 @@ iio_poll_light_open (GUdevDevice *device,
drv_data->input_path = g_build_filename (g_udev_device_get_sysfs_path (device),
"in_illuminance_input",
NULL);
+ if (!g_file_test (drv_data->input_path, G_FILE_TEST_EXISTS)) {
+ g_free (drv_data->input_path);
+ drv_data->input_path = g_build_filename (g_udev_device_get_sysfs_path (device),
+ "in_illuminance_raw",
+ NULL);
+ }
+
+ drv_data->scale = g_udev_device_get_sysfs_attr_as_double (device, "in_illuminance_scale");
+ if (drv_data->scale == 0.0)
+ drv_data->scale = 1.0;
return TRUE;
}