12 volatile bool active = true;
13 volatile bool goneActive = false;
14 volatile bool goneInactive = false;
16 void sigHandler(int sig)
31 void enableALS(bool enable) {
32 int fd = open("/proc/acpi/call", O_RDWR);
34 fprintf(stderr, "Error opening /proc/acpi/call");
39 buf = "\\_SB.PCI0.LPCB.EC0.TALS 0x1";
41 buf = "\\_SB.PCI0.LPCB.EC0.TALS 0x0";
44 write(fd, buf, strlen(buf) + 1);
49 void setScreenBacklight(int percent) {
51 snprintf(cmd, 100, "echo %d > /sys/class/backlight/acpi_video0/brightness", percent);
55 void setKeyboardBacklight(int percent) {
58 if(percent <= 25) value = 0;
59 else if(percent <= 50) value = 1;
60 else if(percent <= 75) value = 2;
61 else if(percent <= 100) value = 3;
64 snprintf(cmd, 150, "echo %d > /sys/class/leds/asus::kbd_backlight/brightness", value);
68 int getAmbientLightPercent() {
69 int fd = open("/proc/acpi/call", O_RDWR);
71 fprintf(stderr, "Error opening /proc/acpi/call");
75 buf = "\\\_SB.ALS._ALI";
77 write(fd, buf, strlen(buf) + 1);
80 int count = read(fd, strals, 100);
84 // 0x32 (min illuminance), 0xC8, 0x190, 0x258, 0x320 (max illuminance).
86 sscanf(strals,"%x",&als);
114 sa.sa_handler = sigHandler;
115 sigemptyset(&sa.sa_mask);
117 sigaction(SIGUSR1, &sa, NULL);
126 goneInactive = false;
129 if(!goneInactive && !goneActive)
138 float als = getAmbientLightPercent();
139 printf("%f\%\n", als);
141 setScreenBacklight(40);
142 setKeyboardBacklight(100);
143 } else if(als <= 25) {
144 setScreenBacklight(60);
145 setKeyboardBacklight(0);
146 } else if(als <= 50) {
147 setScreenBacklight(75);
148 setKeyboardBacklight(0);
149 } else if(als <= 75) {
150 setScreenBacklight(90);
151 setKeyboardBacklight(0);
152 } else if(als <= 100) {
153 setScreenBacklight(100);
154 setKeyboardBacklight(0);