Skip to content

Commit

Permalink
Adding boot volume value to config and startup script #1169
Browse files Browse the repository at this point in the history
  • Loading branch information
MiczFlor committed Dec 6, 2020
1 parent 08db5d9 commit ce0742c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
3 changes: 3 additions & 0 deletions htdocs/inc.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function fileGetContentOrDefault($filename, $defaultValue)
$edition = $globalConf['EDITION'];
$maxvolumevalue = $globalConf['AUDIOVOLMAXLIMIT'];
$startupvolumevalue = $globalConf['AUDIOVOLSTARTUP'];
$bootvolumevalue = $globalConf['AUDIOVOLBOOT'];
$volstepvalue = $globalConf['AUDIOVOLCHANGESTEP'];
$idletimevalue = $globalConf['IDLETIMESHUTDOWN'];
$conf['settings_lang'] = $globalConf['LANG'];
Expand Down Expand Up @@ -193,6 +194,7 @@ function fileGetContentOrDefault($filename, $defaultValue)
'volume',
'maxvolume',
'startupvolume',
'bootvolume',
'volstep',
'shutdown',
'reboot',
Expand Down Expand Up @@ -294,6 +296,7 @@ function fileGetContentOrDefault($filename, $defaultValue)
'volume' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=setvolume -v=%s", // change volume
'maxvolume' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=setmaxvolume -v=%s", // change max volume
'startupvolume' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=setstartupvolume -v=%s", // change startup volume
'bootvolume' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=setbootvolume -v=%s", // change startup volume
'volstep' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=setvolstep -v=%s", // change volume step
'mute' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=mute", // volume mute (toggle)
'volumeup' => "/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=volumeup", // volume up
Expand Down
2 changes: 0 additions & 2 deletions htdocs/inc.setStartupVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
-->
<!-- input-group -->
<?php
//$maxvolumevalue = exec("/usr/bin/sudo ".$conf['scripts_abs']."/playout_controls.sh -c=getmaxvolume");
//$maxvolumevalue = 43.6;//debug
$maxvalueselect = round(($maxvolumevalue/5))*5;
$startupvaluedisplay = round($startupvolumevalue);
?>
Expand Down
1 change: 1 addition & 0 deletions htdocs/lang/lang-de-DE.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
$lang['settingsVolChangePercent'] = "Lautst. Änderung";
$lang['settingsMaxVol'] = "Max. Lautstärke";
$lang['settingsStartupVol'] = "Start-Lautstärke";
$lang['settingsBootVol'] = "Lautst. nach Boot";
$lang['settingsWifiRestart'] = "Die Änderungen an der WiFi-Verbindung erfordern einen Neustart, um wirksam zu werden";
$lang['settingsWifiSsidPlaceholder'] = "z.B. PhonieHomie";
$lang['settingsWifiSsidHelp'] = "Der Name, unter dem dein WiFi als 'verfügbares Netzwerk' angezeigt wird";
Expand Down
1 change: 1 addition & 0 deletions htdocs/lang/lang-en-UK.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
$lang['settingsVolChangePercent'] = "Vol. Change %";
$lang['settingsMaxVol'] = "Maximum Volume";
$lang['settingsStartupVol'] = "Startup Volume";
$lang['settingsBootVol'] = "Volume after reboot";
$lang['settingsWifiRestart'] = "The changes applied to your WiFi connection require a restart to take effect.";
$lang['settingsWifiSsidPlaceholder'] = "e.g.: PhonieHomie";
$lang['settingsWifiSsidHelp'] = "The name under which your WiFi shows up as 'available network'";
Expand Down
1 change: 1 addition & 0 deletions htdocs/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
include("inc.setMaxVolume.php");
include("inc.setVolumeStep.php");
include("inc.setStartupVolume.php");
include("inc.setBootVolume.php");
?>
</div><!-- / .row -->
</div><!-- /.panel-body -->
Expand Down
14 changes: 13 additions & 1 deletion scripts/inc.writeGlobalConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,22 @@ AUDIOVOLMINLIMIT=`cat $PATHDATA/../settings/Min_Volume_Limit`
# Startup_Volume
# 1. create a default if file does not exist
if [ ! -f $PATHDATA/../settings/Startup_Volume ]; then
echo "30" > $PATHDATA/../settings/Startup_Volume
echo "0" > $PATHDATA/../settings/Startup_Volume
chmod 777 $PATHDATA/../settings/Startup_Volume
fi
# 2. then|or read value from file
AUDIOVOLSTARTUP=`cat $PATHDATA/../settings/Startup_Volume`

