PiRadio
\r\n";
echo "\r\n";
} elseif ($msg == "reboot") {
$end = shell_exec('sudo ./scripts/reboot.sh');
/* UWAGA! Folder z plikami uruchamianymi przez sudo
musi byc dopisany w pliku /etc/sudoers */
echo "Reboot in progress.
\r\n";
echo "Wait!
\r\n";
echo "\r\n";
} elseif ($msg == "audio") {
$selected = $_POST['output'];
$hda = $_POST['hda'];
$output_old = $_POST['output_old'];
$hda_old = $_POST['hda_old'];
if (isset($selected)) {
if ( ($selected == $output_old) and ($hda == $hda_old) ) {
echo "No changes in audio output configuration.
\r\n";
echo "\r\n";
} else {
$end = shell_exec('sudo ./scripts/get_audio_info.sh');
$lines = explode(PHP_EOL, $end);
if (count($lines) < 4 ) {
echo "There is only ONE audio output in Your PiRadio!
";
$selected = 'internal';
}
// Set default mixer and device names for internal audio
$mixer = "PCM";
$device = "Internal audio device";
// Set default volume limits for internal audio (HQ)
$volume_min = 35;
$volume_max = 95;
// Prepare pwm parameter
$pwm = ( $hda == 'hdaudio') ? "2" : "1";
if ( $pwm == '1') {
// Default volume limits for internal audio (SQ)
$volume_min = 40;
$volume_max = 100;
}
// If external USB audio selected
if ( $selected == 'usb' ) {
// Default volume limit for USB device
$volume_min = 0;
$volume_max = 100;
// Check number of USB card
preg_match('/bcm2835/', $lines[0], $matches);
$usbline = (isset($matches[0])) ? 2 : 0;
// strange !!!
preg_match("/\[(.*?)\]/", $lines[$usbline], $matches);
$device = $matches[1];
preg_match("/\'(.*?)\'/", $lines[$usbline + 1], $matches);
$mixer = $matches[1];
}
echo "New audio device settings.
";
echo "
Device: ".$device."
";
echo "Mixer: ".$mixer."
";
echo "Internal audio high quality mode: ";
if ( $pwm == 2 ) {
echo "Yes";
} else {
echo "No";
}
echo "
";
$piradio = file_get_contents( "/etc/radiod.conf" );
$piradio_new = preg_replace("/\nvolume_min *= *.*/", "\nvolume_min=".$volume_min, $piradio);
$piradio_new = preg_replace("/\nvolume_max *= *.*/", "\nvolume_max=".$volume_max, $piradio_new);
$piradio_array = parse_ini_string($piradio_new);
$volume_min = ($piradio_array['volume_min']);
$volume_max = ($piradio_array['volume_max']);
echo "Volume limits:
";
echo "";
echo "min: ".$volume_min."
";
echo "max: ".$volume_max."
";
file_put_contents('/etc/radiod.conf', $piradio_new);
chmod("/etc/radiod.conf", 0755);
echo "
";
$end = shell_exec('sudo ./scripts/set_audio.sh '.$selected.' '.$mixer.' '.$pwm );
echo "Reboot in progress.
\r\n";
echo "Wait!
\r\n";
echo "\r\n";
}
} else {
echo "Audio output device not selected.
\r\n";
echo "\r\n";
}
} elseif ($msg == "remote") {
$selected = $_POST['remote'];
if (isset($selected)) {
$remote = file_get_contents( "/usr/share/radio/hardware/remotes/".$selected );
preg_match('/\n# *brand: *.*/', $remote, $matches);
$remotename = preg_replace("/\n# *brand: */", "", $matches[0]);
echo "Selected ".$remotename." remote controller.
\r\n";
$end = shell_exec('sudo ./scripts/set_remote.sh '.$selected );
echo "Reboot in progress.
\r\n";
echo "Wait!
\r\n";
echo "\r\n";
} else {
echo "Remote controller not selected.
\r\n";
echo "\r\n";
}
} elseif ($msg == "stations") {
$option = $_POST['submit'];
if ($option == "new") {
echo "New stations list:\r\n";
$stations = $_POST['stations'];
if ($stations[0] == "#") {
$stations = "\r\n".$stations;
}
$stations_tmp = preg_replace("/\n#.*/", "", $stations);
echo "".htmlspecialchars($stations_tmp)."
";
file_put_contents('/var/lib/radiod/stationlist_new', $stations);
chmod("/var/lib/radiod/stationlist_new", 0755);
echo "\r\n";
echo '