diff --git a/src/Makefile.am b/src/Makefile.am index d9bd610..36f6eeb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,6 +28,8 @@ iio_sensor_proxy_SOURCES = \ iio-buffer-utils.c \ accel-mount-matrix.h \ accel-mount-matrix.c \ + accel-location.h \ + accel-location.c \ $(BUILT_SOURCES) iio_sensor_proxy_CPPFLAGS = \ diff --git a/src/accel-location.c b/src/accel-location.c new file mode 100644 index 0000000..e2a618c --- /dev/null +++ b/src/accel-location.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 Luís Ferreira + * + * 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 + * the Free Software Foundation. + * + */ + +#include "accel-location.h" + +AccelLocation +setup_accel_location (GUdevDevice *device) +{ + AccelLocation ret; + const char *location; + + location = g_udev_device_get_property (device, "ACCEL_LOCATION"); + if (location) { + if (parse_accel_location (location, &ret)) + return ret; + + g_warning ("Failed to parse ACCEL_LOCATION ('%s') from udev", + location); + } else { + g_debug ("No autodetected location, falling back to display location"); + } + + ret = ACCEL_LOCATION_DISPLAY; + return ret; +} + +gboolean +parse_accel_location (const char *location, AccelLocation *value) +{ + /* Empty string means we use the display location */ + if (location == NULL || + *location == '\0' || + (g_strcmp0 (location, "display") == 0)) { + *value = ACCEL_LOCATION_DISPLAY; + return TRUE; + } else if (g_strcmp0 (location, "base") == 0) { + *value = ACCEL_LOCATION_BASE; + return TRUE; + } else { + g_warning ("Failed to parse '%s' as a location", location); + return FALSE; + } +} \ No newline at end of file diff --git a/src/accel-location.h b/src/accel-location.h new file mode 100644 index 0000000..3edf8e3 --- /dev/null +++ b/src/accel-location.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2019 Luís Ferreira + * + * 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 + * the Free Software Foundation. + * + */ + +#include +#include + +typedef enum { + ACCEL_LOCATION_DISPLAY, + ACCEL_LOCATION_BASE, +} AccelLocation; + +AccelLocation setup_accel_location (GUdevDevice *device); + +gboolean parse_accel_location (const char *location, + AccelLocation *value); \ No newline at end of file