Debian – Accelerometer and Screen Rotation on Non-Touchscreen Laptop

debianhard-diskjoysticksensors

I've recently got a non-touchscreen hp laptop with a hdd accelerometer. After upgrading it to Debian testing I noticed that whenever I tilt my laptop upwards past +45 deg, the screen rotates upside down. The opposite happens when I tilt my laptop -45 deg. To clarify, I am facing my laptop with the screen facing me with the keyboard parallel to the ground. The screen also rotates whenever I tilt my laptop clockwise or counterclockwise.

Is there a file where I can edit to change the screen's rotational direction?

The accelerometer in /proc/bus/input/devices shows this:

    I: Bus=0019 Vendor=0000 Product=0000 Version=0000
    N: Name="ST LIS3LV02DL Accelerometer"
    P: Phys=lis3lv02d/input0
    S: Sysfs=/devices/platform/lis3lv02d/input/input7
    U: Uniq=
    H: Handlers=event6 js0
    B: PROP=0
    B: EV=9
    B: ABS=7   

EDIT:

I found that watch -n 1 'cat /sys/devices/platform/lis3lv02d/position' is similar to what is found with the command below. Except it just displays coordinates such as (18,18,1098).

evtest /dev/input/event6 shows this:

    william@wksp0:~/Downloads$ sudo evtest /dev/input/event6
    Input driver version is 1.0.1
    Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
    Input device name: "ST LIS3LV02DL Accelerometer"
    Supported events:
      Event type 0 (EV_SYN)
      Event type 3 (EV_ABS)
        Event code 0 (ABS_X)
          Value     20
          Min    -2304
          Max     2304
          Fuzz      18
          Flat      18
        Event code 1 (ABS_Y)
          Value    -38
          Min    -2304
          Max     2304
          Fuzz      18
          Flat      18
        Event code 2 (ABS_Z)
          Value   1105
          Min    -2304
          Max     2304
          Fuzz      18
          Flat      18
    Properties:
    Testing ... (interrupt to exit)
    Event: time 1483747056.088195, type 3 (EV_ABS), code 1 (ABS_Y), value -23
    Event: time 1483747056.088195, -------------- SYN_REPORT ------------
    Event: time 1483747056.124189, type 3 (EV_ABS), code 0 (ABS_X), value 20
    Event: time 1483747056.124189, type 3 (EV_ABS), code 1 (ABS_Y), value -38
    Event: time 1483747056.124189, type 3 (EV_ABS), code 2 (ABS_Z), value 1105
    Event: time 1483747056.124189, -------------- SYN_REPORT ------------
    Event: time 1483747056.210931, type 3 (EV_ABS), code 0 (ABS_X), value -18
    Event: time 1483747056.210931, type 3 (EV_ABS), code 1 (ABS_Y), value -28
    Event: time 1483747056.210931, type 3 (EV_ABS), code 2 (ABS_Z), value 1107...

EDIT2:

After some googling, I've come across this which lead me to some interesting files that have little to no help on this. 😛

Best Answer

The whole story you mention is actually a kind of bug in iio-sensor-proxy or in your DE code who makes use of iio-sensor-proxy info.

Is not bios or kernel that does the rotation but the marriage between iio-sensor-proxy and your Desktop Environment.

DE like Gnome (and Cinnamon as turns out) does screen auto rotate based on the data provided by iio-sensor-proxy in dbus.

You can try to remove/purge iio-sensor-proxy and screen rotation will go away completely.

It is not clear if this is a iio-sensor-proxy bug or a Cinnamon bug. It could be iio-sensor-proxy that is reading in a wrong way your accelerometer data or could be Cinnamon who even if it receives correct data by sensor-proxy, rotates the screen wrongly.

You can clarify this issue by running monitor-sensor in root terminal. This utility comes with iio-sensor-proxy package and displays in terminal the current state of accelerometer / current screen orientation.
If orientation is correctly displayed by monitor-sensor then it is a Cinnamon bug. But i'm 90% sure that this is an iio-sensor-proxy bug and you should report it to the developer.

PS: It had been also mentioned that sensor-proxy had been working well with kernels up to version 4.7 but had some problems with kernel 4.8 and above. You could try to install an older kernel (i.e 4.7) for testing.

If monitor-sensor reports correctly the orientation and this is a Cinnamon bug, as a workaround you could disable Cinnamon auto screen rotation feature and run a kind of shell script that will make the correct rotation based on the data of monitor-sensor.

PS: Gnome gives the option to completely disable auto screen rotation, i'm not sure if Cinnamon has this option too.

In XFCE that iio-sensor-proxy is installed but XFCE devs are not performing auto screen rotation (yet) we apply this script to have auto screen rotation: https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu

PS: Improved version for touch screens with transformation matrix: https://github.com/gevasiliou/PythonTests/blob/master/autorotate.sh

Update for future reference / future "google searches"

As advised in comments, by running monitor-sensor in a root terminal and observing the messages provided by iio-sensor-proxy it proved that iio-sensor-proxy is correctly understood the real screen orientation.
As a result this seems to be a Cinnamon bug that though it gets correct info by iio-sensor-proxy is rotating the screen wrongly.

You can disable the Cinnamon auto rotation feature and try the auto-rotation script as advised above (https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu).

To disable Cinnamon internal autorotation you need to apply settings set org.cinnamon.settings-daemon.plugins.orientation active false as advised in OP's comment.

Related Question