|
|
@ -4,13 +4,14 @@ |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
|
|
|
|
void usage() { |
|
|
|
void usage() { |
|
|
|
fprintf(stderr, "Usage: setpineled [red|green|blue] [0-255]\n"); |
|
|
|
fprintf(stderr, "Usage: setpineled [red|green|blue|white] [0-255]\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
int brightness; |
|
|
|
int brightness; |
|
|
|
char * color; |
|
|
|
char * color; |
|
|
|
char * command; |
|
|
|
char * command; |
|
|
|
|
|
|
|
char * type; |
|
|
|
|
|
|
|
|
|
|
|
if (argc < 2) { |
|
|
|
if (argc < 2) { |
|
|
|
usage(); |
|
|
|
usage(); |
|
|
@ -25,17 +26,27 @@ int main(int argc, char *argv[]) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
color = argv[argc--]; |
|
|
|
color = argv[argc--]; |
|
|
|
if (strcmp(color, "red") && strcmp(color, "blue") && strcmp(color, "green")) { |
|
|
|
if ( |
|
|
|
|
|
|
|
strcmp(color, "red") &&
|
|
|
|
|
|
|
|
strcmp(color, "blue") &&
|
|
|
|
|
|
|
|
strcmp(color, "green") && |
|
|
|
|
|
|
|
strcmp(color, "white") |
|
|
|
|
|
|
|
) { |
|
|
|
usage(); |
|
|
|
usage(); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(color, "white")) { |
|
|
|
|
|
|
|
type = "flash"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
type = "indicator"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
command = malloc(80); |
|
|
|
command = malloc(80); |
|
|
|
sprintf( |
|
|
|
sprintf( |
|
|
|
command, |
|
|
|
command, |
|
|
|
"sh -c 'echo %d > /sys/devices/platform/leds/leds/pinephone:%s:user/brightness'", |
|
|
|
"sh -c 'echo %d > /sys/class/leds/%s:%s/brightness'", |
|
|
|
brightness, |
|
|
|
brightness, color, type |
|
|
|
color |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
if (setuid(0)) { |
|
|
|
if (setuid(0)) { |
|
|
|
fprintf(stderr, "setuid(0) failed\n"); |
|
|
|
fprintf(stderr, "setuid(0) failed\n"); |
|
|
|