From 34b2c570382dd5f93b9124fb548be41c02b5800c Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Fri, 15 May 2020 21:23:49 -0500 Subject: [PATCH] Fixes related to cleaning up modem functionality; fix audio; add flash toggle --- README.md | 5 ++++ configs/default_alsa_sound.conf | 5 ++-- scripts/core/sxmo_appmenu.sh | 3 +-- scripts/core/sxmo_flashtoggle.sh | 6 +++++ scripts/core/sxmo_statusbar.sh | 2 +- scripts/modem/sxmo_modemcall.sh | 33 ++++++++++++++---------- scripts/modem/sxmo_modemmonitor.sh | 13 ++++++++-- scripts/modem/sxmo_modemmonitortoggle.sh | 2 +- scripts/modem/sxmo_modemtext.sh | 13 +++++----- 9 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 README.md create mode 100755 scripts/core/sxmo_flashtoggle.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..62bf3fd --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# sxmo-utils + +This repository contains scripts and C programs to support sxmo. + + diff --git a/configs/default_alsa_sound.conf b/configs/default_alsa_sound.conf index 99a61fc..04d235c 100644 --- a/configs/default_alsa_sound.conf +++ b/configs/default_alsa_sound.conf @@ -1,4 +1,3 @@ -# Mute speaker, only output to headphones state.sun50ia64audio { control.1 { iface MIXER @@ -429,8 +428,8 @@ state.sun50ia64audio { control.33 { iface MIXER name 'DAC Mixer AIF2 DAC Playback Switch' - value.0 true - value.1 true + value.0 false + value.1 false comment { access 'read write' type BOOLEAN diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 8f14285..b1a91d0 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -40,13 +40,12 @@ programchoicesinit() { # System Control menu echo $WMCLASS | grep -i "config" && 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 $(pgrep -f sxmo_modemmonitor.sh >/dev/null && echo -n "On → Off" || echo -n "Off → On") ^ 1 ^ sxmo_modemmonitortoggle.sh Modem Info ^ 0 ^ sxmo_modeminfo.sh Modem Log ^ 0 ^ sxmo_modemlog.sh + Flash $(cat /sys/class/leds/white:flash/brightness | grep -E '^0$' > /dev/null && echo -n "Off → On" || echo -n "On → Off") ^ 1 ^ sxmo_flashtoggle.sh Rotate ^ 1 ^ rotate Wifi ^ 0 ^ st -e "nmtui" Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh diff --git a/scripts/core/sxmo_flashtoggle.sh b/scripts/core/sxmo_flashtoggle.sh new file mode 100755 index 0000000..1470a46 --- /dev/null +++ b/scripts/core/sxmo_flashtoggle.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +sxmo_setpineled white "$( + cat /sys/class/leds/white:flash/brightness | + grep -E '^0$' > /dev/null && echo 255 || echo 0 +)" + diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index b702c54..dc7d39f 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -24,7 +24,7 @@ do # Volume VOL=$( - echo "$(audiodevice)" | + echo "$(amixer sget $(audiodevice))" | grep -oE '([0-9]+)%' | tr -d ' %' | awk '{ s += $1; c++ } END { print s/c }' | diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index 115609e..ab06b8e 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -1,9 +1,12 @@ #!/usr/bin/env sh +PID=$$ LOGDIR=/home/$USER/.sxmo +trap "kill 0" SIGINT err() { echo -e "$1" | dmenu -fn Terminus-20 -c -l 10 - kill $$ + alsactl --file /usr/share/sxmo/default_alsa_sound.conf restore + kill -9 0 } modem_n() { @@ -11,10 +14,11 @@ modem_n() { } contacts() { - cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF + RES="$(cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF)" + echo $RES + echo -e "$RES" | grep 8042221111 || echo Test Number 8042221111 } - modem_cmd_errcheck() { ARGS="$@" RES="$(mmcli $ARGS 2>&1)" @@ -23,15 +27,16 @@ modem_cmd_errcheck() { } vid_to_number() { - mmcli -m $(modem_n) -o $1 -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ' + mmcli -m $(modem_n) -o $1 -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ' | sed 's/^[+]//' | sed 's/^1//' } log_event() { EVT_HANDLE="$1" EVT_VID="$2" - NUMBER="$(vid_to_number $EVT_VID)" + NUM="$(vid_to_number $EVT_VID)" TIME="$(date --iso-8601=seconds)" - echo -ne "$TIME\t$EVT_HANDLE\t$NUMBER\n" >> $LOGDIR/modemlog.tsv + mkdir -p $LOGDIR + echo -ne "$TIME\t$EVT_HANDLE\t$NUM\n" >> $LOGDIR/modemlog.tsv } toggleflag() { @@ -52,12 +57,13 @@ toggleflag() { dialmenu() { CONTACTS="$(contacts)" NUMBER="$( - echo -e "Close Menu\n$CONTACTS\nTest Number 804-222-1111" | - sxmo_dmenu_with_kb.sh -l 10 -p Number -c -fn Terminus-20 | - awk -F' ' '{print $NF}' | - tr -d - + echo -e "Close Menu\n$CONTACTS" | + sxmo_dmenu_with_kb.sh -l 10 -p Number -c -fn Terminus-20 )" - echo $NUMBER | grep "Close Menu" && kill $$ + echo "$NUMBER" | grep "Close Menu" && kill 0 + + NUMBER="$(echo $NUMBER | awk -F' ' '{print $NF}' | tr -d -)" + echo "$NUMBER" | grep -E '^[0-9]+$'> /dev/null || err "$NUMBER is not a number" echo "Attempting to dial: $NUMBER" >&2 VID="$( @@ -72,7 +78,7 @@ startcall() { VID="$1" #modem_cmd_errcheck --voice-status -o $VID modem_cmd_errcheck -m $(modem_n) -o $VID --start - log_event "call_start" $VID + log_event "call_start" "$VID" } acceptcall() { @@ -163,10 +169,9 @@ dtmfmenu() { done } - dial() { VID="$(dialmenu)" - incallmenu $VID + incallmenu $VID } pickup() { diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index 832243d..e0359e7 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -21,10 +21,13 @@ newcall() { INCOMINGNUMBER=$( mmcli -m $(modem_n) --voice-list-calls -o "$VID" -K | grep call.properties.number | - cut -d ':' -f 2 + cut -d ':' -f 2 | + sed 's/^[+]//' | + sed 's/^1//' ) TIME="$(date --iso-8601=seconds)" + mkdir -p $LOGDIR echo -ne "$TIME\tcall_ring\t$NUMBER\n" >> $LOGDIR/modemlog.tsv echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall echo "Number: $INCOMINGNUMBER (VID: $VID)" @@ -39,7 +42,13 @@ newtexts() { 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+[+]?//')" + NUM="$( + echo "$DAT" | + grep sms.content.number | + sed -E 's/^sms\.content\.number\s+:\s+[+]?//' | + sed 's/^[+]//' | + sed 's/^1//' + )" TIME="$(echo "$DAT" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" TEXTSIZE="$(echo $TEXT | wc -c)" diff --git a/scripts/modem/sxmo_modemmonitortoggle.sh b/scripts/modem/sxmo_modemmonitortoggle.sh index fb501d1..3fb88e0 100755 --- a/scripts/modem/sxmo_modemmonitortoggle.sh +++ b/scripts/modem/sxmo_modemmonitortoggle.sh @@ -3,6 +3,6 @@ pgrep -f sxmo_modemmonitor.sh && pkill -9 -f sxmo_modemmonitor.sh || sxmo_modemm rm /tmp/sxmo_incomingcall # E.g. wait until process killed or started -- maybe there's a better way.. -sleep 0.2 +sleep 1 echo 1 > /tmp/sxmo_bar diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh index 1e1385e..c738b0c 100755 --- a/scripts/modem/sxmo_modemtext.sh +++ b/scripts/modem/sxmo_modemtext.sh @@ -11,8 +11,9 @@ modem_n() { mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 } -contacts() { - cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF +textcontacts() { + # TODO: is find automatically sorted by timestamp? + find $LOGDIR/* -type d -maxdepth 1 | awk -F'/' '{print $NF}' | tac } editmsg() { @@ -24,7 +25,7 @@ editmsg() { sendmsg() { MODEM=$(modem_n) - NUMBER="$1" + NUMBER="$(echo "$1" | sed 's/^[+]//' | sed 's/^1//')" TEXT="$2" TEXTSIZE="$(echo "$TEXT" | wc -c)" @@ -38,7 +39,7 @@ sendmsg() { done TIME="$(date --iso-8601=seconds)" - mkdir -p ~/.sxmo/$NUMBER + mkdir -p $LOGDIR/$NUMBER echo -ne "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUMBER/sms.txt echo -ne "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv @@ -50,7 +51,7 @@ sendtextmenu() { # Prompt for number NUMBER=$( - echo -e "\nCancel\n$(contacts)" | + echo -e "\nCancel\n$(textcontacts)" | awk NF | sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c ) @@ -79,7 +80,7 @@ tailtextlog() { main() { # Display - ENTRIES="$(echo -e "$(contacts)" | xargs -INUM echo NUM logfile)" + ENTRIES="$(echo -e "$(textcontacts)" | xargs -INUM echo NUM logfile)" ENTRIES="$(echo -e "Close Menu\nSend a Text\n$ENTRIES")" NUMBER="$(echo -e "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)" echo $NUMBER | grep "Close Menu" && exit 1