replace setpineled C program with a shell script

Signed-off-by: Stacy Harper <contact@stacyharper.net>
master
Nihal Jere 3 years ago committed by Stacy Harper
parent 5ccfeacfac
commit ce3f2ea319
No known key found for this signature in database
GPG Key ID: 5BAC92328B7C5D65
  1. 8
      Makefile
  2. 52
      programs/sxmo_setpineled.c
  3. 4
      scripts/core/sxmo_blinkled.sh
  4. 2
      scripts/core/sxmo_flashtoggle.sh
  5. 23
      scripts/core/sxmo_setpineled.sh
  6. 4
      scripts/notifications/sxmo_notificationmonitor.sh

@ -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

@ -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=""
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

@ -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
)"

@ -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() {
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
}

Loading…
Cancel
Save