-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrightness.c
More file actions
46 lines (37 loc) · 789 Bytes
/
brightness.c
File metadata and controls
46 lines (37 loc) · 789 Bytes
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
#include <stdio.h>
#include "config.h"
#include "idled.h"
int readBrightness(BRIGHTNESS_TYPE type) {
FILE* fp = NULL;
if (type == LCD) {
fp = fopen(BRIGHTNESS_FILE, "r");
} else if (type == KBD) {
fp = fopen(KBD_BRIGHTNESS_FILE, "r");
}
if (fp != NULL) {
int buffer[5] = { 0 };
int i;
for (i = 0; i < 5; i++) {
fscanf(fp, "%d", &buffer[i]);
}
fclose(fp);
return *buffer;
} else {
return -1;
}
}
int setBrightness(BRIGHTNESS_TYPE type, int brightness) {
FILE* fp = NULL;
if (type == LCD) {
fp = fopen(BRIGHTNESS_FILE, "w");
} else if (type == KBD) {
fp = fopen(KBD_BRIGHTNESS_FILE, "w");
}
if (fp != NULL) {
fprintf(fp, "%d", brightness);
fclose(fp);
return 0;
} else {
return -1;
}
}