~mil/sxmo-utils

c119ab0145206937468a3e04261d9bb63b8f2043 — Miles Alan 1 year, 5 months ago 391df5d
Pull dialing functionality into seperate script; allows in-call check to be valid
3 files changed, 66 insertions(+), 44 deletions(-)

M scripts/core/sxmo_appmenu.sh
M scripts/modem/sxmo_modemcall.sh
A scripts/modem/sxmo_modemdial.sh
M scripts/core/sxmo_appmenu.sh => scripts/core/sxmo_appmenu.sh +1 -1
@@ 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

M scripts/modem/sxmo_modemcall.sh => scripts/modem/sxmo_modemcall.sh +22 -43
@@ 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"

A scripts/modem/sxmo_modemdial.sh => scripts/modem/sxmo_modemdial.sh +43 -0
@@ 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"