[pvrusb2] Text user interface to /sys settings
Phil Endecott
spam_from_pvrusb2 at chezphil.org
Tue Feb 7 14:12:24 CST 2006
Dear All,
I have just cooked up the enclosed script which attempts to provide a
text-mode user interface to the PVRUSB2 settings in /sys. It uses the
"dialog" program to display menus; this is a standard thing in Debian
(it is used by the debconf programs during package installation); other
distributions may or may not have it, and may have incompatible
versions. The best bet is to build from the Debian source code.
Note that I have not actually used this on my PVRSUB2 yet, since it
doesn't work properly with my Debian system. Maybe someone can test it?
Cheers,
Phil.
#!/bin/sh
# pvrui.sh: PVRUSB2 control program.
# Uses the dialog program to display menus.
# Written by Phil Endecott, Feb 2006.
# This code is in the public domain; do whatever you like with it.
sysclassroot=/sys/class/pvrusb2
progtitle="PVRUSB2 Settings"
dialogout=`mktemp`
trap "rm $dialogout" 0
ndevices=`ls $sysclassroot 2>/dev/null | wc -l`
case $ndevices in
0) echo "No pvrusb2 devices found" ; exit 1 ;;
1) device=`ls $sysclassroot` ;;
*) devices=`ls $sysclassroot`
devicelist=
for dev in $devices
do
devicelist="$devicelist $dev $dev"
done
dialog \
--backtitle "$progtitle" \
--no-cancel \
--menu "Select device:" \
0 0 0 \
$devicelist \
2>$dialogout
returncode=$?
case $returncode in
1) exit 1 ;;
0) read device < $dialogout || true ;;
esac ;;
esac
cd $sysclassroot/$device
while true
do
controllist=""
for setting in ctl_*
do
name=`cat $setting/name`
cur_val=`cat $setting/cur_val`
controllist="$controllist '$name' '$cur_val'"
done
eval "dialog \
--backtitle '$progtitle' \
--cancel-label 'Exit' \
--menu 'Settings for $device' \
0 0 0 \
$controllist" \
2>$dialogout
returncode=$?
case $returncode in
1) exit 1 ;;
0) read choice < $dialogout || true
esac
for setting in ctl_*
do
name=`cat $setting/name`
if [ "$name" == "$choice" ]
then
break
fi
done
if [ -f "$setting/enum_val" ]
then
enums=""
for enum in `cat $setting/enum_val`
do
enums="$enums '$enum' ''"
done
current=`cat $setting/cur_val`
eval "dialog \
--backtitle '$progtitle' \
--default-item '$current' \
--menu '$device: $choice' \
0 0 0 \
$enums" \
2>$dialogout
returncode=$?
case $returncode in
1) ;;
0) read value < $dialogout || true
echo $value > $setting/cur_val
esac
else
dialog \
--backtitle "$progtitle" \
--form "$device: $choice" \
0 0 0 \
"Min" 1 1 `cat $setting/min_val` 1 20 0 0 \
"Max" 2 1 `cat $setting/max_val` 2 20 0 0 \
"Current" 3 1 `cat $setting/cur_val` 3 20 12 0 \
2>$dialogout
returncode=$?
case $returncode in
1) ;;
0) read value < $dialogout || true
echo $value > $setting/cur_val
esac
fi
done
More information about the pvrusb2
mailing list