forked from corcoran/chromebook_keyboard_backlight_driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard_brightness.c
61 lines (48 loc) · 1.01 KB
/
keyboard_brightness.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
#include <stdlib.h>
#include <stdio.h>
#define BRIGHTNESS "/sys/class/leds/chromeos::kbd_backlight/brightness"
#define INCREMENT 1.3
#define MAX 100
#define MIN 0
int main(int argc, char **argv) {
FILE *f;
int new;
char buf[32];
if(argc < 2) {
exit(-1);
}
if(!(f=fopen(BRIGHTNESS,"rt"))) {
fprintf(stderr,"Unable to open brightness file (read): %s\n", BRIGHTNESS);
exit(1);
}
fgets(buf,30,f);
fclose(f);
new = atoi(buf);
if(strcmp(argv[1],"up") == 0) {
// have to add one, otherwise 1 * 1.3 = 1, and we never move past that.
// (also 0 * 1.3 = 0, so we'd never get past there either.)
new = new * INCREMENT + 1;
}
if(strcmp(argv[1],"down") == 0) {
new /= INCREMENT;
}
if(strcmp(argv[1],"on") == 0) {
new=100;
}
if(strcmp(argv[1],"off") == 0) {
new=0;
}
if(new < 0) {
new = 0;
}
if(new > 100) {
new = 100;
}
if(!(f=fopen(BRIGHTNESS,"wt"))) {
fprintf(stderr,"Unable to open brightness file (write): %s\n", BRIGHTNESS);
exit(1);
}
fprintf(f,"%d\n",new);
fclose(f);
exit(0);
}