Improving support for accelerometers in iio-sensor-proxy ======================================================== The Fedora project is a community project creating a free Linux distribution called Fedora. The Fedora project is sponsored by Red Hat, also see: https://fedoraproject.org/wiki/Overview https://fedoraproject.org/wiki/Foundations In 2017 Red Hat has formed a team to improve the user experience for RHEL and Fedora workstation laptop users: https://blogs.gnome.org/uraeus/2016/08/12/want-make-linux-run-better-on-laptops/ Various laptop models come with accelerometers. These are mostly found in so called 2-in-1 models. These serve 2 purposes: 1. Automatic rotation of the screen when a 2-in-1 is in tablet mode, or when the device is a tablet. 2. For 2-in-1s using 360° (aka yoga) hinges there are sometimes 2 accelerometers, which allow detecting the angle between the base and display parts of the laptops. This is used to detect if the 2-in-1 is being used as a regular laptop or as a tablet. Under Linux (Fedora, Ubuntu, Endless, etc.) the accelerometers are handled by the iio-sensor-proxy project: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/ Your assignment is to develop 2 enhancement to iio-sensor-proxy: 1. An accelerometer measures G-forces in 3 axis x, y and z. If the accelerometer IC is soldered on the PCB in the right orientation then the 3 axis match the x, y and z axis of the tablet and everything will "just work" but in many cases the 2 orientations do not match. This is corrected by a so called mount-matrix, e.g.: ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1 Currently the mount-matrix line needed for a specific model needs to be manually written. The first enhancement is to write a GUI tool which helps the user generate a mount-matrix for there device. Requirements: - The GUI tool must: - Be easy / intuitive to use - Show a 3D rendering of the device, with a graphical representation of the downwards 1G vector (aka the gravity) working on the device, after applying the currently configured mount-matrix - Allow the user to change the mount-matrix while showing the 3d render - Be able to work on devices with both 1 and 2 accelerometers - Be able to generate a udev hwdb entry to correct the accelerometer orientation - Be released under the GNU General Public License version 3 - Be written in either C or Python (your choice) - Use the GTK3 or GTK4 toolkit - Not use (depend on) any exotic libraries, when in doubt ask Tip: a possible interesting library to use is GThree: https://github.com/alexlarsson/gthree https://blogs.gnome.org/alexl/2014/10/24/introducing-gthree/ https://blogs.gnome.org/alexl/2019/06/05/gthree-is-alive/ - Be integrated into the existing iio-sensor-proxy project as a bundled tool - Be submitted for upstream review and inclusion using a merge-request at the iio-sensor-proxy project gitlab project - The GUI tool should: - Have a wizard mode, which goes something like this: 1. lay the tablet on a flat surface with the display up and then press ok. 2. Hold the tablet in front of you with the display oriented normally, then press ok. 3. Hold the tablet in front of you with the display oriented upside-down). Each step should be accompanied by a picture showing the user what is expected of them. After the wizard, the code should automatically generate the right matrix, based on the measurements taken during each step. - Be able to instantly apply the configured mount-matrix to the running iio-sensor-proxy process, so that the user can test e.g. display-autorotation with the new mount-matrix 2. On 2-in-1s the UI (gnome-shell on Fedora Workstation) adapts itself to some degree based on if the 2-in-1 is in laptop or tablet mode. Some 2-in-1s using 360° (aka yoga) hinges do not have any firmware-interfaces directly reporting their laptop vs tablet mode state. Instead these have 2 accelerometers 1 in the base and 1 in the display part of the 2-in-1. This allows calculating the angle between the 2 halves, which in turn can be used to determine if the 2-in-1 is being used in laptop or tablet mode. Currently iio-sensor-proxy ignores the accelerometer in the base of the device. The second enhancement is to extend iio-sensor-proxy to use both accelerometers and to determine and advertise if the device is in laptop or tablet mode based on the accelerometer readings. Note the iio-sensor-proxy sensor abstraction layer has has already been refactored to be proper object-oriented code so that there can be multiple instances of a single sensor-type. The main event loop still expects there to only be one sensor of each type and will need some work for this. The formula for the calculation of the angle from the two 3d (x,y,z) vectors returned by the accelerometers will be provided, including some (ruby) example code. Requirements: - The new io-sensor-proxy functionality must: - Be able to reliable determine if a 360° hinges style 2-in-1 is in laptop or tablet mode - Report if the device is in laptop or tablet mode by registering an uinput device reporting SW_TABLET_MODE events, so that consumers of this information can use the same API as they are already using on devices where the firmware directly reports the mode - Be released under the GNU General Public License version 3 - Be written in C (as all the existing iio-sensor-proxy code is) - Not introduce any new library dependencies to iio-sensor-proxy - Be submitted for upstream review and inclusion using a merge-request at the iio-sensor-proxy project gitlab project - The new io-sensor-proxy functionality should: - The code determining if the device is in laptop or tablet mode and then advertising this through a uinput_device reporting SW_TABLET_MODE events should be separate from the code reading the 2 accelerometers and determining the angle between the 2 halves. - This separate module / class should consume events which contain 2 angles: 1. the angle between the halves 2. the angle between the bottom of the base and the ground/horizon. - The reason for this requirement is that some new 2-in-1s do not offer direct access to 2 accelerometers. Instead these models have a new firmware interface which reports this 2 angles: https://www.phoronix.com/scan.php?page=news_item&px=Intel-Hinge-Driver-Linux-5.12 Splitting the functionality as described here, will make it easier to support these new models in the future. Also see: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/issues/216 https://www.wikihow.com/Find-the-Angle-Between-Two-Vectors https://github.com/alesguzik/linux_detect_tablet_mode/blob/master/old/detect_tablet_mode Note the above requirements-lists for both enhancements are meant as a starting point for determining the requirements and are not necessarily complete.