From 22d974f22f0721f69aebcb9570897908af2b5a0a Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Mon, 4 May 2020 19:27:22 -0500 Subject: [PATCH] Cleanup calling - mostly working; misc cleanup scripts; add vibrate program --- Makefile | 9 +- programs/sxmo_megiaudioroute.c | 2 +- programs/sxmo_pdudecode.c | 26 ----- programs/sxmo_setpinebacklight.c | 32 +++-- programs/sxmo_vibratepine.c | 110 ++++++++++++++++++ scripts/core/sxmo_appmenu.sh | 141 +++++++++++++---------- scripts/core/sxmo_brightness.sh | 14 ++- scripts/core/sxmo_pastecomplete.sh | 23 ---- scripts/core/sxmo_pipecomplete.sh | 39 +++++++ scripts/core/sxmo_statusbar.sh | 13 ++- scripts/core/sxmo_vol.sh | 31 ++--- scripts/core/sxmo_xinit.sh | 2 +- scripts/modem/sxmo_modemcall.sh | 47 +++++--- scripts/modem/sxmo_modeminfo.sh | 7 ++ scripts/modem/sxmo_modemmonitor.sh | 27 +++-- scripts/modem/sxmo_modemmonitortoggle.sh | 8 ++ scripts/modem/sxmo_modemsendtext.sh | 13 ++- 17 files changed, 367 insertions(+), 177 deletions(-) delete mode 100644 programs/sxmo_pdudecode.c create mode 100644 programs/sxmo_vibratepine.c delete mode 100755 scripts/core/sxmo_pastecomplete.sh create mode 100755 scripts/core/sxmo_pipecomplete.sh create mode 100755 scripts/modem/sxmo_modeminfo.sh create mode 100755 scripts/modem/sxmo_modemmonitortoggle.sh diff --git a/Makefile b/Makefile index 30bc345..6f4dbeb 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,11 @@ programs/sxmo_screenlock: programs/sxmo_megiaudioroute: gcc -o programs/sxmo_megiaudioroute programs/sxmo_megiaudioroute.c -programs/sxmo_pdudecode: - gcc -o programs/sxmo_pdudecode programs/sxmo_pdudecode.c -I/usr/include/gammu -lGammu -lm +programs/sxmo_vibratepine: + gcc -o programs/sxmo_vibratepine programs/sxmo_vibratepine.c -install: programs/sxmo_setpineled programs/sxmo_setpinebacklight programs/sxmo_screenlock programs/sxmo_megiaudioroute programs/sxmo_pdudecode + +install: programs/sxmo_setpineled programs/sxmo_setpinebacklight programs/sxmo_screenlock programs/sxmo_megiaudioroute programs/sxmo_vibratepine mkdir -p $(PREFIX)/usr/share/sxmo cp configs/* $(PREFIX)/usr/share/sxmo @@ -38,4 +39,4 @@ install: programs/sxmo_setpineled programs/sxmo_setpinebacklight programs/sxmo_s cp programs/sxmo_screenlock $(PREFIX)/usr/bin cp programs/sxmo_megiaudioroute $(PREFIX)/usr/bin - cp programs/sxmo_pdudecode $(PREFIX)/usr/bin + cp programs/sxmo_vibratepine $(PREFIX)/usr/bin diff --git a/programs/sxmo_megiaudioroute.c b/programs/sxmo_megiaudioroute.c index 8bfcffe..ac49eac 100644 --- a/programs/sxmo_megiaudioroute.c +++ b/programs/sxmo_megiaudioroute.c @@ -380,7 +380,7 @@ int main(int ac, char* av[]) audio_setup.dai2_en = 1; break; default: /* '?' */ - fprintf(stderr, "Usage: %s [-s] [-m] [-h] [-e] [-2]\n", av[0]); + fprintf(stderr, "Usage: %s [-s] [-m] [-h] [-e] [-2] [-z]\n", av[0]); exit(EXIT_FAILURE); } } diff --git a/programs/sxmo_pdudecode.c b/programs/sxmo_pdudecode.c deleted file mode 100644 index 54bb42b..0000000 --- a/programs/sxmo_pdudecode.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include - -int main(int argc, char **argv) { - GSM_SMSMessage m; - GSM_Error err; - int i; - char timestamp[50]; - char * hexstring; - - hexstring = malloc(strlen(argv[1]) / 2); - for (i = 0; i < strlen(argv[1]) / 2; i++) { - sscanf(argv[1] + i*2, "%2hhx", &hexstring[i]); - } - err = GSM_DecodePDUFrame(NULL, &m, hexstring, strlen(argv[1]) / 2, NULL, 1); - if (err != ERR_NONE) { - fprintf(stderr, "Failure to parse string: %s\n", GSM_ErrorString(err)); - } - GSM_DateTimeToTimestamp(&m.DateTime, timestamp); - - printf("Date: %s\n", timestamp); - printf("Number: %s\n", DecodeUnicodeConsole(m.Number)); - printf("Message:\n%s\n", DecodeUnicodeConsole(m.Text)); -} diff --git a/programs/sxmo_setpinebacklight.c b/programs/sxmo_setpinebacklight.c index 703fe58..6f14c01 100644 --- a/programs/sxmo_setpinebacklight.c +++ b/programs/sxmo_setpinebacklight.c @@ -3,8 +3,18 @@ #include #include +char * pbpScreen = "/sys/class/backlight/edp-backlight/brightness"; +char * ppScreen = "/sys/devices/platform/backlight/backlight/backlight/brightness"; + void usage() { - fprintf(stderr, "Usage: setpinebacklight [0-10]\n"); + fprintf(stderr, "Usage: sxmo_setpinebacklight [number]\n"); +} + +void writeFile(char *filepath, int brightness) { + FILE *f; + f = fopen(filepath, "w+"); + fprintf(f, "%d\n", brightness); + fclose(f); } int main(int argc, char *argv[]) { @@ -18,20 +28,18 @@ int main(int argc, char *argv[]) { argc--; brightness = atoi(argv[argc--]); - if (brightness < 0 || brightness > 10) { - usage(); + if (setuid(0)) { + fprintf(stderr, "setuid(0) failed\n"); return 1; } - command = malloc(100); - sprintf( - command, - "sh -c 'echo %d > /sys/devices/platform/backlight/backlight/backlight/brightness'", - brightness - ); - if (setuid(0)) { - fprintf(stderr, "setuid(0) failed\n"); + if (access(pbpScreen, F_OK) != -1) { + writeFile(pbpScreen, brightness); + fprintf(stderr, "Set PBP brightness to %d\n", brightness); + } else if (access(ppScreen, F_OK) != -1) { + writeFile(ppScreen, brightness); + fprintf(stderr, "Set PP brightness to %d\n", brightness); } else { - return system(command); + fprintf(stderr, "Neither PP or PBP Screen found!\n"); } } diff --git a/programs/sxmo_vibratepine.c b/programs/sxmo_vibratepine.c new file mode 100644 index 0000000..0d194fd --- /dev/null +++ b/programs/sxmo_vibratepine.c @@ -0,0 +1,110 @@ +/* Based on: https://xnux.eu/devices/feature/vibrator.html#toc-example-program-to-control-the-vibration-motor */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void syscall_error(int is_err, const char* fmt, ...) +{ + va_list ap; + + if (!is_err) + return; + + printf("ERROR: "); + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + printf(": %s\n", strerror(errno)); + + exit(1); +} + +int open_event_dev(const char* name_needle, int flags) +{ + char path[256]; + char name[256]; + int fd, ret; + + // find the right device and open it + for (int i = 0; i < 10; i++) { + snprintf(path, sizeof path, "/dev/input/event%d", i); + fd = open(path, flags); + if (fd < 0) + continue; + + ret = ioctl(fd, EVIOCGNAME(256), name); + if (ret < 0) + continue; + + if (strstr(name, name_needle)) + return fd; + + close(fd); + } + + errno = ENOENT; + return -1; +} + +void usage() { + fprintf(stderr, "Usage: sxmo_vibratepine duration_ms\n"); + fprintf(stderr, " sxmo_vibratepine duration_ms strength_number\n"); +} + +int main(int argc, char* argv[]) +{ + int fd, ret; + struct pollfd pfds[1]; + int effects; + + int durationMs, strength; + + if (argc < 1) { + usage(); + return 1; + } + argc--; + + if (argc > 1) { + strength = atoi(argv[argc--]); + } else { + strength = 4000; + } + + durationMs = atoi(argv[argc--]); + + fd = open_event_dev("vibrator", O_RDWR | O_CLOEXEC); + syscall_error(fd < 0, "Can't open vibrator event device"); + ret = ioctl(fd, EVIOCGEFFECTS, &effects); + syscall_error(ret < 0, "EVIOCGEFFECTS failed"); + + struct ff_effect e = { + .type = FF_RUMBLE, + .id = -1, + .u.rumble = { .strong_magnitude = strength }, + }; + + ret = ioctl(fd, EVIOCSFF, &e); + syscall_error(ret < 0, "EVIOCSFF failed"); + + struct input_event play = { .type = EV_FF, .code = e.id, .value = 3 }; + ret = write(fd, &play, sizeof play); + syscall_error(ret < 0, "write failed"); + + usleep(durationMs * 1000); + + ret = ioctl(fd, EVIOCRMFF, e.id); + syscall_error(ret < 0, "EVIOCRMFF failed"); + + close(fd); + return 0; +} diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 1eafab9..4a201ad 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -1,30 +1,24 @@ #!/usr/bin/env sh WIN=$(xdotool getwindowfocus) -INCOMINGCALL=$(cat /tmp/sxmo_incomingcall || echo NOCALL) programchoicesinit() { WMCLASS="${1:-$(xprop -id $(xdotool getactivewindow) | grep WM_CLASS | cut -d ' ' -f3-)}" - # Default + # Default system menu (no matches) CHOICES="$(echo " Scripts ^ 0 ^ sxmo_appmenu.sh scripts Apps ^ 0 ^ sxmo_appmenu.sh applications - Volume ↑ ^ 1 ^ sxmo_vol.sh up - Volume ↓ ^ 1 ^ sxmo_vol.sh down - Dialer ^ 1 ^ sxmo_phonecaller.exp dial + Volume ↑ ^ 1 ^ sxmo_vol.sh up + Volume ↓ ^ 1 ^ sxmo_vol.sh down + Dialer ^ 1 ^ sxmo_modemcall.sh dial Texts ^ 0 ^ sxmo_readtexts.sh Camera ^ 0 ^ sxmo_camera.sh Wifi ^ 0 ^ st -e "nmtui" System Config ^ 0 ^ sxmo_appmenu.sh control Logout ^ 0 ^ pkill -9 dwm - Close Menu ^ 0 ^ quit ")" && WINNAME=Sys - # E.g. for the system menu if there's an incoming call pop it on top of menu - echo "$INCOMINGCALL" | grep -v NOCALL && CHOICES="$(echo " - Pickup $INCOMINGCALL ^ 0 ^ sxmo_phonecaller.exp pickup $INCOMINGCALL - ")""$CHOICES" - + # Apps menu echo $WMCLASS | grep -i "applications" && CHOICES="$(echo " Surf ^ 0 ^ surf NetSurf ^ 0 ^ netsurf @@ -33,30 +27,31 @@ programchoicesinit() { St ^ 0 ^ st Firefox ^ 0 ^ firefox Foxtrotgps ^ 0 ^ foxtrotgps - Close Menu ^ 0 ^ quit - ")" && WINNAME=Apps + ")" && WINNAME=Apps && return + # Scripts menu echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo " Timer ^ 0 ^ sxmo_timermenu.sh Youtube ^ 0 ^ sxmo_youtube.sh Youtube (Audio) ^ 0 ^ sxmo_youtube.sh --no-video Weather ^ 0 ^ sxmo_weather.sh RSS ^ 0 ^ sxmo_rss.sh - Close Menu ^ 0 ^ quit - ")" && WINNAME=Scripts + ")" && WINNAME=Scripts && return + # System Control menu echo $WMCLASS | grep -i "control" && CHOICES="$(echo " - Volume ↑ ^ 1 ^ sxmo_vol.sh up - Volume ↓ ^ 1 ^ sxmo_vol.sh down - Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up - Brightness ↓ ^ 1 ^ sxmo_brightness.sh down - Modem Info ^ 1 ^ st -e 'mmcli -m 0 && read' - Rotate ^ 1 ^ rotate - Wifi ^ 0 ^ st -e "nmtui" - Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh - Close Menu ^ 0 ^ quit - ")" && WINNAME=Control - + Volume ↑ ^ 1 ^ sxmo_vol.sh up + Volume ↓ ^ 1 ^ sxmo_vol.sh down + Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up + Brightness ↓ ^ 1 ^ sxmo_brightness.sh down + Modem $(pgrep -f sxmo_modemmonitor.sh >/dev/null && echo -n "On → Off" || echo -n "Off → On") ^ 1 ^ sxmo_modemmonitortoggle.sh + Modem Info ^ 1 ^ sxmo_modeminfo.sh + Rotate ^ 1 ^ rotate + Wifi ^ 0 ^ st -e "nmtui" + Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh + ")" && WINNAME=Control && return + + # MPV echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo " Pause ^ 0 ^ key space Seek ← ^ 1 ^ key Left @@ -69,30 +64,27 @@ programchoicesinit() { Loopmark ^ 1 ^ key l Info ^ 1 ^ key i Seek Info ^ 1 ^ key o - Close Menu ^ 0 ^ quit - ")" && WINNAME=Mpv + ")" && WINNAME=Mpv && return # St echo $WMCLASS | grep -i "st-256color" && CHOICES="$(echo " Pastecomplete ^ 0 ^ key Ctrl+Shift+u + Copycomplete ^ 0 ^ key Ctrl+Shift+i Paste ^ 0 ^ key Ctrl+Shift+v - Pipe Data ^ 0 ^ Zoom + ^ 1 ^ key Ctrl+Shift+Prior Zoom - ^ 1 ^ key Ctrl+Shift+Next - Scroll ↑ ^ 1 ^ key Shift+Prior - Scroll ↓ ^ 1 ^ key Shift+Next + Scroll ↑ ^ 1 ^ key Ctrl+Shift+b + Scroll ↓ ^ 1 ^ key Ctrl+Shift+f Invert ^ 1 ^ key Ctrl+Shift+x Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys - Close Menu ^ 0 ^ quit - ")" && WINNAME=st + ")" && WINNAME=st && return # St hotkeys echo $WMCLASS | grep -i "sthotkeys" && CHOICES="$(echo " Send Ctrl-C ^ 0 ^ key Ctrl+c Send Ctrl-L ^ 0 ^ key Ctrl+l Send Ctrl-D ^ 0 ^ key Ctrl+d - Close Menu ^ 0 ^ quit - ")" && WINNAME=st + ")" && WINNAME=st && return # Surf echo $WMCLASS | grep surf && CHOICES="$(echo " @@ -107,18 +99,27 @@ programchoicesinit() { Search ^ 1 ^ key Ctrl+f History ← ^ 1 ^ key Ctrl+h History → ^ 1 ^ key Ctrl+l - Close Menu ^ 0 ^ quit - ")" && WINNAME=surf + ")" && WINNAME=surf && return + # Netsurf echo $WMCLASS | grep -i netsurf && CHOICES="$(echo " Pipe URL ^ 0 ^ sxmo_urlhandler.sh Zoom + ^ 1 ^ key Ctrl+plus Zoom - ^ 1 ^ key Ctrl+minus History ← ^ 1 ^ key Alt+Left History → ^ 1 ^ key Alt+Right - Close Menu ^ 0 ^ quit - ")" && WINNAME=netsurf + ")" && WINNAME=netsurf && return + # Firefox + echo $WMCLASS | grep -i firefox && CHOICES="$(echo " + Pipe URL ^ 0 ^ sxmo_urlhandler.sh + Zoom + ^ 1 ^ key Ctrl+plus + Zoom - ^ 1 ^ key Ctrl+minus + History ← ^ 1 ^ key Alt+Left + History → ^ 1 ^ key Alt+Right + ")" && WINNAME=netsurf && return + + # Foxtrot GPS echo $WMCLASS | grep -i foxtrot && CHOICES="$(echo " Zoom + ^ 1 ^ key i Zoom - ^ 1 ^ key o @@ -127,8 +128,33 @@ programchoicesinit() { Route ^ 0 ^ key r Gmaps Transfer ^ 0 ^ key o Copy Cords ^ 0 ^ key o - Close Menu ^ 0 ^ quit - ")" && WINNAME=gps + ")" && WINNAME=gps && return +} + +getprogchoices() { + # E.g. sets CHOICES var + programchoicesinit $@ + + # Decorate menu at top w/ incoming call entry if present + INCOMINGCALL=$(cat /tmp/sxmo_incomingcall || echo NOCALL) + echo "$INCOMINGCALL" | grep -v NOCALL && CHOICES="$(echo " + Pickup $(echo $INCOMINGCALL | cut -d: -f2) ^ 0 ^ sxmo_modemcall.sh pickup $(echo $INCOMINGCALL | cut -d: -f1) + $CHOICES + ")" + + # Decorate menu at bottom w/ system menu entry if not system menu + echo $WINNAME | grep -v Sys && CHOICES=" + $CHOICES + System Menu ^ 0 ^ sxmo_appmenu.sh sys + " + + # Decorate menu at bottom w/ close menu entry + CHOICES=" + $CHOICES + Close Menu ^ 0 ^ quit + " + + PROGCHOICES="$(echo "$CHOICES" | xargs -0 echo | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1')" } rotate() { @@ -145,33 +171,30 @@ quit() { exit 0 } -boot() { +mainloop() { DMENUIDX=0 PICKED="" - pgrep -f sxmo_appmenu.sh | grep -Ev "^${$}$" | xargs kill -9 - pkill -9 dmenu -} + ARGS="$@" -mainloop() { while : do - PICKED=$( - echo "$CHOICES" | - xargs -0 echo | + # E.g. sets PROGCHOICES + getprogchoices $ARGS + + PICKED="$( + echo "$PROGCHOICES" | cut -d'^' -f1 | - sed '/^[[:space:]]*$/d' | - awk '{$1=$1};1' | dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$WINNAME" - ) - LOOP=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2) - CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f3) - DMENUIDX=$(echo $(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1) - 1 | bc) + )" + LOOP="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f2)" + CMD="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f3)" + DMENUIDX="$(echo "$PROGCHOICES" | grep -F -n "$PICKED" | cut -d ':' -f1)" + echo "Eval: <$CMD> from picked <$PICKED> with loop <$LOOP>" eval $CMD echo $LOOP | grep 1 || quit done } -boot -programchoicesinit $@ -mainloop - +pgrep -f sxmo_appmenu.sh | grep -Ev "^${$}$" | xargs kill -9 +pkill -9 dmenu +mainloop $@ diff --git a/scripts/core/sxmo_brightness.sh b/scripts/core/sxmo_brightness.sh index 963bf11..1dea256 100755 --- a/scripts/core/sxmo_brightness.sh +++ b/scripts/core/sxmo_brightness.sh @@ -1,25 +1,29 @@ #!/usr/bin/env sh -MAX=10 +[ -e /sys/class/backlight/edp-backlight ] && DEV=/sys/class/backlight/edp-backlight +[ -e /sys/devices/platform/backlight/backlight/backlight ] && DEV=/sys/devices/platform/backlight/backlight/backlight + +MAX=$(cat $DEV/max_brightness) MIN=2 +STEP=$(echo "($MAX - $MIN) / 10" | bc) setdelta() { sxmo_setpinebacklight $( - cat /sys/class/backlight/backlight/brightness | + cat $DEV/brightness | xargs -IB echo B $1 | bc | xargs -INUM echo -e "$MIN\nNUM" | sort -n | tail -n1 | xargs -INUM echo -e "$MAX\nNUM" | sort -n | head -n1 ) - sxmo_notify.sh 200 "Backlight $(cat /sys/class/backlight/backlight/brightness)/10" + sxmo_notify.sh 200 "Backlight $(cat $DEV/brightness)/${MAX}" } up() { - setdelta "+1" + setdelta "+${STEP}" } down() { - setdelta "-1" + setdelta "-${STEP}" } $1 $2 \ No newline at end of file diff --git a/scripts/core/sxmo_pastecomplete.sh b/scripts/core/sxmo_pastecomplete.sh deleted file mode 100755 index bea69a2..0000000 --- a/scripts/core/sxmo_pastecomplete.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env sh -INPUT="$(cat)" - -pidof svkbd-sxmo || svkbd-sxmo & - -RESULT="$( - echo "$( - echo "Close Menu" && - echo "$INPUT" |\ - grep -Eo '\S+' |\ - tr -d '[:blank:]' |\ - sort |\ - uniq - )" | dmenu -p Type -l 10 -i -c -fn Terminus-20 -)" - -pkill svkbd-sxmo - -if [[ "$RESULT" = "Close Menu" ]]; then - exit 0 -else - xdotool type "$RESULT" -fi diff --git a/scripts/core/sxmo_pipecomplete.sh b/scripts/core/sxmo_pipecomplete.sh new file mode 100755 index 0000000..7566798 --- /dev/null +++ b/scripts/core/sxmo_pipecomplete.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env sh +INPUT="$(cat)" + +pidof svkbd-sxmo || svkbd-sxmo & + +capfirstchar() { + awk -F -vOFS= {$1=toupper($1);print $0} +} + +RESULT="$( + echo "$( + echo "Close Menu" && + echo "$INPUT" |\ + grep -Eo '\S+' |\ + tr -d '[:blank:]' |\ + sort |\ + uniq + )" | dmenu -p $(echo $1 | capfirstchar) -l 10 -i -c -fn Terminus-20 +)" + +pkill svkbd-sxmo + +copy() { + if [[ "$RESULT" = "Close Menu" ]]; then + exit 0 + else + echo "$RESULT" | xsel -i + fi +} + +type() { + if [[ "$RESULT" = "Close Menu" ]]; then + exit 0 + else + xdotool type "$RESULT" + fi +} + +$@ diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index ca08745..fc20995 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -1,15 +1,23 @@ #!/usr/bin/env sh +pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs kill -9 + UPDATEFILE=/tmp/sxmo_bar touch $UPDATEFILE while : do + # M symbol if modem monitoring is on + MODEMMON="" + pgrep -f sxmo_modemmonitor.sh && MODEMMON="M " + + # Battery pct PCT=$(cat /sys/class/power_supply/*-battery/capacity) BATSTATUS=$( cat /sys/class/power_supply/*-battery/status | cut -c1 ) + # Volume VOL=$( echo "$(amixer sget Headphone || amixer sget Speaker)" | grep -oE '([0-9]+)%' | @@ -18,11 +26,12 @@ do xargs printf %.0f ) + # Time TIME=$(date +%R) - BAR=" V${VOL} ${BATSTATUS}${PCT}% ${TIME}" + BAR=" ${MODEMMON}V${VOL} ${BATSTATUS}${PCT}% ${TIME}" xsetroot -name "$BAR" - inotifywait -e MODIFY $UPDATEFILE & sleep 5 & wait -n + inotifywait -e MODIFY $UPDATEFILE & sleep 30 & wait -n pgrep -P $$ | xargs kill -9 done \ No newline at end of file diff --git a/scripts/core/sxmo_vol.sh b/scripts/core/sxmo_vol.sh index 72979b5..f6c1036 100755 --- a/scripts/core/sxmo_vol.sh +++ b/scripts/core/sxmo_vol.sh @@ -1,23 +1,26 @@ #!/usr/bin/env sh device() { - amixer sget Headphone && echo Headphone || echo Speaker + amixer sget Headphone > /dev/null && echo Headphone || echo Speaker } -incvol() { - amixer set $(device) 1+ +notify() { + sxmo_notify.sh 200 "Volume $( + amixer get "$(device)" | + grep -oE '([0-9]+)%' | + tr -d ' %' | + awk '{ s += $1; c++ } END { print s/c }' | + xargs printf %.0f + )" echo 1 > /tmp/sxmo_bar } -decvol() { + +up() { + amixer set $(device) 1+ + notify +} +down() { amixer set $(device) 1- - echo 1 > /tmp/sxmo_bar + notify } -echo $1 | grep up && echo 1 > /tmp/sxmo_bar && incvol -echo $1 | grep down && echo 1 > /tmp/sxmo_bar && decvol -sxmo_notify.sh 200 "Volume $( - echo "$(amixer sget Headphone || amixer sget Speaker)" | - grep -oE '([0-9]+)%' | - tr -d ' %' | - awk '{ s += $1; c++ } END { print s/c }' | - xargs printf %.0f -)" +$@ diff --git a/scripts/core/sxmo_xinit.sh b/scripts/core/sxmo_xinit.sh index 19c0365..ef05cf9 100755 --- a/scripts/core/sxmo_xinit.sh +++ b/scripts/core/sxmo_xinit.sh @@ -10,7 +10,7 @@ alsactl --file /usr/share/sxmo/default_alsa_sound.conf restore #xset r off # E.g. for PBP -synclient TapButton1=1 TapButton2=3 TapButton3=2 +synclient TapButton1=1 TapButton2=3 TapButton3=2 MinSpeed=0.25 keynav & conky -c /usr/share/sxmo/conky.conf -d diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index dbec749..624a7d2 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -5,6 +5,10 @@ err() { exit 1 } +modem_n() { + mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 +} + toggleflag() { TOGGLEFLAG=$1 shift @@ -29,30 +33,37 @@ dialmenu() { tr -d - )" echo "Attempting to dial: $NUMBER" >&2 - VID=$( - sudo mmcli -m 0 --voice-create-call "number=$NUMBER" | grep -Eo Call/[0-9]+ | grep -oE [0-9]+ - ) + VID="$( + sudo mmcli -m $(modem_n) --voice-create-call "number=$NUMBER" | grep -Eo Call/[0-9]+ | grep -oE [0-9]+ + )" echo "Starting call with VID: $VID" >&2 - - echo "$(startcall $VID)" + startcall $VID >&@ + echo $VID } startcall() { - VID=$1 - sudo mmcli -m 0 -o $VID --start | grep "successfully started" || err "Couldn't start call!" - echo $VID + VID="$1" + sudo mmcli --voice-status -o $VID + sudo mmcli -m $(modem_n) -o $VID --start | grep "successfully started" || err "Couldn't start call!" +} + +acceptcall() { + VID="$1" + echo "Attempting to pickup VID $VID" + sudo mmcli --voice-status -o $VID + sudo mmcli -m $(modem_n) -o $VID --accept | grep "successfully" || err "Couldn't accept call!" } hangup() { VID=$1 - sudo mmcli -m 0 -o $VID --hangup + sudo mmcli -m $(modem_n) -o $VID --hangup | grep "successfully hung up" || err "Failed to hangup the call?" exit 1 } incallmenu() { DMENUIDX=0 VID="$1" - + NUMBER=$(mmcli -m $(modem_n) -o $VID -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ') # E.g. Run once w/o -2, and then run once with -2 FLAGS="-e -m" sxmo_megiaudioroute $FLAGS @@ -77,7 +88,7 @@ incallmenu() { TSPEAKER ^ FLAGS="$(toggleflag "-s" "$FLAGS")" DTMF Tones ^ dtmfmenu $VID Hangup ^ hangup $VID - Lock Screen ^ hangup + Lock Screen ^ sxmo_screenlock ' | sed "s/TMUTE/$TMUTE/;s/TECHO/$TECHO/;s/TEARPIECE/$TEARPIECE/;s/TLINEJACK/$TLINEJACK/;s/TSPEAKER/$TSPEAKER/" )" @@ -87,7 +98,7 @@ incallmenu() { cut -d'^' -f1 | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1' | - dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$VID" + dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$NUMBER" ) CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2) DMENUIDX=$(echo $(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1) - 1 | bc) @@ -103,13 +114,13 @@ dtmfmenu() { while true do PICKED="$( - echo $NUMS | grep -o . | sed '1 iReturn to Call Menu' | + echo "$NUMS" | grep -o . | sed '1 iReturn to Call Menu' | dmenu -l 20 -fn Terminus-20 -c -idx $DMENUIDX -p "DTMF Tone" )" - DMENUIDX=$(echo $NUMS | grep -bo $PICKED | cut -d: -f1 | xargs -IN echo 2+N | bc) + DMENUIDX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc) - echo $PICKED | grep "Return to Call Menu" && break - mmcli -m 0 -o $VID --send-dtmf="$PICKED" + echo "$PICKED" | grep "Return to Call Menu" && break + sudo mmcli -m $(modem_n) -o $VID --send-dtmf="$PICKED" done } @@ -120,7 +131,9 @@ dial() { } pickup() { - startcall $1 + acceptcall $1 + incallmenu $1 } +modem_n || err "Couldn't determine modem number - is modem online?" $@ diff --git a/scripts/modem/sxmo_modeminfo.sh b/scripts/modem/sxmo_modeminfo.sh new file mode 100755 index 0000000..7614011 --- /dev/null +++ b/scripts/modem/sxmo_modeminfo.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +modem_n() { + mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 +} + +st -e sh -c "mmcli -m $(modem_n) && read" diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index 207fa6d..e3aec2d 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -1,17 +1,26 @@ #!/usr/bin/env sh TIMEOUT=3 -MODEM=$(mmcli -L | grep -o "Modem/[0-9]" | grep -o [0-9]$) + +modem_n() { + mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 +} newcall() { + VID="$1" sxmo_setpineled green 1 + for i in $(sudo mmcli -m $(modem_n) --voice-list-calls | grep terminated | grep -oE Call\/[0-9]+ | cut -d'/' -f2); do + sudo mmcli -m $(modem_n) --voice-delete-call $i + done + echo "Incoming Call:" INCOMINGNUMBER=$( - mmcli -m 0 --voice-list-calls -o 3 -K | + mmcli -m $(modem_n) --voice-list-calls -o "$VID" -K | grep call.properties.number | cut -d ':' -f 2 ) - echo "Number: $INCOMINGNUMBER" + echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall + echo "Number: $INCOMINGNUMBER (VID: $VID)" } newtexts() { @@ -19,7 +28,7 @@ newtexts() { echo "New Texts:" for i in $(echo -e "$1") ; do - DAT="$(mmcli -m 0 -s $i -K)" + DAT="$(mmcli -m $(modem_n) -s $i -K)" TEXT="$(echo "$DAT" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" NUM="$(echo "$DAT" | grep sms.content.number | sed -E 's/^sms\.content\.number\s+:\s+[+]?//')" @@ -29,7 +38,7 @@ newtexts() { mkdir -p ~/.sxmo/$NUM echo -ne "$NUM at $TIME:\n$TEXT\n\n" >> ~/.sxmo/$NUM/sms.txt echo -ne "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> ~/.sxmo/$NUM/log.tsv - sudo mmcli -m $MODEM --messaging-delete-sms=$i + sudo mmcli -m $(modem_n) --messaging-delete-sms=$i done } @@ -37,21 +46,21 @@ while true do sxmo_setpineled green 0 VOICECALLID="$( - mmcli -m 0 --voice-list-calls -a | + mmcli -m $(modem_n) --voice-list-calls -a | grep -Eo '[0-9]+ incoming \(ringing-in\)' | grep -Eo '[0-9]+' )" TEXTIDS="$( - mmcli -m 0 --messaging-list-sms | - grep -Eo '/SMS/[0-9] \(received\)' | + mmcli -m $(modem_n) --messaging-list-sms | + grep -Eo '/SMS/[0-9]+ \(received\)' | grep -Eo '[0-9]+' )" echo VIDS $VOICECALLID echo TIDS $TEXTIDS - echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" + echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" || rm /tmp/sxmo_incomingcall echo "$TEXTIDS" | grep . && newtexts "$TEXTIDS" sleep $TIMEOUT done diff --git a/scripts/modem/sxmo_modemmonitortoggle.sh b/scripts/modem/sxmo_modemmonitortoggle.sh new file mode 100755 index 0000000..fb501d1 --- /dev/null +++ b/scripts/modem/sxmo_modemmonitortoggle.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +pgrep -f sxmo_modemmonitor.sh && pkill -9 -f sxmo_modemmonitor.sh || sxmo_modemmonitor.sh & +rm /tmp/sxmo_incomingcall + +# E.g. wait until process killed or started -- maybe there's a better way.. +sleep 0.2 + +echo 1 > /tmp/sxmo_bar diff --git a/scripts/modem/sxmo_modemsendtext.sh b/scripts/modem/sxmo_modemsendtext.sh index cf7d5b7..cb3c224 100755 --- a/scripts/modem/sxmo_modemsendtext.sh +++ b/scripts/modem/sxmo_modemsendtext.sh @@ -1,8 +1,13 @@ #!/usr/bin/env sh EDITOR=vis -modem() { - mmcli -L | grep -o "Modem/[0-9]" | grep -o [0-9]$ +err() { + echo $1 | dmenu -fn Terminus-20 -c -l 10 + exit 1 +} + +modem_n() { + mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 } editmsg() { @@ -13,7 +18,7 @@ editmsg() { } sendmsg() { - MODEM=$(modem) + MODEM=$(modem_n) SMSNO=$( sudo mmcli -m $MODEM --messaging-create-sms="text='$2',number=$1" | grep -o [0-9]*$ @@ -25,7 +30,7 @@ sendmsg() { } main() { - modem || st -e "echo Couldn't determine modem number - is modem online?" + modem_n || err "Couldn't determine modem number - is modem online?" # Prompt for number NUMBER=$(