Signed-off-by: Stacy Harper <contact@stacyharper.net>master
parent
5ccfeacfac
commit
ce3f2ea319
6 changed files with 29 additions and 64 deletions
@ -1,52 +0,0 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <unistd.h> |
||||
|
||||
void usage() { |
||||
fprintf(stderr, "Usage: setpineled [red|green|blue|white] [0-255]\n"); |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int brightness; |
||||
char * color; |
||||
char * command; |
||||
char * type; |
||||
|
||||
if (argc < 2) { |
||||
usage(); |
||||
return 1; |
||||
} |
||||
argc--; |
||||
brightness = atoi(argv[argc--]); |
||||
|
||||
if (brightness < 0 || brightness > 255) { |
||||
usage(); |
||||
return 1; |
||||
} |
||||
|
||||
color = argv[argc--]; |
||||
if ( |
||||
strcmp(color, "red") && |
||||
strcmp(color, "blue") && |
||||
strcmp(color, "green") && |
||||
strcmp(color, "white") |
||||
) { |
||||
usage(); |
||||
return 1; |
||||
} |
||||
|
||||
if (!strcmp(color, "white")) { |
||||
type = "flash"; |
||||
} else { |
||||
type = "indicator"; |
||||
} |
||||
|
||||
command = malloc(80); |
||||
sprintf( |
||||
command, |
||||
"sh -c 'echo %d > /sys/class/leds/%s:%s/brightness'", |
||||
brightness, color, type |
||||
); |
||||
return system(command); |
||||
} |
@ -0,0 +1,23 @@ |
||||
#!/bin/sh |
||||
|
||||
usage () { |
||||
printf "usage: %s [red|green|blue|white] [0-255]\n" "$0" |
||||
exit 1 |
||||
} |
||||
|
||||
[ $# -lt 2 ] && usage |
||||
|
||||
case $1 in |
||||
red|green|blue) color="$1"; type="indicator" ;; |
||||
white) color="$1"; type="flash" ;; |
||||
*) usage ;; |
||||
esac |
||||
|
||||
if [ "$2" -lt 0 ] || [ "$2" -gt 255 ] |
||||
then |
||||
usage |
||||
fi |
||||
|
||||
brightness="$2" |
||||
|
||||
printf "%s\n" "$brightness" > "/sys/class/leds/$color:$type/brightness" |
Loading…
Reference in new issue