You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

5 years ago
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char * pbpScreen = "/sys/class/backlight/edp-backlight/brightness";
char * ppScreen = "/sys/devices/platform/backlight/backlight/backlight/brightness";
5 years ago
void usage() {
fprintf(stderr, "Usage: sxmo_setpinebacklight [number]\n");
}
void writeFile(char *filepath, int brightness) {
FILE *f;
f = fopen(filepath, "w+");
fprintf(f, "%d\n", brightness);
fclose(f);
5 years ago
}
int main(int argc, char *argv[]) {
char * command;
int brightness;
if (argc < 2) {
usage();
return 1;
}
argc--;
brightness = atoi(argv[argc--]);
if (setuid(0)) {
fprintf(stderr, "setuid(0) failed\n");
5 years ago
return 1;
}
if (access(pbpScreen, F_OK) != -1) {
writeFile(pbpScreen, brightness);
fprintf(stderr, "Set PBP brightness to %d\n", brightness);
} else if (access(ppScreen, F_OK) != -1) {
writeFile(ppScreen, brightness);
fprintf(stderr, "Set PP brightness to %d\n", brightness);
5 years ago
} else {
fprintf(stderr, "Neither PP or PBP Screen found!\n");
5 years ago
}
}