diff --git a/src/accel-attributes.c b/src/accel-attributes.c index 768fcfb..45fed2c 100644 --- a/src/accel-attributes.c +++ b/src/accel-attributes.c @@ -24,6 +24,11 @@ setup_accel_location (GUdevDevice *device) g_warning ("Failed to parse ACCEL_LOCATION ('%s') from udev", location); } + location = g_udev_device_get_sysfs_attr (device, "label"); + if (location) { + if (parse_accel_label (location, &ret)) + return ret; + } location = g_udev_device_get_sysfs_attr (device, "location"); if (location) { if (parse_accel_location (location, &ret)) @@ -38,6 +43,23 @@ setup_accel_location (GUdevDevice *device) return ret; } +gboolean +parse_accel_label (const char *location, AccelLocation *value) +{ + if (location == NULL || + *location == '\0') + return FALSE; + if (g_str_equal (location, "accel-base")) { + *value = ACCEL_LOCATION_BASE; + return TRUE; + } else if (g_str_equal (location, "accel-display")) { + *value = ACCEL_LOCATION_DISPLAY; + return TRUE; + } + g_debug ("Failed to parse label '%s' as a location", location); + return FALSE; +} + gboolean parse_accel_location (const char *location, AccelLocation *value) { diff --git a/src/accel-attributes.h b/src/accel-attributes.h index 1abb915..4f7031e 100644 --- a/src/accel-attributes.h +++ b/src/accel-attributes.h @@ -22,5 +22,7 @@ AccelLocation setup_accel_location (GUdevDevice *device); gboolean parse_accel_location (const char *location, AccelLocation *value); +gboolean parse_accel_label (const char *location, + AccelLocation *value); gboolean get_accel_scale (GUdevDevice *device, AccelScale *scale_vec); diff --git a/src/test-accel-location.c b/src/test-accel-location.c index 82b0a0a..5495960 100644 --- a/src/test-accel-location.c +++ b/src/test-accel-location.c @@ -13,6 +13,28 @@ #define VALID_BASE_LOCATION "base" #define INVALID_LOCATION "invalid" +#define VALID_DISPLAY_LOCATION_LABEL "accel-display" +#define VALID_BASE_LOCATION_LABEL "accel-base" +#define INVALID_LOCATION_LABEL "proximity-foo-bar" + +static void +test_accel_label (void) +{ + AccelLocation location; + + /* display location */ + g_assert_true (parse_accel_label (VALID_DISPLAY_LOCATION_LABEL, &location)); + g_assert_true (location == ACCEL_LOCATION_DISPLAY); + + /* base location */ + g_assert_true (parse_accel_label (VALID_BASE_LOCATION_LABEL, &location)); + g_assert_true (location == ACCEL_LOCATION_BASE); + + /* invalid label */ + g_assert_false (parse_accel_location (NULL, &location)); + g_assert_false (parse_accel_location (INVALID_LOCATION_LABEL, &location)); +} + static void test_accel_location (void) { @@ -41,6 +63,7 @@ int main (int argc, char **argv) g_test_init (&argc, &argv, NULL); g_test_add_func ("/iio-sensor-proxy/accel-location", test_accel_location); + g_test_add_func ("/iio-sensor-proxy/accel-label", test_accel_label); return g_test_run (); }