##############################################
# Volume_Boot - after reboot
# 1. create a default if file does not exist
if [ ! -f $PATHDATA/../settings/Volume_Boot ]; then
echo "30" > $PATHDATA/../settings/Volume_Boot
chmod 777 $PATHDATA/../settings/Volume_Boot
fi
# 2. then|or read value from file
AUDIOVOLBOOT=`cat $PATHDATA/../settings/Volume_Boot`

##############################################
# Change_Volume_Idle
# Change volume during idle (or only change it during Play and in the WebApp)
Expand Down Expand Up @@ -282,6 +292,7 @@ CMDSEEKBACK=`grep 'CMDSEEKBACK' $PATHDATA/../settings/rfid_trigger_play.conf|tai
# AUDIOVOLMAXLIMIT
# AUDIOVOLMINLIMIT
# AUDIOVOLSTARTUP
# AUDIOVOLBOOT
# VOLCHANGEIDLE
# IDLETIMESHUTDOWN
# POWEROFFCMD
Expand Down Expand Up @@ -314,6 +325,7 @@ echo "AUDIOVOLCHANGESTEP=\"${AUDIOVOLCHANGESTEP}\"" >> "${PATHDATA}/../settings/
echo "AUDIOVOLMAXLIMIT=\"${AUDIOVOLMAXLIMIT}\"" >> "${PATHDATA}/../settings/global.conf"
echo "AUDIOVOLMINLIMIT=\"${AUDIOVOLMINLIMIT}\"" >> "${PATHDATA}/../settings/global.conf"
echo "AUDIOVOLSTARTUP=\"${AUDIOVOLSTARTUP}\"" >> "${PATHDATA}/../settings/global.conf"
echo "AUDIOVOLBOOT=\"${AUDIOVOLBOOT}\"" >> "${PATHDATA}/../settings/global.conf"
echo "VOLCHANGEIDLE=\"${VOLCHANGEIDLE}\"" >> "${PATHDATA}/../settings/global.conf"
echo "IDLETIMESHUTDOWN=\"${IDLETIMESHUTDOWN}\"" >> "${PATHDATA}/../settings/global.conf"
echo "POWEROFFCMD=\"${POWEROFFCMD}\"" >> "${PATHDATA}/../settings/global.conf"
Expand Down
36 changes: 36 additions & 0 deletions scripts/playout_controls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ NOW=`date +%Y-%m-%d.%H:%M:%S`
# setstartupvolume
# getstartupvolume
# setvolumetostartup
# setbootvolume
# getbootvolume
# setvolumetobootvolume
# volumeup
# volumedown
# getchapters
Expand Down Expand Up @@ -560,6 +563,39 @@ case $COMMAND in
echo -e setvol ${AUDIOVOLSTARTUP}\\nclose | nc -w 1 localhost 6600
fi

fi
;;
setbootvolume)
if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi
# if value is greater than wanted maxvolume, set value to maxvolume
if [ ${VALUE} -gt $AUDIOVOLMAXLIMIT ];
then
VALUE=$AUDIOVOLMAXLIMIT;
fi
# write new value to file
echo "$VALUE" > ${PATHDATA}/../settings/Volume_Boot
# create global config file because individual setting got changed
. ${PATHDATA}/inc.writeGlobalConfig.sh
;;
getbootvolume)
if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi
echo ${AUDIOVOLBOOT}
;;
setvolumetobootvolume)
if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi
# check if startup-volume is disabled
if [ "${AUDIOVOLBOOT}" == 0 ]; then
exit 1
else
# set volume level in percent
if [ "${VOLUMEMANAGER}" == "amixer" ]; then
# volume handling alternative with amixer not mpd (2020-06-12 related to ticket #973)
amixer sset \'$AUDIOIFACENAME\' ${AUDIOVOLBOOT}%
else
# manage volume with mpd
echo -e setvol ${AUDIOVOLBOOT}\\nclose | nc -w 1 localhost 6600
fi

fi
;;
playerstop)
Expand Down
11 changes: 10 additions & 1 deletion scripts/startup-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ STATUS=0
while [ "$STATUS" != "ACTIVE" ]; do STATUS=$(echo -e status\\nclose | nc -w 1 localhost 6600 | grep 'OK MPD'| sed 's/^.*$/ACTIVE/'); done

####################################
# check if and set volume on startup
# Set volume levels on boot
# Both can be set in the Web UI under settings
# Confusion explained:
# 1. Set the volume to the global boot level.
# Sometimes the Pi sets volume to 0.
# The first command makes sure there is *some* level, not 0.
# 2. Then set the volume to the startup volume.
# If the kids crank up the volume at night,
# after a reboot, the box will be back to this level.
/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=setvolumetobootvolume
/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=setvolumetostartup

####################
Expand Down

0 comments on commit ce0742c

Please sign in to comment.