~mil/sxmo-tickets#526: 
Add ring profiles for incoming calls and texts

This is a proposed set of patches that will add a menu item to the audio menu to choose between profiles for incoming calls and texts(mute, vibrate, ring, ring&vibrate). It also includes a config file so the user can set their ringtone and text sound without editing the scripts.

--- a/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh
+++ b/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh
@@ -24,12 +24,30 @@
 fi

 # Start the mpv ring until another hook kill it or the max (10) is reached
-mpv --quiet --no-video --loop=10 /usr/share/sxmo/ring.ogg &
-MPVID=$!
-echo "$MPVID" > "$XDG_RUNTIME_DIR/sxmo.ring.pid"
+source "$HOME/.sxmocfg"

-# Vibrate while mpv is running
-while kill -0 $MPVID; do
+case `cat /home/user/.ringmode` in
+       0) #Mute
+          ;;
+       1) #Vibrate
+          for i in `seq 5`; do
                sxmo_vibrate 1500
                sleep 0.5
-done
+           done
+          ;;
+       2) #Ring
+          timeout "$RINGTIME" mpv --quiet --no-video --loop="$RINGNUMBER" $RINGTONE &
+           MPVID=$!
+           echo "$MPVID" > "$XDG_RUNTIME_DIR/sxmo.ring.pid"
+          ;;
+       *) #Default ring and vibrate
+          timeout "$RINGTIME" mpv --quiet --no-video --loop="$RINGNUMBER" $RINGTONE &
+          MPVID=$!
+          echo "$MPVID" > "$XDG_RUNTIME_DIR/sxmo.ring.pid"
+           # Vibrate while mpv is running
+          while kill -0 $MPVID; do
+                         sxmo_vibrate 1500
+                         sleep 0.5
+          done
+          ;;
+esac
--- a/usr/share/sxmo/default_hooks/sxmo_hook_sms.sh
+++ b/usr/share/sxmo/default_hooks/sxmo_hook_sms.sh
@@ -14,4 +14,19 @@
 # Finally, mms may include this parameter:
 # $4 = Group Contact Name or Number (if number not in contacts)

-mpv --quiet --no-video /usr/share/sxmo/notify.ogg
+source "$HOME/.sxmocfg"
+
+case `cat /home/user/.ringmode` in
+       0) #Mute
+          ;;
+       1) #Vibrate
+          sxmo_vibrate 500
+          ;;
+       2) #Ring
+          mpv --quiet --no-video "$TEXTSOUND"
+          ;;
+       *) #Default: ring&vibrate
+          mpv --quiet --no-video "$TEXTSOUND" &
+          sxmo_vibrate 500
+          ;;
+esac
--- -
+++ /home/user/.sxmocfg
@@ -0,0 +1,10 @@
+#Set RINGTONE to audio file to play for incoming call
+RINGTONE="/usr/share/sxmo/ring.ogg"
+#Set TEXTSOUND to audio file to play when receive text message
+TEXTSOUND="/usr/share/sxmo/notify.ogg"
+
+#Set RINGTIME to number of seconds the phone will ring
+RINGTIME=20
+#Set RINGNUMBER to number of times phone will ring or repeat ringtone
+#(Whichever RINGTIME or RINGNUMBER runs less will be how long phone rings)
+RINGNUMER=10
--- a/usr/bin/sxmo_audio.sh
+++ b/usr/bin/sxmo_audio.sh
@@ -92,6 +92,17 @@
        else
                printf "Mic: On -> Off ^ sxmo_modemaudio.sh mute_mic\n"
        fi
+       printf "%s " "$icon_ear"
+       case `cat /home/user/.ringmode` in
+               0) printf "Mute -> Vibrate ^ echo 1 > /home/user/.ringmode\n"
+                  ;;
+               1) printf "Vibrate -> Ring ^ echo 2 > /home/user/.ringmode\n"
+                  ;;
+               2) printf "Ring -> Ring&Vibrate ^ echo "" > /home/user/.ringmode\n"
+                  ;;
+               *) printf "Ring&Vibrate -> Mute ^ echo 0 > /home/user/.ringmode\n"
+                  ;;
+       esac
 }

 pulsemenuchoices() {
Status
REPORTED
Submitter
~shivers
Assigned to
No-one
Submitted
4 months ago
Updated
4 months ago
Labels
No labels applied.

~earboxer 4 months ago

Not a bad idea to have ringmodes (and a menu to switch them)! -- but honestly now that I think of it, I would just want to script my ringmode (don't ring during known meetings, etc) if it bothered me that much.

In terms of the config, we generally just use the hooks, but sometimes also environment variables as our config.

~aren 4 months ago

Please use git send-email to send this to the sxmo-devel mailing list at ~mil/sxmo-devel@lists.sr.ht . If you haven't sent emails using git before https://git-send-email.io/ is a good guide.

From quickly skimming your patch it's an interesting idea, but your implementation has some issues:

  • you should use $XDG_CONFIG_HONE/sxmo instead of $HOME or /home/user
  • we already load configuration from ~/.profile and $XDG_CONFIG_HOME/sxmo/profile, which serves the same purpose as the sxmocfg file you added.
  • you might want to consider using the name of the ring mode instead of a number (eg mute instead of 0)

~shivers 4 months ago

Thanks for the great suggestions for improvements and the link to the git send-email guide. I have made the corrections to the files and when I figure out git send-email I will send it to the sxmo-devel mailing list.

~stacyharper 4 months ago

I'm not opposed to merge something like that. Those scripts are simple enough and extendable easily. I'm in favor to have this feature by default.

Use a hook for the menu part as other already recommended, to be able to add additional modes.

I'll review your futures patch with pleasure :)

Register here or Log in to comment, or comment via email.