Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Hack to control the keyboard backlight level on a Thinkpad Lenovo X1 Carbon Touch

View tmp.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
 
/* gcc -o tmp `pkg-config --libs --cflags glib-2.0` tmp.c
*
* # modprobe ec_sys
*
* # watch -n 0.1 hexdump -C /sys/kernel/debug/ec/ec0/io
*
* 00000000 a7 05 a0 e2 00 86 05 00 00 00 47 00 00 03 00 10 |..........G.....|
* 00000000 a7 05 a0 e2 00 86 05 00 00 00 47 00 00 43 00 10 |..........G..C..|
* 00000000 a7 05 a0 e2 00 86 05 00 00 00 47 00 00 83 00 10 |..........G.....|
*
* # ./tmp 0
* # ./tmp 1
* # ./tmp 2
*
*/
 
#include <glib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
 
char levels[] = {
0x03,
0x43,
0x83
};
 
static void
usage (char **argv)
{
g_print ("%s [level]\n", argv[0]);
g_print ("Where level is between 1 and 3\n");
}
 
int main (int argc, char **argv)
{
int fd;
int level;
 
if (argc < 2) {
usage (argv);
return 1;
}
level = atoi(argv[1]);
if (level < 0 || level > 3) {
usage (argv);
return 1;
}
 
fd = open ("/sys/kernel/debug/ec/ec0/io", O_RDWR);
if (fd < 0) {
g_print ("open: %s\n", g_strerror (errno));
return 1;
}
if (lseek (fd, 0xd, SEEK_CUR) < 0) {
g_print ("seek: %s\n", g_strerror (errno));
return 1;
}
if (write (fd, &levels[level], 1) < 0) {
g_print ("write: %s\n", g_strerror (errno));
return 1;
}
 
return 0;
}

Thank you for this great gist, as it solved our needed issue. I posted an answer based on this gist:

http://askubuntu.com/questions/383501/enable-the-keyboard-backlights-on-supported-lenovo-e-g-carbon-x1-with-command/

Any chance this will work for the 2014 none touch version?

Thanks! Confirmed this works on a Fedora 20 system, compiled with:

$ gcc -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include thinklight.c -o ThinkLight -lglib-2.0

Dude, nice one. 1 coffee @changetip

is this code gonna work on Toshiba U945, or do I need change this code for getting my keyboard backling works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.