File: README.md

package info (click to toggle)
iio-sensor-proxy 3.8-1.ssc0
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 764 kB
  • sloc: ansic: 5,667; python: 995; xml: 105; makefile: 15; sh: 13
file content (229 lines) | stat: -rw-r--r-- 9,008 bytes parent folder | download | duplicates (3)
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
iio-sensor-proxy
================

IIO sensors to D-Bus proxy

See https://hadess.pages.freedesktop.org/iio-sensor-proxy/ for
developer information.

Matrix room: https://matrix.to/#/#iio-sensor-proxy:dylanvanassche.be

Installation
------------
```sh
$ meson _build -Dprefix=/usr
$ ninja -v -C _build install
```
It requires libgudev, systemd (>= 233 for the accelerometer quirks) and polkit-gobject.

Running the tests will require gobject-introspection support for Python,
[python-dbusmock](https://github.com/martinpitt/python-dbusmock/),
[umockdev](https://github.com/martinpitt/umockdev) and [psutil](https://github.com/giampaolo/psutil).

Usage
-----

With a GNOME 3.18 (or newer) based system, orientation changes will
automatically be applied when rotating the panel, ambient light will be used
to change the screen brightness, and GeoClue will be able to read the compass
data to show the direction in Maps.

Note that nothing in iio-sensor-proxy is GNOME specific, or relies on GNOME.
GNOME and GeoClue use the data provided by iio-sensor-proxy, other desktop
environments are more than welcome to use this as a basis for their own
integration.

Debugging
---------

Note that a number of kernel bugs will prevent it from working correctly on
some machines so please make sure to use the latest upstream kernel (kernel
crashes on the Surface Pro, sensor failing to work after suspend on the Yoga
Pro, etc.).

You can verify that sensors are detected by running `udevadm info --export-db`
and checking for an output resembling this one:
```
P: /devices/platform/80860F41:04/i2c-12/i2c-BMA250E:00/iio:device0
N: iio:device0
E: DEVNAME=/dev/iio:device0
E: DEVPATH=/devices/platform/80860F41:04/i2c-12/i2c-BMA250E:00/iio:device0
E: DEVTYPE=iio_device
E: MAJOR=249
E: MINOR=0
E: SUBSYSTEM=iio
E: SYSTEMD_WANTS=iio-sensor-proxy.service
E: TAGS=:systemd:
E: USEC_INITIALIZED=7750292
```

You can now check whether a sensor is detected by running:
```
gdbus introspect --system --dest net.hadess.SensorProxy --object-path /net/hadess/SensorProxy
```

After that, use `monitor-sensor` to see changes in the ambient light,
accelerometer, compass or proximity sensors.
```sh
Usage:
  monitor-sensor [OPTION…]

Help Options:
  -h, --help       Show help options

Application Options:
  -a, --all        Monitor all the sensor changes
  --accel          Monitor accelerometer changes
  --proximity      Monitor proximity sensor changes
  --compass        Monitor compass changes
  --light          Monitor light changes changes
```

If that doesn't work, please file an issue, make sure iio-sensor-proxy is new
enough and attach the output of:
```sh
/usr/libexec/iio-sensor-proxy -v -r
```
running as `root`.

Note that, before filing any issues against iio-sensor-proxy, you'll want
to make doubly-sure that the IIO device actually works, using `iio_generic_buffer`
(usually packaged as part of the `kernel-tools` package). For example, to
test IIO sensor `0`:
```sh
sudo iio_generic_buffer -A -N 0
```

Accelerometer orientation
-------------------------

iio-sensor-proxy expects the accelerometer readings to match those defined
in the [Linux IIO](https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/tree/Documentation/ABI/testing/sysfs-bus-iio#n1638)
documentation, the [Windows Integrating Motion and Orientation Sensors](https://docs.microsoft.com/en-us/windows-hardware/design/whitepapers/integrating-motion-and-orientation-sensors)
whitepaper, and the [Android sensor documentation](https://developer.android.com/reference/android/hardware/SensorEvent).

When the accelerometer is not mounted the same way as the screen, we need
to modify the readings from the accelerometer to make sure that the computed
orientation matches the screen one.

This is done using a “mount matrix”, a matrix that applied to the reading will
correct that reading to match the expected orientation, whether:
- selecting a value for an axis (with a $`1`$)
- negating that value (with a $`-1`$)
- ignoring that value (with a $`0`$)

```math
  \left[ {\begin{array}{ccc}
   accel~x & accel~y & accel~z\\
  \end{array} } \right]
*
  \left[ {\begin{array}{ccc}
   x_1 & y_1 & z_1\\
   x_2 & y_2 & z_2\\
   x_3 & y_3 & z_3\\
  \end{array} } \right]
 =
  \left[ {\begin{array}{ccc}
   corrected~x & corrected~y & corrected~z\\
  \end{array} } \right]
```

For each axis of the original accelerometer reading, a corresponding line in the
mount matrix will be used to compute which axis it should be assigned to in the
corrected readings. For example, the first line of the matrix will define whether
the $`accel~x`$ value will correspond to the corrected $`x`$, $`y`$ or $`z`$ axis
(with a $`1`$ for that axis, and $`0`$ for the others), or needs to be negated
(by setting it to $`-1`$).

A matrix of $` \left[ {\begin{array}{ccc}
   0 & 0 & 1\\
   0 & -1 & 0\\
   1 & 0 & 0\\
  \end{array} } \right]
`$ will swap the $`x`$ and $`z`$ values, and negate the $`y`$ reading.

A matrix of $` \left[ {\begin{array}{ccc}
   1 & 0 & 0\\
   0 & 1 & 0\\
   0 & 0 & 1\\
  \end{array} } \right]
`$ (the identity matrix) is the default, and will not change any of the read
values.

Each accelerometer axis reading can only be assigned (negated or not) to a
single corrected axis reading, and each corrected axis reading can only come
from a single accelerometer axis reading.

`iio-sensor-proxy` reads this information from the device's
`ACCEL_MOUNT_MATRIX` udev property. See [60-sensor.hwdb](https://github.com/systemd/systemd/blob/master/hwdb.d/60-sensor.hwdb)
for details.

For device-tree based devices, and some ACPI ones too, the `mount_matrix`,
`in_accel_mount_matrix` and `in_mount_matrix` sysfs files can also be used
to export that information directly from the kernel.

The mount matrix format used in systemd's hwdb and the IIO subsystem is a
one-line representation of the matrix above:
```math
x_1, y_1, z_1; x_2, y_2, z_2; x_3, y_3, z_3
```

Accelerometer testing (without an accelerometer)
------------------------------------------------

If your hardware lacks an accelerometer, you can run the `fake-input-accelerometer` binary as root.
This should create a new virtual device on the system, which can be interacted through `monitor-sensor`,
`evtest`, or raw D-Bus. Use the printed keyboard commands to change the calculated orientation
of that accelerometer.

Compass testing
---------------

Only the GeoClue daemon (as the geoclue user) is allowed to access the `net.hadess.SensorProxy.Compass`
interface, the results of which it will propagate to clients along with positional information.

If your device does not contain a compass, you can run tests with:
- If your device does not contain a real compass:
  - Add FAKE_COMPASS=1 to the environment of `iio-sensor-proxy.service` if your device does not contain a real one
  - Run the daemon manually with `systemctl start iio-sensor-proxy.service`
- Verify that iio-sensor-proxy is running with `systemctl` or `ps`
- As root, get a shell as the `geoclue` user with `su -s /bin/bash geoclue`
- Run, as the `geoclue` user, `monitor-sensor`

Proximity sensor near detection
-------------------------------

Whether an object is considered near to a proximity sensor depends on the
sensor configuration and scale but also on the device's physical properties
(e.g. the distance of the sensor from the covering glass) so there is
no good device-independent default.

`iio-sensor-proxy` reads this information from the device's
`PROXIMITY_NEAR_LEVEL` udev property. See [60-sensor.hwdb](https://github.com/systemd/systemd/blob/master/hwdb.d/60-sensor.hwdb)
for details.

For device-tree based devices, exporting the information through the kernel is done
via the [near-level property](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/iio/common.yaml#n22).

Known problems
--------------

Every Linux kernel from 4.3 up to version 4.12 had a bug that made
made iio-sensor-proxy fail to see any events coming from sensors until the
sensor was power-cycled (unplugged and replugged, or suspended and resumed).

The bug was finally fixed in [this commit](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f1664eaacec31035450132c46ed2915fd2b2049a)
in the upstream kernel and backported to stable releases. If you experience
unresponsive sensors, ask your distributor to make sure this patch was
applied to the version you're using.

The IIO sensors regressed again not long afterwards, which got fixed in
[this commit](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6f92253024d9d947a4f454654840ce479e251376).
Again, make sure that your kernel contains this fix.

References
----------

- [sensorfw](https://git.merproject.org/mer-core/sensorfw/tree/master)
- [android-iio-sensors-hal](https://github.com/01org/android-iio-sensors-hal)
- [Sensor orientation on MSDN](https://msdn.microsoft.com/en-us/windows/uwp/devices-sensors/sensor-orientation)