This fixes this compilation warning:
iio-sensor-proxy.c: In function ‘sensor_changes’:
iio-sensor-proxy.c:737:9: error: declaration of ‘i’ shadows a previous local [-Werror=shadow]
guint i;
^
iio-sensor-proxy.c:710:8: note: shadowed declaration is here
guint i;
Using 4.8-rc kernel, orientation got flipped. The right-up became normal
and normal became right-up. The reason for this is that orientation code
of iio-sensor-proxy observes x and y swapped (actually they are not in
the data provided by IIO).
Although it is triggered by some kernel change, the reliance on
g_dir_read_name() to get the correct order of channels is not correct.
We should look at the in_xxx_x_index field and calculate correct byte
offset in the iio buffer data.
For example with 4.8 kernel: from log with added index location printed
** (process:4945): DEBUG: Built channel array for in_accel_y: index: 1, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4945): DEBUG: Built channel array for in_accel_x: index: 0, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4945): DEBUG: Built channel array for in_accel_z: index: 2, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
(Here in_accel_y appeared before in_accel_x in g_dir_read_name(), because
of that channel array ordering is wrong hence location was
calculated wrong as below)
...
...
** (process:4945): DEBUG: process_scan_1: channel_index: 1, chan_name: in_accel_x, channel_data_index: 0 location: 4
** (process:4945): DEBUG: process_scan_1: channel_index: 0, chan_name: in_accel_y, channel_data_index: 1 location: 0
** (process:4945): DEBUG: process_scan_1: channel_index: 2, chan_name: in_accel_z, channel_data_index: 2 location: 8
** (process:4945): DEBUG: Read from IIO: -880449, 32851, -457812
To fix this we need to calculate the byte offset location using
channel_index not in the order they are returned by g_dir_read_name().
The easiest fix is to sort the array of channels in
build_channel_array() based on index. Also added some debug to print
index and location.
After the fix, the above log will change to:
** (process:4674): DEBUG: Built channel array for in_accel_x: index: 0, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4674): DEBUG: Built channel array for in_accel_y: index: 1, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4674): DEBUG: Built channel array for in_accel_z: index: 2, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
(Sorted above, so location of byte offset is correct)
** (process:4674): DEBUG: process_scan_1: channel_index: 0, chan_name: in_accel_x, channel_data_index: 0 location: 0
** (process:4674): DEBUG: process_scan_1: channel_index: 1, chan_name: in_accel_y, channel_data_index: 1 location: 4
** (process:4674): DEBUG: process_scan_1: channel_index: 2, chan_name: in_accel_z, channel_data_index: 2 location: 8
** (process:4674): DEBUG: Read from IIO: 34804, -878496, -448046
Closes: #99
* On the Cube i9 tablet, the accelerometer is declared as KIOX000A in
the ACPI DSDT table.
Also, it reports the opposite of "y" compared to what is expected.
* This has been tested on the Cube i9 with a patched kernel that fixes
the ACPI detection by the kxcj9 driver.
Signed-off-by: Christophe Chapuis <chris.chapuis@gmail.com>
40-* is too early to have some of the tags added to devices we want to
use. For example, input accelerometers wouldn't be tagged for
iio-sensor-proxy usage, as the tagging would be done in 50-*.
80 seems to be a good priority.
Closes#71
And stop polling when we receive an event from the kernel telling us
about coarse orientation changes.
In the future, we might want to whitelist those accelerometers that send
kevents, but it's probably just the pega_accel one that does it, and I
don't have such a machine anymore.
The _raw is not needed in the channel name for process_scan_1().
This function looks up the channel from its channel name (in this
case "in_rot_from_north_magnetic_tilt_comp").
The channel name is read from the file ending in _en from the
scanning_element folder, in build_channel_array().
Closes#38