17 février 2019

Manage Clevo N151ZU keyboard backlight

Backlight keyboard

I recently bought a new laptop from Obsidian-PC that offers computers based on Clevo barebones. My choice was the new N151ZU (same as the 150 but in aluminum finish). Even if it is a good machine, I encountered a little issue because the keyboard backlight is blue by default and Obsidian does not yet provide a Linux tool to modify it (whereas they provide a well known tool for Windows). After some researches, I came across this Tuxedo github repository that provides the sources for a kernel module for its laptops. It turns out that this code works very well on my laptop and I suppose that it should also work on any Clevo N150ZU or N151ZU based laptops. Obsidian has also confirmed me that they are working on a code similar to Tuxedo’s.

Install Tuxedo backlit kernel module from sources

The first step is to compile the kernel module provided by Tuxedo. As I use eOS (elementary), I chose to use DKMS to load the module. In the Tuxedo doc, this is explained in the paragraph The DKMS route.

Following are few lines of shell showing how to get the sources, compile and install the module. Be careful, I use sudo -i to not have to do sudo every line because I’m lazy.

git clone https://github.com/tuxedocomputers/tuxedo-keyboard.git
cd tuxedo-keyboard
make clean
sudo -i
cp -R . /usr/src/tuxedo_keyboard-1
dkms add -m tuxedo_keyboard -v 1
dkms install -m tuxedo_keyboard -v 1
echo tuxedo_keyboard >> /etc/modules

How to adjust backlight using keyboard keys

Thanks to the newly installed module, you can now use the four dedicated keys on the numeric keypad to adjust the backlight:

Backlight keyboard
Numpad keys managing backlight

They are /, *, – et + keys, combined withFn key.

« / » allows you to loop through the different backlight modes. Not very useful on everyday use, except to discover the available modes.

« * » allow you to switch on or off the backlight.

« – » et « + » allow you to lower or rise the brighness of backlight.

Change default color at startup

However, the default color is always blue. We will see for example how to switch to white (more elegant). The approach is the same for other colors, just adjust the hexadecimal values.

sudo -i
echo "options tuxedo_keyboard mode=0 brightness=255 state=1 color_left=0xffffff color_center=0xffffff color_right=0xffffff" > /etc/modprobe.d/tuxedo_keyboard.conf

To change this setting, simply edit the following file

sudo vim /etc/modprobe.d/tuxedo_keyboard.conf

« mode » allow you to choose the default mode. All modes are listed here. If you want to choose a fixed color, use the value 0. This is equivalent to « / » key.

« brightness » allows to set the backlight intensity (0 = off, 255 = max), this is equivalent to « + » et « – » keys.

« state » allow you to switch on or off the backlight, this is equivalent « * » key.

However, you’ll have to reboot the computer for the change to take effect, as settings are loaded by kernel module.

Keep settings when computer sleeps

There is still an issue as settings are not kept when computer sleeps and wake up, especially when it hibernates.Hopefully, there is a great guy who found a solution.

Just put this script in a file named tuxedo_keyboard in the systemd hibernation hooks directory (/ lib / systemd / system-sleep /), and make it executable:

#!/bin/sh
case $1 in
  (pre)
    for file in color_center color_left color_right color_extra mode brightness state;
    do
      filepath="/sys/devices/platform/tuxedo_keyboard/$file"
      if [ -e $filepath ]
      then
        case $file in
          (color_*)
            prefix="0x"
            ;;
          (*)
            prefix=""
            ;;
        esac
        echo "$file ${prefix}$(cat $filepath)" >> /tmp/tuxedo_keyboard_conf
      fi
    done
    ;;
  (post)
    if [ -e /tmp/tuxedo_keyboard_conf ];
    then
      awk '{ print $2 >("/sys/devices/platform/tuxedo_keyboard/" $1) }' /tmp/tuxedo_keyboard_conf
      rm /tmp/tuxedo_keyboard_conf
    fi
    ;;
esac

This script saves the keyboard state in /tmp/tuxedo_keyboard_conf when the computer goes to sleep and reloads the state at wake-up. This does not work for a reboot, but it works for all sleep modes (hibernation, standby, etc.).

Conclusion

We now have a basic but complete backlighting management of our Clevo N150/151ZU: manual management using the keypad keys, change of the default state and keep state during standby.

Ceci pourrait aussi vous intéresser...