accel: Add support for the new "accel-*" IIO labels
See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9a6df4b1ab0e467f23ccdcbb82700cfb3eaf44a3
This commit is contained in:
@@ -24,6 +24,11 @@ setup_accel_location (GUdevDevice *device)
|
|||||||
g_warning ("Failed to parse ACCEL_LOCATION ('%s') from udev",
|
g_warning ("Failed to parse ACCEL_LOCATION ('%s') from udev",
|
||||||
location);
|
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");
|
location = g_udev_device_get_sysfs_attr (device, "location");
|
||||||
if (location) {
|
if (location) {
|
||||||
if (parse_accel_location (location, &ret))
|
if (parse_accel_location (location, &ret))
|
||||||
@@ -38,6 +43,23 @@ setup_accel_location (GUdevDevice *device)
|
|||||||
return ret;
|
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
|
gboolean
|
||||||
parse_accel_location (const char *location, AccelLocation *value)
|
parse_accel_location (const char *location, AccelLocation *value)
|
||||||
{
|
{
|
||||||
|
@@ -22,5 +22,7 @@ AccelLocation setup_accel_location (GUdevDevice *device);
|
|||||||
|
|
||||||
gboolean parse_accel_location (const char *location,
|
gboolean parse_accel_location (const char *location,
|
||||||
AccelLocation *value);
|
AccelLocation *value);
|
||||||
|
gboolean parse_accel_label (const char *location,
|
||||||
|
AccelLocation *value);
|
||||||
|
|
||||||
gboolean get_accel_scale (GUdevDevice *device, AccelScale *scale_vec);
|
gboolean get_accel_scale (GUdevDevice *device, AccelScale *scale_vec);
|
||||||
|
@@ -13,6 +13,28 @@
|
|||||||
#define VALID_BASE_LOCATION "base"
|
#define VALID_BASE_LOCATION "base"
|
||||||
#define INVALID_LOCATION "invalid"
|
#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
|
static void
|
||||||
test_accel_location (void)
|
test_accel_location (void)
|
||||||
{
|
{
|
||||||
@@ -41,6 +63,7 @@ int main (int argc, char **argv)
|
|||||||
g_test_init (&argc, &argv, NULL);
|
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-location", test_accel_location);
|
||||||
|
g_test_add_func ("/iio-sensor-proxy/accel-label", test_accel_label);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user