/bma250-screen-autorotator

Automatic screen rotator based on BMA250 accelerometer

Primary LanguageCGNU General Public License v3.0GPL-3.0

Screen autorotator based on BMA250 Bosch accelerometer License: GPL v3

This script is designed to poll BMA250 accelerometer for position info. Depending of this data, screen will be rotated using xrandr.

It also supports rotating a pointing device, like for example, a touchscreen.

I hope this application will be useful to provide a more complete experience in some chinese tablets based in Intel microprocessors when running Linux.

This program was developed for and tested in a Chuwi Hi 10 Pro, running Lubuntu 17.10 with 4.13.0-25 kernel installed. A guide to run Linux in this device can be found here.

Compilation and installation

First of all dependencies must be installed:

sudo apt-get install libxrandr-dev libxi-dev i2c-tools

Then, it can be compiled and installed as normal:

autoreconf -vfi
./configure
make
sudo make install

Executing the aplication will need root permissions, because it needs to read from /dev/i2c-* file.

Special configurations

In the case of Chiwi Hi10 Pro, BMA250 accelerometer is located in the bus /dev/i2c-2 listening in address 0x18. In order to make easier the use of this software in other devices, you can configure some parameters by defining macros at compilation time:

    ./configure CFLAGS='-D<macro>=<value>'
  • BMA250_I2C_BUS: This macro defines which /dev/i2c-%d file will be open. Default value es 2.
  • BMA250_I2C_ADDR: This macro defines which address is assigned to the device inside i2c bus. By default, 0x18 address is set.
  • POLLING_USECS: Waiting time (in usecs) between accelerometer data reads. Default value is set to 500 * 1000.
  • XDEVICE: This is the ID of the pointing device to rotate. It can be obtained from xinput by executing xinput list. By default this macro is not defined, if so, no pointing device will be rotated.

For example, in the case of the Chuwi Hi10 Pro, this macro needs to be set to 11 according to xinput output: Xinput list output

./configure CFLAGS="-DXDEVICE=11"
  • DEBUG: Defining this macro produces some useful debug information in stdout.

Installation in LXDE (Lubuntu)

In order to launch autorrotator on startup, it can be included in /etc/lightdm/lightdm.conf.d/80-display-setup.conf:

[SeatDefaults]
display-setup-script=autorotator_bg.sh

autorotator_bg.sh is only a bash script that executes autorotator in the background to let lightdm complete display initialization when called as display setup script. You can copy it in /usr/local/bin. Do not forget to set it as executable with chmod +x:

#!/bin/bash
autorotator &

In some cases, LXDE DPI settings go crazy, and tipography renders really small. You can edit .Xresources in you home directory to override DPI settings:

Xft.dpi: 140

References

I have written a complete guide for running Lubuntu in the Chuwi Hi10 Pro, it can be found here.

If you are interested in more info about running Linux (Arch Linux) in a Chiwi Hi10 Pro, you can get more information on Daniel Otero's repository:

https://github.com/danielotero/linux-on-hi10

If you want to use BMA250, this guys have very good examples and more information:

https://github.com/ControlEverythingCommunity/BMA250

I have to thank user falconer in askUbuntu for information about how to run this script at lightdm startup:

https://askubuntu.com/questions/408302/rotated-monitor-login-screen-needs-rotation

I also have to thank Mitch Lindgren by his post on how to set LXDE DPI settings:

http://blog.mlindgren.ca/entry/2015/02/21/configuring-dpi-in-lubuntu-slash-lxde/

About

Copyright (c) 2018 Guillermo Climent, https://github.com/willyneutron

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 3 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.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.