8 #include <linux/input.h>
10 static void screenlight(int up)
12 static const char *path = "/sys/class/backlight/gmux_backlight/brightness";
13 static int prev, next, tmp;
17 // Open brightness file
19 fd = fopen(path, "r+");
21 printf("error opening file\n");
25 // Reset if someone else changed the value
26 fseek(fd, 0, SEEK_SET);
27 fscanf(fd, "%d", &tmp);
29 val = pow(tmp/1024.0, 1/10.0);
31 // printf("convert: %d -> %d -> %f\n",
34 // Update the current value
35 val += 0.01 * (up?1:-1);
39 // Write it back to the file
40 next = pow(val, 10) * 1024;
46 //printf("saving: %d\n", next);
47 fprintf(fd, "%d", next);
51 static void keylight(int up)
53 //static const char *path = "/sys/class/leds/smc::kbd_backlight/brightness";
56 int main(int argc, char **argv)
58 struct input_event ev;
61 //if ((fd = open("/dev/input/event4", O_RDONLY)) < 0) {
62 //if ((fd = open("/dev/input/event6", O_RDONLY)) < 0) {
63 if ((fd = open("/dev/input/event10", O_RDONLY)) < 0) {
68 while ((len = read(fd, &ev, sizeof(ev)))) {
69 if (len != sizeof(ev)) {
76 printf("%ld.%06lu: type=%04hx code=%04hx val=%08x\n",
79 ev.type, ev.code, ev.value);
83 if (ev.type != EV_KEY)
85 if (ev.value == 0) // key up
89 case KEY_BRIGHTNESSDOWN:
92 case KEY_BRIGHTNESSUP:
95 case KEY_KBDILLUMDOWN: