From c119ab0145206937468a3e04261d9bb63b8f2043 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Sat, 27 Jun 2020 20:58:39 -0500 Subject: [PATCH] Pull dialing functionality into seperate script; allows in-call check to be valid --- scripts/core/sxmo_appmenu.sh | 2 +- scripts/modem/sxmo_modemcall.sh | 65 +++++++++++---------------------- scripts/modem/sxmo_modemdial.sh | 43 ++++++++++++++++++++++ 3 files changed, 66 insertions(+), 44 deletions(-) create mode 100755 scripts/modem/sxmo_modemdial.sh diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 52f46be..d6c6288 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -188,7 +188,7 @@ programchoicesinit() { Apps ^ 0 ^ sxmo_appmenu.sh applications Files ^ 0 ^ sxmo_files.sh Maps ^ 0 ^ foxtrotgps - Dialer ^ 0 ^ sxmo_modemcall.sh dial + Dialer ^ 0 ^ sxmo_modemdial.sh Texts ^ 0 ^ sxmo_modemtext.sh Camera ^ 0 ^ sxmo_camera.sh Wifi ^ 0 ^ st -e nmtui diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index 869d021..084b345 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -37,7 +37,12 @@ modem_cmd_errcheck() { } vid_to_number() { - mmcli -m "$(modem_n)" -o "$1" -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ' | sed 's/^[+]//' | sed 's/^1//' + mmcli -m "$(modem_n)" -o "$1" -K | + grep call.properties.number | + cut -d ':' -f2 | + tr -d ' ' | + sed 's/^[+]//' | + sed 's/^1//' } log_event() { @@ -69,42 +74,24 @@ toggleflagset() { FLAGS="$(toggleflag "$1" "$FLAGS")" } -dialmenu() { - CONTACTS="$(contacts)" - NUMBER="$( - printf %b "Close Menu\n$CONTACTS" | - grep . | - sxmo_dmenu_with_kb.sh -l 10 -p Number -c -fn Terminus-20 - )" - echo "$NUMBER" | grep "Close Menu" && kill 0 - - NUMBER="$(echo "$NUMBER" | awk -F' ' '{print $NF}' | tr -d -)" - echo "$NUMBER" | grep -qE '^[+0-9]+$' || fatalerr "$NUMBER is not a number" - - echo "Attempting to dial: $NUMBER" >&2 - CALLID="$( - mmcli -m "$(modem_n)" --voice-create-call "number=$NUMBER" | - grep -Eo "Call/[0-9]+" | - grep -oE "[0-9]+" - )" - echo "Starting call with CALLID: $CALLID" >&2 - startcall "$CALLID" >&2 - echo "$CALLID" -} - -startcall() { - CALLID="$1" - #modem_cmd_errcheck --voice-status -o $CALLID - modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --start - log_event "call_start" "$CALLID" -} - acceptcall() { CALLID="$1" - echo "Attempting to pickup CALLID $CALLID" - #mmcli --voice-status -o $CALLID - modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept - log_event "call_pickup" "$CALLID" + echo "Attempting to initialize CALLID $CALLID" + DIRECTION="$( + mmcli --voice-status -o "$CALLID" -K | + grep call.properties.direction | + cut -d: -f2 | + tr -d " " + )" + if [ "$DIRECTION" = "outgoing" ]; then + modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --start + log_event "call_start" "$CALLID" + elif [ "$DIRECTION" = "incoming" ]; then + modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept + log_event "call_pickup" "$CALLID" + else + fatalerr "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>" + fi } hangup() { @@ -200,14 +187,6 @@ dtmfmenu() { done } - -dial() { - CALLID="$(dialmenu)" - incallsetup "$CALLID" - incallmonitor "$CALLID" & - incallmenuloop "$CALLID" -} - pickup() { acceptcall "$1" incallsetup "$1" diff --git a/scripts/modem/sxmo_modemdial.sh b/scripts/modem/sxmo_modemdial.sh new file mode 100755 index 0000000..c42912a --- /dev/null +++ b/scripts/modem/sxmo_modemdial.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env sh +LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem +trap "gracefulexit" INT TERM + +fatalerr() { + # E.g. hangup all calls, switch back to default audio, notify user, and die + mmcli -m "$(mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2)" --voice-hangup-all + notify-send "$1" + (sleep 0.5; echo 1 > /tmp/sxmo_bar) & + kill -9 0 +} + +modem_n() { + MODEMS="$(mmcli -L)" + echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || fatalerr "Couldn't find modem - is your modem enabled?" + echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 +} + +dialmenu() { + CONTACTS="$(contacts)" + NUMBER="$( + printf %b "Close Menu\n$CONTACTS" | + grep . | + sxmo_dmenu_with_kb.sh -l 10 -p Number -c -fn Terminus-20 + )" + echo "$NUMBER" | grep "Close Menu" && kill 0 + + NUMBER="$(echo "$NUMBER" | awk -F' ' '{print $NF}' | tr -d -)" + echo "$NUMBER" | grep -qE '^[+0-9]+$' || fatalerr "$NUMBER is not a number" + + echo "Attempting to dial: $NUMBER" >&2 + CALLID="$( + mmcli -m "$(modem_n)" --voice-create-call "number=$NUMBER" | + grep -Eo "Call/[0-9]+" | + grep -oE "[0-9]+" + )" + echo "Starting call with CALLID: $CALLID" >&2 + echo "$CALLID" +} + +modem_n || fatalerr "Couldn't determine modem number - is modem online?" +CREATEDCALLID="$(dialmenu)" +sxmo_modemcall.sh pickup "$CREATEDCALLID"