replace setpineled C program with a shell script
Signed-off-by: Stacy Harper <contact@stacyharper.net>
This commit is contained in:
parent
5ccfeacfac
commit
ce3f2ea319
6 changed files with 29 additions and 64 deletions
8
Makefile
8
Makefile
|
@ -3,7 +3,6 @@ PREFIX:=/usr
|
||||||
.PHONY: install shellcheck
|
.PHONY: install shellcheck
|
||||||
|
|
||||||
PROGRAMS = \
|
PROGRAMS = \
|
||||||
programs/sxmo_setpineled \
|
|
||||||
programs/sxmo_megiaudioroute \
|
programs/sxmo_megiaudioroute \
|
||||||
programs/sxmo_vibratepine
|
programs/sxmo_vibratepine
|
||||||
|
|
||||||
|
@ -14,9 +13,6 @@ test: shellcheck
|
||||||
shellcheck:
|
shellcheck:
|
||||||
shellcheck -x scripts/*/*
|
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
|
programs/sxmo_megiaudioroute: programs/sxmo_megiaudioroute.c
|
||||||
gcc -o 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
|
gcc -o programs/sxmo_vibratepine programs/sxmo_vibratepine.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f programs/sxmo_setpineled programs/sxmo_megiaudioroute programs/sxmo_vibratepine
|
rm -f programs/sxmo_megiaudioroute programs/sxmo_vibratepine
|
||||||
|
|
||||||
install: $(PROGRAMS)
|
install: $(PROGRAMS)
|
||||||
cd configs && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd ..
|
cd configs && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd ..
|
||||||
|
@ -52,8 +48,6 @@ install: $(PROGRAMS)
|
||||||
# Bin
|
# Bin
|
||||||
install -D -t $(DESTDIR)$(PREFIX)/bin scripts/*/*
|
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_megiaudioroute $(DESTDIR)$(PREFIX)/bin/
|
||||||
install -D programs/sxmo_vibratepine $(DESTDIR)$(PREFIX)/bin/
|
install -D programs/sxmo_vibratepine $(DESTDIR)$(PREFIX)/bin/
|
||||||
@echo "-------------------------------------------------------------------">&2
|
@echo "-------------------------------------------------------------------">&2
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
PIDS=""
|
PIDS=""
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
sxmo_setpineled "$i" 150 &
|
sxmo_setpineled.sh "$i" 150 &
|
||||||
PIDS="$PIDS $!"
|
PIDS="$PIDS $!"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$PIDS" | grep -E '[^ ]+' | xargs wait
|
echo "$PIDS" | grep -E '[^ ]+' | xargs wait
|
||||||
|
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
sxmo_setpineled "$i" 0
|
sxmo_setpineled.sh "$i" 0
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
sxmo_setpineled white "$(
|
sxmo_setpineled.sh white "$(
|
||||||
grep -qE '^0$' /sys/class/leds/white:flash/brightness &&
|
grep -qE '^0$' /sys/class/leds/white:flash/brightness &&
|
||||||
echo 255 || echo 0
|
echo 255 || echo 0
|
||||||
)"
|
)"
|
||||||
|
|
23
scripts/core/sxmo_setpineled.sh
Executable file
23
scripts/core/sxmo_setpineled.sh
Executable file
|
@ -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"
|
|
@ -43,10 +43,10 @@ recreateexistingnotifs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
syncled() {
|
syncled() {
|
||||||
sxmo_setpineled green 0
|
sxmo_setpineled.sh green 0
|
||||||
if [ "$(find "$NOTIFDIR"/ -type f | wc -l)" -gt 0 ]; then
|
if [ "$(find "$NOTIFDIR"/ -type f | wc -l)" -gt 0 ]; then
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
sxmo_setpineled green 1
|
sxmo_setpineled.sh green 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue