diff --git a/Makefile b/Makefile index 0fde409..3c07fa4 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ PREFIX:=/usr .PHONY: install shellcheck PROGRAMS = \ - programs/sxmo_setpineled \ programs/sxmo_megiaudioroute \ programs/sxmo_vibratepine @@ -14,9 +13,6 @@ test: shellcheck shellcheck: shellcheck -x scripts/*/* -programs/sxmo_setpineled: programs/sxmo_setpineled.c - gcc -o programs/sxmo_setpineled programs/sxmo_setpineled.c - programs/sxmo_megiaudioroute: programs/sxmo_megiaudioroute.c gcc -o programs/sxmo_megiaudioroute programs/sxmo_megiaudioroute.c @@ -24,7 +20,7 @@ programs/sxmo_vibratepine: programs/sxmo_vibratepine.c gcc -o programs/sxmo_vibratepine programs/sxmo_vibratepine.c clean: - rm -f programs/sxmo_setpineled programs/sxmo_megiaudioroute programs/sxmo_vibratepine + rm -f programs/sxmo_megiaudioroute programs/sxmo_vibratepine install: $(PROGRAMS) cd configs && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd .. @@ -52,8 +48,6 @@ install: $(PROGRAMS) # Bin install -D -t $(DESTDIR)$(PREFIX)/bin scripts/*/* - install -D -m 0755 programs/sxmo_setpineled $(DESTDIR)$(PREFIX)/bin/ - install -D programs/sxmo_megiaudioroute $(DESTDIR)$(PREFIX)/bin/ install -D programs/sxmo_vibratepine $(DESTDIR)$(PREFIX)/bin/ @echo "-------------------------------------------------------------------">&2 diff --git a/programs/sxmo_setpineled.c b/programs/sxmo_setpineled.c deleted file mode 100644 index b86bd54..0000000 --- a/programs/sxmo_setpineled.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include - -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); -} diff --git a/scripts/core/sxmo_blinkled.sh b/scripts/core/sxmo_blinkled.sh index 2a0e556..36cee37 100755 --- a/scripts/core/sxmo_blinkled.sh +++ b/scripts/core/sxmo_blinkled.sh @@ -6,12 +6,12 @@ PIDS="" for i in "$@"; do - sxmo_setpineled "$i" 150 & + sxmo_setpineled.sh "$i" 150 & PIDS="$PIDS $!" done echo "$PIDS" | grep -E '[^ ]+' | xargs wait for i in "$@"; do - sxmo_setpineled "$i" 0 + sxmo_setpineled.sh "$i" 0 done diff --git a/scripts/core/sxmo_flashtoggle.sh b/scripts/core/sxmo_flashtoggle.sh index 2c26f39..101922b 100755 --- a/scripts/core/sxmo_flashtoggle.sh +++ b/scripts/core/sxmo_flashtoggle.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh -sxmo_setpineled white "$( +sxmo_setpineled.sh white "$( grep -qE '^0$' /sys/class/leds/white:flash/brightness && echo 255 || echo 0 )" diff --git a/scripts/core/sxmo_setpineled.sh b/scripts/core/sxmo_setpineled.sh new file mode 100755 index 0000000..70729c0 --- /dev/null +++ b/scripts/core/sxmo_setpineled.sh @@ -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" diff --git a/scripts/notifications/sxmo_notificationmonitor.sh b/scripts/notifications/sxmo_notificationmonitor.sh index 96be1f7..4e3ff54 100755 --- a/scripts/notifications/sxmo_notificationmonitor.sh +++ b/scripts/notifications/sxmo_notificationmonitor.sh @@ -43,10 +43,10 @@ recreateexistingnotifs() { } syncled() { - sxmo_setpineled green 0 + sxmo_setpineled.sh green 0 if [ "$(find "$NOTIFDIR"/ -type f | wc -l)" -gt 0 ]; then sleep 0.1 - sxmo_setpineled green 1 + sxmo_setpineled.sh green 1 fi }