diff --git a/src/Makefile.am b/src/Makefile.am index 3277da5..0080eec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,8 +28,8 @@ iio_sensor_proxy_SOURCES = \ iio-buffer-utils.c \ accel-mount-matrix.h \ accel-mount-matrix.c \ - accel-location.h \ - accel-location.c \ + accel-attributes.h \ + accel-attributes.c \ $(BUILT_SOURCES) iio_sensor_proxy_CPPFLAGS = \ @@ -63,8 +63,8 @@ test_mount_matrix_LDADD = $(IIO_SENSOR_PROXY_LIBS) test_accel_location_SOURCES = \ test-accel-location.c \ - accel-location.h \ - accel-location.c + accel-attributes.h \ + accel-attributes.c test_accel_location_CPPFLAGS = \ $(IIO_SENSOR_PROXY_CFLAGS) \ diff --git a/src/accel-location.c b/src/accel-attributes.c similarity index 70% rename from src/accel-location.c rename to src/accel-attributes.c index f6cd196..8b23878 100644 --- a/src/accel-location.c +++ b/src/accel-attributes.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2019 Luís Ferreira + * Copyright (c) 2019 Daniel Stuart * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3 as published by @@ -7,7 +8,7 @@ * */ -#include "accel-location.h" +#include "accel-attributes.h" AccelLocation setup_accel_location (GUdevDevice *device) @@ -55,3 +56,23 @@ parse_accel_location (const char *location, AccelLocation *value) return FALSE; } } + +gdouble +get_accel_scale (GUdevDevice *device) +{ + gdouble scale; + + scale = g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale"); + if (scale != 0.0) { + g_debug ("Attribute in_accel_scale ('%f') found on sysfs", scale); + return scale; + } + scale = g_udev_device_get_sysfs_attr_as_double (device, "scale"); + if (scale != 0.0) { + g_debug ("Attribute scale ('%f') found on sysfs", scale); + return scale; + } + + g_debug ("Failed to auto-detect scale, falling back to 1.0"); + return 1.0; +} diff --git a/src/accel-location.h b/src/accel-attributes.h similarity index 75% rename from src/accel-location.h rename to src/accel-attributes.h index 3edf8e3..c92b026 100644 --- a/src/accel-location.h +++ b/src/accel-attributes.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2019 Luís Ferreira + * Copyright (c) 2019 Daniel Stuart * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3 as published by @@ -18,4 +19,6 @@ typedef enum { AccelLocation setup_accel_location (GUdevDevice *device); gboolean parse_accel_location (const char *location, - AccelLocation *value); \ No newline at end of file + AccelLocation *value); + +gdouble get_accel_scale (GUdevDevice *device); \ No newline at end of file diff --git a/src/drivers.h b/src/drivers.h index f2cb5e2..6e9eaa9 100644 --- a/src/drivers.h +++ b/src/drivers.h @@ -9,7 +9,7 @@ #include #include -#include "accel-location.h" +#include "accel-attributes.h" typedef enum { DRIVER_TYPE_ACCEL, diff --git a/src/drv-iio-poll-accel.c b/src/drv-iio-poll-accel.c index 9b85c7d..280f69e 100644 --- a/src/drv-iio-poll-accel.c +++ b/src/drv-iio-poll-accel.c @@ -25,8 +25,7 @@ typedef struct DrvData { const char *name; AccelVec3 *mount_matrix; AccelLocation location; - - double scale; + gdouble scale; } DrvData; static DrvData *drv_data = NULL; @@ -128,9 +127,7 @@ iio_poll_accel_open (GUdevDevice *device, drv_data->location = setup_accel_location (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"); - if (drv_data->scale == 0.0) - drv_data->scale = 1.0; + drv_data->scale = get_accel_scale (device); return TRUE; } diff --git a/src/test-accel-location.c b/src/test-accel-location.c index 681d91f..82b0a0a 100644 --- a/src/test-accel-location.c +++ b/src/test-accel-location.c @@ -7,7 +7,7 @@ * */ -#include "accel-location.h" +#include "accel-attributes.h" #define VALID_DISPLAY_LOCATION "display" #define VALID_BASE_LOCATION "base"