1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
|
From: Dylan Van Assche <me@dylanvanassche.be>
Date: Sun, 23 Apr 2023 16:54:10 +0200
Subject: [PATCH] iio-sensor-proxy: Add ssc support
---
.gitlab-ci.yml | 22 +++
data/80-iio-sensor-proxy.rules | 6 +
data/iio-sensor-proxy.service.in | 2 +-
data/meson.build | 4 +
meson.build | 1 +
meson_options.txt | 4 +
src/drivers.h | 7 +
src/drv-ssc-accel.c | 149 ++++++++++++++++
src/drv-ssc-compass.c | 131 ++++++++++++++
src/drv-ssc-light.c | 124 +++++++++++++
src/drv-ssc-proximity.c | 126 +++++++++++++
src/iio-sensor-proxy.c | 21 ++-
src/meson.build | 16 ++
tests/integration-test.py | 1 +
tests/meson.build | 14 ++
tests/ssc-test.py | 373 +++++++++++++++++++++++++++++++++++++++
16 files changed, 999 insertions(+), 2 deletions(-)
create mode 100644 src/drv-ssc-accel.c
create mode 100644 src/drv-ssc-compass.c
create mode 100644 src/drv-ssc-light.c
create mode 100644 src/drv-ssc-proximity.c
create mode 100755 tests/ssc-test.py
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f404c7a..e675640 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -41,6 +41,28 @@ build-debian-trixie:
- "${CI_PROJECT_DIR}/_build/meson-dist"
- "${CI_PROJECT_DIR}/_build/docs/html/"
+build-debian-trixie-libssc:
+ before_script:
+ - apt-get update
+ - apt-get -y install eatmydata
+ - eatmydata apt-get -y install $DEPENDENCIES
+ - eatmydata apt-get -y install python3 python-is-python3 python3-dev qrtr-tools libprotobuf-c-dev libprotobuf-dev protobuf-c-compiler protobuf-compiler python3-gi libmbim-glib-dev libqmi-glib-dev python3-protobuf libqrtr1
+ - git clone "https://codeberg.org/DylanVanAssche/libssc.git"
+ - cd libssc
+ - mkdir _build
+ - meson setup _build
+ - meson compile --verbose -C _build
+ - meson install --no-rebuild -C _build
+ - cd mocking
+ - ./ssc-server &
+ - cd ../..
+ script:
+ - meson -Dssc-support=enabled -Dtests=true -Dgtk_doc=true -Dgtk-tests=true _build
+ - meson compile --verbose -C _build
+ - meson install -C _build
+ - meson dist -C _build
+ - meson test --verbose -C _build
+
pages:
needs:
- build-debian-trixie
diff --git a/data/80-iio-sensor-proxy.rules b/data/80-iio-sensor-proxy.rules
index 8389697..0436cd5 100644
--- a/data/80-iio-sensor-proxy.rules
+++ b/data/80-iio-sensor-proxy.rules
@@ -18,6 +18,12 @@ SUBSYSTEM=="iio", TEST=="in_proximity_raw", ENV{IIO_SENSOR_PROXY_TYPE}+="iio-pol
SUBSYSTEM=="iio", TEST=="in_proximity0_raw", ENV{IIO_SENSOR_PROXY_TYPE}+="iio-poll-proximity"
SUBSYSTEM=="input", ENV{ID_INPUT_ACCELEROMETER}=="1", ENV{IIO_SENSOR_PROXY_TYPE}+="input-accel"
+# Set the sensor type for all the types we recognise for SDSP/ADSP with libssc.
+# Some devices expose the sensors via a separate SDSP while others re-use ADSP.
+# These DSPs expose itself as /dev/fastrpc-* in the misc subsystem.
+SUBSYSTEM=="misc", KERNEL=="fastrpc-adsp*", ENV{IIO_SENSOR_PROXY_TYPE}+="ssc-accel ssc-light ssc-proximity ssc-compass"
+SUBSYSTEM=="misc", KERNEL=="fastrpc-sdsp*", ENV{IIO_SENSOR_PROXY_TYPE}+="ssc-accel ssc-light ssc-proximity ssc-compass"
+
ENV{IIO_SENSOR_PROXY_TYPE}=="", GOTO="iio_sensor_proxy_end"
# We got here because we have a sensor type, which means we need the service
diff --git a/data/iio-sensor-proxy.service.in b/data/iio-sensor-proxy.service.in
index 4bc921b..29ea3c0 100644
--- a/data/iio-sensor-proxy.service.in
+++ b/data/iio-sensor-proxy.service.in
@@ -14,6 +14,6 @@ ProtectControlGroups=true
ProtectHome=true
ProtectKernelModules=true
PrivateTmp=true
-RestrictAddressFamilies=AF_UNIX AF_LOCAL AF_NETLINK
+RestrictAddressFamilies=AF_UNIX AF_LOCAL AF_NETLINK AF_QIPCRTR
MemoryDenyWriteExecute=true
RestrictRealtime=true
diff --git a/data/meson.build b/data/meson.build
index 97dbc07..49eb3e2 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,3 +1,7 @@
+rules = files(
+ '80-iio-sensor-proxy.rules'
+)
+
install_data(
'80-iio-sensor-proxy.rules',
install_dir: udev_rules_dir
diff --git a/meson.build b/meson.build
index 2a31b12..7984575 100644
--- a/meson.build
+++ b/meson.build
@@ -46,6 +46,7 @@ gio_dep = dependency('gio-2.0', version: '>= 2.76')
gudev_dep = dependency('gudev-1.0', version: '>= 237')
polkit_gobject_dep = dependency('polkit-gobject-1', version: '>= 0.91')
polkit_policy_directory = polkit_gobject_dep.get_pkgconfig_variable('policydir')
+libssc_dep = dependency('libssc', version: '>=0.2.1', required: get_option('ssc-support'))
xmllint = find_program('xmllint', required: false)
diff --git a/meson_options.txt b/meson_options.txt
index de5fbf4..b0dee40 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -18,6 +18,10 @@ option('geoclue-user',
description: 'The USER (existing) as which geoclue service is running',
type: 'string',
value: 'geoclue')
+option('ssc-support',
+ description: 'Enable Qualcomm SSC support',
+ type: 'feature',
+ value: 'auto')
option('gtk_doc',
type: 'boolean',
value: false,
diff --git a/src/drivers.h b/src/drivers.h
index 33ad667..5e0347c 100644
--- a/src/drivers.h
+++ b/src/drivers.h
@@ -161,4 +161,11 @@ extern SensorDriver iio_buffer_compass;
extern SensorDriver iio_poll_proximity;
extern SensorDriver input_proximity;
+#ifdef HAS_LIBSSC
+extern SensorDriver ssc_proximity;
+extern SensorDriver ssc_light;
+extern SensorDriver ssc_accel;
+extern SensorDriver ssc_compass;
+#endif
+
gboolean drv_check_udev_sensor_type (GUdevDevice *device, const gchar *match, const char *name);
diff --git a/src/drv-ssc-accel.c b/src/drv-ssc-accel.c
new file mode 100644
index 0000000..06470a3
--- /dev/null
+++ b/src/drv-ssc-accel.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2023-2025 Dylan Van Assche
+ *
+ * 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 "drivers.h"
+#include "accel-mount-matrix.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <libssc-sensor.h>
+#include <libssc-sensor-accelerometer.h>
+
+typedef struct DrvData {
+ SSCSensorAccelerometer *sensor;
+ gulong measurement_id;
+ AccelVec3 *mount_matrix;
+ AccelLocation location;
+ AccelScale scale;
+} DrvData;
+
+static gboolean
+ssc_accelerometer_discover (GUdevDevice *device)
+{
+ g_autoptr(SSCSensorAccelerometer) sensor = NULL;
+
+ /* Verify presence of FastRPC device */
+ if (!drv_check_udev_sensor_type (device, "ssc-accel", NULL))
+ return FALSE;
+
+ /* Open and close SSC accelerometer for discovering */
+ sensor = ssc_sensor_accelerometer_new_sync (NULL, NULL);
+ if (!sensor)
+ return FALSE;
+
+ if (!ssc_sensor_accelerometer_close_sync (sensor, NULL, NULL))
+ return FALSE;
+
+ g_debug ("Found SSC accelerometer at %s", g_udev_device_get_sysfs_path (device));
+ return TRUE;
+}
+
+static void
+measurement_cb (SSCSensorAccelerometer *sensor, gfloat accel_x, gfloat accel_y, gfloat accel_z, gpointer user_data)
+{
+ SensorDevice *sensor_device = user_data;
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+ AccelReadings readings;
+ AccelVec3 tmp;
+
+ tmp.x = accel_x;
+ tmp.y = accel_y;
+ tmp.z = accel_z;
+
+ if (!apply_mount_matrix (drv_data->mount_matrix, &tmp))
+ g_warning ("Could not apply mount matrix");
+
+ readings.accel_x = tmp.x;
+ readings.accel_y = tmp.y;
+ readings.accel_z = tmp.z;
+ copy_accel_scale (&readings.scale, drv_data->scale);
+
+ sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
+}
+
+static SensorDevice *
+ssc_accelerometer_open (GUdevDevice *device)
+{
+ g_autoptr(GError) error = NULL;
+ SensorDevice *sensor_device;
+ DrvData *drv_data;
+
+ sensor_device = g_new0 (SensorDevice, 1);
+ sensor_device->priv = g_new0 (DrvData, 1);
+
+ drv_data = (DrvData *) sensor_device->priv;
+ drv_data->sensor = ssc_sensor_accelerometer_new_sync (NULL, &error);
+ if (!drv_data->sensor)
+ g_warning ("Creating SSC accelerometer sensor failed: %s", error->message);
+
+ /* Setup accel attributes */
+ drv_data->mount_matrix = setup_mount_matrix (device);
+ drv_data->location = setup_accel_location (device);
+ set_accel_scale (&drv_data->scale, 1.0);
+
+ return sensor_device;
+}
+
+static void
+ssc_accelerometer_set_polling (SensorDevice *sensor_device, gboolean state)
+{
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+ g_autoptr(GError) error = NULL;
+ if (state) {
+ if (drv_data->measurement_id)
+ return;
+
+ /* Start listening for measurements */
+ drv_data->measurement_id = g_signal_connect (drv_data->sensor,
+ "measurement",
+ G_CALLBACK (measurement_cb),
+ sensor_device);
+ /* Enable sensor */
+ if (!ssc_sensor_accelerometer_open_sync (drv_data->sensor, NULL, &error)) {
+ g_warning ("Opening SSC accelerometer sensor failed: %s", error->message);
+ return;
+ }
+ } else {
+ if (!drv_data->measurement_id)
+ return;
+
+ /* Stop listening for measurements */
+ g_clear_signal_handler (&drv_data->measurement_id, drv_data->sensor);
+
+ /* Disable sensor */
+ if (!ssc_sensor_accelerometer_close_sync (drv_data->sensor, NULL, &error))
+ g_warning ("Closing SSC accelerometer sensor failed: %s", error->message);
+ }
+}
+
+static void
+ssc_accelerometer_close (SensorDevice *sensor_device)
+{
+ g_autoptr(GError) error = NULL;
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+
+ g_clear_object (&drv_data->sensor);
+ g_clear_pointer (&drv_data->mount_matrix, g_free);
+ g_clear_pointer (&sensor_device->priv, g_free);
+ g_free (sensor_device);
+}
+
+SensorDriver ssc_accel = {
+ .driver_name = "SSC accelerometer sensor",
+ .type = DRIVER_TYPE_ACCEL,
+
+ .discover = ssc_accelerometer_discover,
+ .open = ssc_accelerometer_open,
+ .set_polling = ssc_accelerometer_set_polling,
+ .close = ssc_accelerometer_close,
+};
diff --git a/src/drv-ssc-compass.c b/src/drv-ssc-compass.c
new file mode 100644
index 0000000..3b1a5c1
--- /dev/null
+++ b/src/drv-ssc-compass.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2023-2025 Dylan Van Assche
+ *
+ * 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 "drivers.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <libssc-sensor.h>
+#include <libssc-sensor-compass.h>
+
+typedef struct DrvData {
+ SSCSensorCompass *sensor;
+ gulong measurement_id;
+} DrvData;
+
+static gboolean
+ssc_compass_discover (GUdevDevice *device)
+{
+ g_autoptr(SSCSensorCompass) sensor = NULL;
+
+ /* Verify presence of FastRPC device */
+ if (!drv_check_udev_sensor_type (device, "ssc-compass", NULL))
+ return FALSE;
+
+ /* Open and close SSC compass for discovering */
+ sensor = ssc_sensor_compass_new_sync (NULL, NULL);
+ if (!sensor)
+ return FALSE;
+
+ if (!ssc_sensor_compass_close_sync (sensor, NULL, NULL))
+ return FALSE;
+
+ g_debug ("Found SSC compass at %s", g_udev_device_get_sysfs_path (device));
+ return TRUE;
+}
+
+static void
+measurement_cb (SSCSensorCompass *sensor, gfloat azimuth, gpointer user_data)
+{
+ SensorDevice *sensor_device = user_data;
+ CompassReadings readings;
+
+ readings.heading = azimuth;
+
+ sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
+}
+
+static SensorDevice *
+ssc_compass_open (GUdevDevice *device)
+{
+ g_autoptr(GError) error = NULL;
+ SensorDevice *sensor_device;
+ DrvData *drv_data;
+
+ sensor_device = g_new0 (SensorDevice, 1);
+ sensor_device->priv = g_new0 (DrvData, 1);
+
+ drv_data = (DrvData *) sensor_device->priv;
+ drv_data->sensor = ssc_sensor_compass_new_sync (NULL, &error);
+ if (!drv_data->sensor)
+ g_warning ("Creating SSC compass sensor failed: %s", error->message);
+ else {
+ g_object_get (drv_data->sensor,
+ SSC_SENSOR_NAME, &sensor_device->name,
+ NULL);
+ }
+
+ return sensor_device;
+}
+
+static void
+ssc_compass_set_polling (SensorDevice *sensor_device, gboolean state)
+{
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+ g_autoptr(GError) error = NULL;
+
+ if (state) {
+ if (drv_data->measurement_id)
+ return;
+ /* Start listening for measurements */
+ drv_data->measurement_id = g_signal_connect (drv_data->sensor,
+ "measurement",
+ G_CALLBACK (measurement_cb),
+ sensor_device);
+
+ /* Enable sensor */
+ if (!ssc_sensor_compass_open_sync (drv_data->sensor, NULL, &error))
+ g_warning ("Opening SSC compass sensor failed: %s", error->message);
+ } else {
+ if (!drv_data->measurement_id)
+ return;
+
+ /* Stop listening for measurements */
+ g_clear_signal_handler (&drv_data->measurement_id, drv_data->sensor);
+
+ /* Disable sensor */
+ if (!ssc_sensor_compass_close_sync (drv_data->sensor, NULL, &error))
+ g_warning ("Closing SSC compass sensor failed: %s", error->message);
+ }
+}
+
+static void
+ssc_compass_close (SensorDevice *sensor_device)
+{
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+
+ g_clear_object (&drv_data->sensor);
+ g_clear_pointer (&sensor_device->name, g_free);
+ g_clear_pointer (&sensor_device->priv, g_free);
+ g_free (sensor_device);
+}
+
+SensorDriver ssc_compass = {
+ .driver_name = "SSC compass sensor",
+ .type = DRIVER_TYPE_COMPASS,
+
+ .discover = ssc_compass_discover,
+ .open = ssc_compass_open,
+ .set_polling = ssc_compass_set_polling,
+ .close = ssc_compass_close,
+};
diff --git a/src/drv-ssc-light.c b/src/drv-ssc-light.c
new file mode 100644
index 0000000..1a66140
--- /dev/null
+++ b/src/drv-ssc-light.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2023-2025 Dylan Van Assche
+ *
+ * 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 "drivers.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <libssc-sensor.h>
+#include <libssc-sensor-light.h>
+
+typedef struct DrvData {
+ SSCSensorLight *sensor;
+ gulong measurement_id;
+} DrvData;
+
+static gboolean
+ssc_light_discover (GUdevDevice *device)
+{
+ g_autoptr(SSCSensorLight) sensor = NULL;
+
+ /* Verify presence of FastRPC device */
+ if (!drv_check_udev_sensor_type (device, "ssc-light", NULL))
+ return FALSE;
+
+ /* Open and close SSC light sensor for discovering */
+ sensor = ssc_sensor_light_new_sync (NULL, NULL);
+ if (!sensor)
+ return FALSE;
+
+ if (!ssc_sensor_light_close_sync (sensor, NULL, NULL))
+ return FALSE;
+
+ g_debug ("Found SSC light at %s", g_udev_device_get_sysfs_path (device));
+ return TRUE;
+}
+
+static void
+measurement_cb (SSCSensorLight *sensor, gfloat intensity, gpointer user_data)
+{
+ SensorDevice *sensor_device = user_data;
+ LightReadings readings;
+
+ readings.level = intensity;
+ readings.uses_lux = TRUE;
+ sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
+}
+
+static SensorDevice *
+ssc_light_open (GUdevDevice *device)
+{
+ g_autoptr(GError) error = NULL;
+ SensorDevice *sensor_device;
+ DrvData *drv_data;
+
+ sensor_device = g_new0 (SensorDevice, 1);
+ sensor_device->priv = g_new0 (DrvData, 1);
+
+ drv_data = (DrvData *) sensor_device->priv;
+ drv_data->sensor = ssc_sensor_light_new_sync (NULL, &error);
+ if (!drv_data->sensor)
+ g_warning ("Creating SSC light sensor failed: %s", error->message);
+
+ return sensor_device;
+}
+
+static void
+ssc_light_set_polling (SensorDevice *sensor_device, gboolean state)
+{
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+ g_autoptr (GError) error = NULL;
+ if (state) {
+ if (drv_data->measurement_id)
+ return;
+ /* Start listening for measurements */
+ drv_data->measurement_id = g_signal_connect (drv_data->sensor,
+ "measurement",
+ G_CALLBACK (measurement_cb),
+ sensor_device);
+ /* Enable sensor */
+ if (!ssc_sensor_light_open_sync (drv_data->sensor, NULL, &error))
+ g_warning ("Opening SSC light sensor failed: %s", error->message);
+ } else {
+ if (!drv_data->measurement_id)
+ return;
+
+ /* Stop listening for measurements */
+ g_clear_signal_handler (&drv_data->measurement_id, drv_data->sensor);
+
+ /* Disable sensor */
+ if (!ssc_sensor_light_close_sync (drv_data->sensor, NULL, &error))
+ g_warning ("Closing SSC light sensor failed: %s", error->message);
+ }
+}
+
+static void
+ssc_light_close (SensorDevice *sensor_device)
+{
+ g_autoptr(GError) error = NULL;
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+
+ g_clear_object (&drv_data->sensor);
+ g_clear_pointer (&sensor_device->priv, g_free);
+ g_free (sensor_device);
+}
+
+SensorDriver ssc_light = {
+ .driver_name = "SSC light sensor",
+ .type = DRIVER_TYPE_LIGHT,
+
+ .discover = ssc_light_discover,
+ .open = ssc_light_open,
+ .set_polling = ssc_light_set_polling,
+ .close = ssc_light_close,
+};
diff --git a/src/drv-ssc-proximity.c b/src/drv-ssc-proximity.c
new file mode 100644
index 0000000..f0ba5a2
--- /dev/null
+++ b/src/drv-ssc-proximity.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2023-2025 Dylan Van Assche
+ *
+ * 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 "drivers.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <libssc-sensor.h>
+#include <libssc-sensor-proximity.h>
+
+typedef struct DrvData {
+ SSCSensorProximity *sensor;
+ gulong measurement_id;
+} DrvData;
+
+static gboolean
+ssc_proximity_discover (GUdevDevice *device)
+{
+ SSCSensorProximity *sensor = NULL;
+
+ /* Verify presence of FastRPC device */
+ if (!drv_check_udev_sensor_type (device, "ssc-proximity", NULL))
+ return FALSE;
+
+ /* Open and close SSC proximity sensor for discovering */
+ sensor = ssc_sensor_proximity_new_sync (NULL, NULL);
+ if (!sensor)
+ return FALSE;
+
+ if (!ssc_sensor_proximity_close_sync (sensor, NULL, NULL)) {
+ g_clear_object (&sensor);
+ return FALSE;
+ }
+
+ g_clear_object (&sensor);
+
+ g_debug ("Found SSC proximity at %s", g_udev_device_get_sysfs_path (device));
+ return TRUE;
+}
+
+static void
+measurement_cb (SSCSensorProximity *sensor, gboolean near, gpointer user_data)
+{
+ SensorDevice *sensor_device = user_data;
+ ProximityReadings readings;
+
+ readings.is_near = near ? PROXIMITY_NEAR_TRUE : PROXIMITY_NEAR_FALSE;
+ sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
+}
+
+static SensorDevice *
+ssc_proximity_open (GUdevDevice *device)
+{
+ g_autoptr(GError) error = NULL;
+ SensorDevice *sensor_device;
+ DrvData *drv_data;
+
+ sensor_device = g_new0 (SensorDevice, 1);
+ sensor_device->priv = g_new0 (DrvData, 1);
+ drv_data = (DrvData *) sensor_device->priv;
+ drv_data->sensor = ssc_sensor_proximity_new_sync (NULL, &error);
+ if (!drv_data->sensor)
+ g_warning ("Creating SSC proximity sensor failed: %s", error->message);
+
+ return sensor_device;
+}
+
+static void
+ssc_proximity_set_polling (SensorDevice *sensor_device, gboolean state)
+{
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+ g_autoptr(GError) error = NULL;
+ if (state) {
+ if (drv_data->measurement_id)
+ return;
+ /* Start listening for measurements */
+ drv_data->measurement_id = g_signal_connect (drv_data->sensor,
+ "measurement",
+ G_CALLBACK (measurement_cb),
+ sensor_device);
+
+ /* Enable sensor */
+ if (!ssc_sensor_proximity_open_sync (drv_data->sensor, NULL, &error)) {
+ g_warning ("Opening SSC proximity sensor failed: %s", error ? error->message : "UNKNOWN");
+ return;
+ }
+ } else {
+ if (!drv_data->measurement_id)
+ return;
+ /* Stop listening for measurements */
+ g_clear_signal_handler (&drv_data->measurement_id, drv_data->sensor);
+ /* Disable sensor */
+ if (!ssc_sensor_proximity_close_sync (drv_data->sensor, NULL, &error))
+ g_warning ("Closing SSC proximity sensor failed: %s", error->message);
+ }
+}
+
+static void
+ssc_proximity_close (SensorDevice *sensor_device)
+{
+ DrvData *drv_data = (DrvData *) sensor_device->priv;
+
+ g_clear_object (&drv_data->sensor);
+ g_clear_pointer (&sensor_device->priv, g_free);
+ g_free (sensor_device);
+}
+
+SensorDriver ssc_proximity = {
+ .driver_name = "SSC proximity sensor",
+ .type = DRIVER_TYPE_PROXIMITY,
+
+ .discover = ssc_proximity_discover,
+ .open = ssc_proximity_open,
+ .set_polling = ssc_proximity_set_polling,
+ .close = ssc_proximity_close,
+};
diff --git a/src/iio-sensor-proxy.c b/src/iio-sensor-proxy.c
index 5f26d3d..75ad0fe 100644
--- a/src/iio-sensor-proxy.c
+++ b/src/iio-sensor-proxy.c
@@ -79,6 +79,12 @@ static const SensorDriver * const drivers[] = {
&iio_buffer_compass,
&iio_poll_proximity,
&input_proximity,
+#ifdef HAS_LIBSSC
+ &ssc_proximity,
+ &ssc_light,
+ &ssc_accel,
+ &ssc_compass,
+#endif
};
static ReadingsUpdateFunc driver_type_to_callback_func (DriverType type);
@@ -128,6 +134,11 @@ find_sensors (GUdevClient *client,
platform = g_udev_client_query_by_subsystem (client, "platform");
devices = g_list_concat (devices, input);
devices = g_list_concat (devices, platform);
+#ifdef HAS_LIBSSC
+ GList *fastrpc;
+ fastrpc = g_udev_client_query_by_subsystem (client, "misc");
+ devices = g_list_concat (devices, fastrpc);
+#endif
/* Find the devices */
for (l = devices; l != NULL; l = l->next) {
@@ -727,7 +738,15 @@ name_acquired_handler (GDBusConnection *connection,
gpointer user_data)
{
SensorData *data = user_data;
- const gchar * const subsystems[] = { "iio", "input", "platform", NULL };
+ const gchar * const subsystems[] = {
+ "iio",
+ "input",
+ "platform",
+#ifdef HAS_LIBSSC
+ "misc",
+#endif
+ NULL
+ };
guint i;
data->client = g_udev_client_new (subsystems);
diff --git a/src/meson.build b/src/meson.build
index 4b822fc..3337e24 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,5 +1,8 @@
config_h = configuration_data()
config_h.set_quoted('VERSION', meson.project_version())
+if get_option('ssc-support').enabled()
+ config_h.set_quoted('HAS_LIBSSC', '1')
+endif
config_h_files = configure_file(
output: 'config.h',
configuration: config_h
@@ -7,6 +10,10 @@ config_h_files = configure_file(
deps = [ gio_dep, gudev_dep, mathlib_dep, polkit_gobject_dep ]
+if get_option('ssc-support').enabled()
+ deps = deps + [ libssc_dep ]
+endif
+
resources = gnome.compile_resources(
'iio-sensor-proxy-resources', 'iio-sensor-proxy.gresource.xml',
c_name: 'iio_sensor_proxy',
@@ -38,6 +45,15 @@ sources = [
config_h_files,
]
+if get_option('ssc-support').enabled()
+ sources = sources + [
+ 'drv-ssc-proximity.c',
+ 'drv-ssc-light.c',
+ 'drv-ssc-accel.c',
+ 'drv-ssc-compass.c',
+ ]
+endif
+
executable('iio-sensor-proxy',
sources,
dependencies: deps,
diff --git a/tests/integration-test.py b/tests/integration-test.py
index 95b9da3..23bf623 100755
--- a/tests/integration-test.py
+++ b/tests/integration-test.py
@@ -56,6 +56,7 @@ class Tests(dbusmock.DBusTestCase):
def setUpClass(cls):
# run from local build tree if we are in one, otherwise use system instance
builddir = os.getenv('top_builddir', '.')
+ print(os.path.join(builddir, 'src', 'iio-sensor-proxy'))
if os.access(os.path.join(builddir, 'src', 'iio-sensor-proxy'), os.X_OK):
cls.daemon_path = os.path.join(builddir, 'src', 'iio-sensor-proxy')
cls.monitor_sensor_path = os.path.join(builddir, 'src', 'monitor-sensor')
diff --git a/tests/meson.build b/tests/meson.build
index e51e90f..3ce4a37 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -16,3 +16,17 @@ foreach ut: unit_tests
env: envs,
)
endforeach
+
+if get_option('ssc-support').enabled()
+ r = run_command(unittest_inspector, files('ssc-test.py'), check: true)
+ unit_tests = r.stdout().strip().split('\n')
+ foreach ut: unit_tests
+ ut_args = files('ssc-test.py')
+ ut_args += ut
+ test(ut,
+ python3,
+ args: ut_args,
+ env: envs,
+ )
+ endforeach
+endif
diff --git a/tests/ssc-test.py b/tests/ssc-test.py
new file mode 100755
index 0000000..72e24f0
--- /dev/null
+++ b/tests/ssc-test.py
@@ -0,0 +1,373 @@
+#!/usr/bin/python3
+
+# iio-sensor-proxy integration test suite
+#
+# Run in built tree to test local built binaries, or from anywhere else to test
+# system installed binaries.
+#
+# Copyright: (C) 2011 Martin Pitt <martin.pitt@ubuntu.com>
+# (C) 2021 Bastien Nocera <hadess@hadess.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import os
+import sys
+import dbus
+import dbusmock
+import gi
+import tempfile
+import psutil
+import subprocess
+import unittest
+import locale
+import time
+
+try:
+ from gi.repository import GLib
+ from gi.repository import Gio
+except ImportError as e:
+ sys.stderr.write('PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e))
+ sys.exit(1)
+
+try:
+ gi.require_version('UMockdev', '1.0')
+ from gi.repository import UMockdev
+except ImportError:
+ sys.stderr.write('umockdev not available (https://github.com/martinpitt/umockdev)\n')
+ sys.exit(1)
+
+
+SP = 'net.hadess.SensorProxy'
+SP_PATH = '/net/hadess/SensorProxy'
+SP_COMPASS = 'net.hadess.SensorProxy.Compass'
+SP_COMPASS_PATH = '/net/hadess/SensorProxy/Compass'
+
+class Tests(dbusmock.DBusTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ # run from local build tree if we are in one, otherwise use system instance
+ builddir = os.getenv('top_builddir', '.')
+ print(os.path.join(builddir, 'src', 'iio-sensor-proxy'))
+ if os.access(os.path.join(builddir, 'src', 'iio-sensor-proxy'), os.X_OK):
+ cls.daemon_path = os.path.join(builddir, 'src', 'iio-sensor-proxy')
+ cls.monitor_sensor_path = os.path.join(builddir, 'src', 'monitor-sensor')
+ print('Testing binaries from local build tree (%s)' % cls.daemon_path)
+ elif os.environ.get('UNDER_JHBUILD', False):
+ jhbuild_prefix = os.environ['JHBUILD_PREFIX']
+ cls.daemon_path = os.path.join(jhbuild_prefix, 'libexec', 'iio-sensor-proxy')
+ cls.monitor_sensor_path = os.path.join(jhbuild_prefix, 'bin', 'monitor-sensor')
+ print('Testing binaries from JHBuild (%s)' % cls.daemon_path)
+ else:
+ cls.daemon_path = None
+ with open('/usr/lib/systemd/system/iio-sensor-proxy.service') as f:
+ for line in f:
+ if line.startswith('ExecStart='):
+ cls.daemon_path = line.split('=', 1)[1].strip()
+ break
+ assert cls.daemon_path, 'could not determine daemon path from systemd .service file'
+ cls.monitor_sensor_path = '/usr/bin/monitor-sensor'
+ print('Testing installed system binary (%s)' % cls.daemon_path)
+
+ # fail on CRITICALs on client and server side
+ GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING |
+ GLib.LogLevelFlags.LEVEL_ERROR |
+ GLib.LogLevelFlags.LEVEL_CRITICAL)
+ os.environ['G_DEBUG'] = 'fatal_warnings'
+
+ # set up a fake system D-BUS
+ cls.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
+ cls.test_bus.up()
+ try:
+ del os.environ['DBUS_SESSION_BUS_ADDRESS']
+ except KeyError:
+ pass
+ os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = cls.test_bus.get_bus_address()
+
+ cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
+ cls.dbus_con = cls.get_dbus(True)
+
+ # Some test outputs require the daemon to run under the fr locale:
+ # so check if that's available
+ try:
+ old_loc = locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
+ locale.setlocale(locale.LC_ALL, old_loc)
+ # We need to make sure the decimal point is correct as on musl libc the above
+ # succeeds yet the tests just fail due to the output being in unexpected format
+ cls.has_fr = locale.localeconv()["decimal_point"] == ","
+ except:
+ cls.has_fr = False
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.test_bus.down()
+ dbusmock.DBusTestCase.tearDownClass()
+
+ def setUp(self):
+ '''Set up a local umockdev testbed.
+
+ The testbed is initially empty.
+ '''
+ self.testbed = UMockdev.Testbed.new()
+ self.polkitd, obj_polkit = self.spawn_server_template(
+ 'polkitd', {}, stdout=subprocess.PIPE)
+ obj_polkit.SetAllowed(['net.hadess.SensorProxy.claim-sensor'])
+
+ self.proxy = None
+ self.log = None
+ self.daemon = None
+
+ def run(self, result=None):
+ super(Tests, self).run(result)
+ if result and len(result.errors) + len(result.failures) > 0 and self.log:
+ with open(self.log.name) as f:
+ sys.stderr.write('\n-------------- daemon log: ----------------\n')
+ sys.stderr.write(f.read())
+ sys.stderr.write('------------------------------\n')
+
+ def tearDown(self):
+ del self.testbed
+ self.stop_daemon()
+
+ if self.polkitd:
+ try:
+ self.polkitd.kill()
+ except OSError:
+ pass
+ self.polkitd.wait()
+ self.polkitd = None
+
+ #
+ # Daemon control and D-BUS I/O
+ #
+
+ def start_daemon(self, env = None, wrapper = None):
+ '''Start daemon and create DBus proxy.
+
+ When done, this sets self.proxy as the Gio.DBusProxy for power-profiles-daemon.
+ '''
+ if not env:
+ env = os.environ.copy()
+ env['G_DEBUG'] = 'fatal-criticals'
+ env['G_MESSAGES_DEBUG'] = 'all'
+ env['UMOCKDEV_DEBUG'] = 'all'
+ # note: Python doesn't propagate the setenv from Testbed.new(), so we
+ # have to do that ourselves
+ env['UMOCKDEV_DIR'] = self.testbed.get_root_dir()
+ self.log = tempfile.NamedTemporaryFile()
+ timeout_multiplier = 1
+ if wrapper:
+ daemon_path = wrapper + [ self.daemon_path ]
+ else:
+ daemon_path = [ self.daemon_path ]
+ if os.getenv('VALGRIND') != None:
+ daemon_path = ['valgrind'] + daemon_path + ['-v']
+ timeout_multiplier = 10
+ else:
+ daemon_path = daemon_path + ['-v']
+
+ self.daemon = subprocess.Popen(daemon_path,
+ env=env, stdout=self.log,
+ stderr=subprocess.STDOUT)
+
+ # wait until the daemon gets online
+ timeout = 100 * timeout_multiplier
+ while timeout > 0:
+ time.sleep(0.1)
+ timeout -= 1
+ try:
+ self.get_dbus_property('HasAccelerometer')
+ break
+ except GLib.GError:
+ pass
+ else:
+ self.fail('daemon did not start in 10 seconds')
+
+ self.proxy = Gio.DBusProxy.new_sync(
+ self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, SP,
+ SP_PATH, SP, None)
+
+ self.assertEqual(self.daemon.poll(), None, 'daemon crashed')
+
+ def stop_daemon(self):
+ '''Stop the daemon if it is running.'''
+
+ if self.daemon:
+ try:
+ for child in psutil.Process(self.daemon.pid).children(recursive=True):
+ child.kill()
+ self.daemon.kill()
+ except OSError:
+ pass
+ self.daemon.wait()
+ self.daemon = None
+ self.proxy = None
+
+ def get_dbus_property(self, name):
+ '''Get property value from daemon D-Bus interface.'''
+
+ proxy = Gio.DBusProxy.new_sync(
+ self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, SP,
+ SP_PATH, 'org.freedesktop.DBus.Properties', None)
+ return proxy.Get('(ss)', SP, name)
+
+ def get_compass_dbus_property(self, name):
+ '''Get property value from daemon compass D-Bus interface.'''
+
+ proxy = Gio.DBusProxy.new_sync(
+ self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, SP,
+ SP_COMPASS_PATH, 'org.freedesktop.DBus.Properties', None)
+ return proxy.Get('(ss)', SP_COMPASS, name)
+
+ def have_text_in_log(self, text):
+ return self.count_text_in_log(text) > 0
+
+ def count_text_in_log(self, text):
+ with open(self.log.name) as f:
+ return f.read().count(text)
+
+ def read_sysfs_attr(self, device, attribute):
+ with open(os.path.join(self.testbed.get_root_dir() + device, attribute), 'rb') as f:
+ return f.read()
+ return None
+
+ def read_file(self, path):
+ with open(path, 'rb') as f:
+ return f.read()
+ return None
+
+ def assertEventually(self, condition, message=None, timeout=50):
+ '''Assert that condition function eventually returns True.
+
+ Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
+ printed on failure.
+ '''
+ while timeout >= 0:
+ context = GLib.MainContext.default()
+ while context.iteration(False):
+ pass
+ if condition():
+ break
+ timeout -= 1
+ time.sleep(0.1)
+ else:
+ self.fail(message or 'timed out waiting for ' + str(condition))
+
+ #
+ # Actual test cases
+ #
+
+ def test_ssc_proximity(self):
+ '''SSC proximity'''
+ prox = self.testbed.add_device('misc', 'ssc-proximity', None,
+ ['name', 'SSC Test Proximity Sensor'],
+ ['NAME', '"SSC Proximity Sensor"',
+ 'DEVNAME', '/dev/fastrpc-sdsp',
+ 'IIO_SENSOR_PROXY_TYPE', 'ssc-proximity']
+ )
+ self.start_daemon()
+ self.assertEqual(self.get_dbus_property('HasAmbientLight'), False)
+ self.assertEqual(self.get_dbus_property('HasAccelerometer'), False)
+ self.assertEqual(self.get_dbus_property('HasProximity'), True)
+ self.assertEqual(self.get_compass_dbus_property('HasCompass'), False)
+
+ # Default values
+ self.assertEqual(self.get_dbus_property('ProximityNear'), False)
+
+ self.proxy.ClaimProximity()
+ self.assertEqual(self.get_dbus_property('ProximityNear'), True)
+ self.assertEventually(lambda: self.get_dbus_property('ProximityNear') == False)
+ self.assertEventually(lambda: self.get_dbus_property('ProximityNear') == True)
+
+ self.stop_daemon()
+
+ def test_ssc_accel(self):
+ '''SSC accelerometer'''
+ prox = self.testbed.add_device('misc', 'ssc-accel', None,
+ ['name', 'SSC Test Accelerometer Sensor'],
+ ['NAME', '"SSC Accelerometer Sensor"',
+ 'DEVNAME', '/dev/fastrpc-sdsp',
+ 'IIO_SENSOR_PROXY_TYPE', 'ssc-accel']
+ )
+ self.start_daemon()
+ self.assertEqual(self.get_dbus_property('HasAmbientLight'), False)
+ self.assertEqual(self.get_dbus_property('HasAccelerometer'), True)
+ self.assertEqual(self.get_dbus_property('HasProximity'), False)
+ self.assertEqual(self.get_compass_dbus_property('HasCompass'), False)
+
+ self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'undefined')
+
+ self.proxy.ClaimAccelerometer()
+ self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'left-up')
+
+ self.stop_daemon()
+
+ def test_ssc_light(self):
+ '''SSC light'''
+ prox = self.testbed.add_device('misc', 'ssc-light', None,
+ ['name', 'SSC Test Light Sensor'],
+ ['NAME', '"SSC Light Sensor"',
+ 'DEVNAME', '/dev/fastrpc-sdsp',
+ 'IIO_SENSOR_PROXY_TYPE', 'ssc-light']
+ )
+ self.start_daemon()
+ self.assertEqual(self.get_dbus_property('HasAmbientLight'), True)
+ self.assertEqual(self.get_dbus_property('HasAccelerometer'), False)
+ self.assertEqual(self.get_dbus_property('HasProximity'), False)
+ self.assertEqual(self.get_compass_dbus_property('HasCompass'), False)
+
+ # Default values
+ self.assertEqual(self.get_dbus_property('LightLevelUnit'), 'lux')
+ self.assertEqual(self.get_dbus_property('LightLevel'), 0)
+
+ self.proxy.ClaimLight()
+ self.assertEventually(lambda: self.get_dbus_property('LightLevel') == 7)
+ self.assertEqual(self.get_dbus_property('LightLevelUnit'), 'lux')
+
+ self.stop_daemon()
+
+ def test_ssc_compass(self):
+ '''SSC compass'''
+ prox = self.testbed.add_device('misc', 'ssc-compass', None,
+ ['name', 'SSC Test Compass Sensor'],
+ ['NAME', '"SSC Compass Sensor"',
+ 'DEVNAME', '/dev/fastrpc-sdsp',
+ 'IIO_SENSOR_PROXY_TYPE', 'ssc-compass']
+ )
+ self.start_daemon()
+ self.assertEqual(self.get_dbus_property('HasAmbientLight'), False)
+ self.assertEqual(self.get_dbus_property('HasAccelerometer'), False)
+ self.assertEqual(self.get_dbus_property('HasProximity'), False)
+ self.assertEqual(self.get_compass_dbus_property('HasCompass'), True)
+ self.assertEqual(int(self.get_compass_dbus_property('CompassHeading')), 0)
+
+ self.stop_daemon()
+
+ #
+ # Helper methods
+ #
+
+ @classmethod
+ def _props_to_str(cls, properties):
+ '''Convert a properties dictionary to uevent text representation.'''
+
+ prop_str = ''
+ if properties:
+ for k, v in properties.items():
+ prop_str += '%s=%s\n' % (k, v)
+ return prop_str
+
+if __name__ == '__main__':
+ # run ourselves under umockdev
+ if 'umockdev' not in os.environ.get('LD_PRELOAD', ''):
+ os.execvp('umockdev-wrapper', ['umockdev-wrapper'] + sys.argv)
+
+ unittest.main()
|