The added features within the attached patch:
1) Show current channel for each attached pvrusb2 device. (ie.
change-channel.sh c)
2) Increment or decrement current channel for each pvrusb2 device. (ie.
change-channel.sh + or -)

Modifications:
1) I've also provided more detailed when -h is used.
2) Some other minor syntax corrections were made while trying to
preserve original code & syntax.  (Unless somebody knows of a good
sh/bash style checker???)

Seems to be well tested by me.  Just hope the changes held up after
using diff. (Sigh, the missed miracles of SVN! ;-)

--
Roger
http://www.eskimo.com/~roger/index.html
Key fingerprint = 8977 A252 2623 F567 70CD 1261 640F C963 1005 1D61

Thu Nov 8 14:23:35 AKST 2007
--- change-channel.sh.orig	2007-11-04 12:50:45.000000000 -0900
+++ change-channel.sh	2007-11-08 14:18:29.000000000 -0900
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# $Id: change-channel.sh 1690 2007-11-04 21:50:45Z isely $
+# $Id: change-channel.sh 603 2005-09-22 02:47:18Z isely $
 
 # This sysfs based channel changing script was contributed on
 # 10-Sep-2005 by Per Christian Henden <[EMAIL PROTECTED]>.  Please see
@@ -8,7 +8,6 @@
 # script.  The text of his e-mail describing this script is pasted
 # below:
 
-#
 # Hi,
 #
 # I made a script for changing channels (attached).
@@ -41,41 +40,150 @@
 # script, so make sure you change that to point to your frequency file.
 #
 # -PER
-#
 
+# 2007.11.06  Roger <[EMAIL PROTECTED]>
+#   Added show current channel, channel increment, channel decrement
+#     ie. "change-channel.sh +" or "change-channel.sh -"
+#   Some duplicate code is present and could be modified into functions
+#   However, "mplayer tv://" is on the horizon and this script could be
+#   soon deprecated! :-)
 
 #set -x #debug
 
-FREQUENCY_FILE="/home/perchrh/.tv/freqs"
+#FREQUENCY_FILE=""
+FREQUENCY_FILE="/home/roger/.tv/freqs"
 CHANNELID=$1
 
-#check first if we are root
+# Check first if we are root
 if [ $UID != "0" ]
-   then
+then
    echo "You need to be root to change channels"
    exit
 fi
 
-#check parameters
-if [ $# == "0" ]
+# Check for existing config file
+if [ -a $HOME/.tv/freqs ]
+then
+  FREQUENCY_FILE=$HOME/.tv/freqs
+
+else if [[ $FREQUENCY_FILE = "" ]]
+then
+  echo "No Frequency File Specified"
+  echo
+  echo "You need one of Xawtv's \"*.list\" files, according to your broadcast,"
+  echo "copied and renamed to $HOME/.tv/freqs file"
+  echo
+  exit
+fi
+fi
+
+# Check parameters
+if [ $# == "0" ] || [ $1 == "-h" ]
 then
-   echo "Usage is $0 \<channel id\>"
-   echo "e.g. $0 S10"
-   echo "Use $0 -list to get a list of available channels"
+   echo "Usage: $0 [CHANNEL ID]"
+   echo
+   echo "  +		Increment current channel by +1"
+   echo "  -		Decrement current channel by -1"
+   echo "  c		Show current channel"
+   echo
+   echo "  -h		This help screen"
+   echo "  -list		List of available channels"
+   echo
+   echo "Examples:"
+   echo
+   echo "  Change to channel S10"
+   echo
+   echo "  # $0 S10"
+   echo
+   echo "  Increment channel by +1"
+   echo
+   echo "  # $0 +"
+   echo
    exit
-else if [ $1 == "-list" ]
+fi
+
+# List Available Channels
+if [ $1 == "-list" ]
 then
   echo "Available channels are:"
   grep "\[" $FREQUENCY_FILE|tr -d "[,]"
   exit
 fi
+
+# Show Current Channel
+if [ $1 == "c" ]
+then
+  if [ -x /sys/class/pvrusb2/ ]
+  then
+    # find current frequency on each pvrusb2 device
+    ids=`find /sys/class/pvrusb2/ -maxdepth 1 -mindepth 1 -type d`
+	  for id in $ids
+	  do
+      current_freq=`cat $ids/ctl_frequency/cur_val`
+  
+      # adjust frequency for association with xawtv frequencies
+      current_freq=$(( $current_freq/1000 ))
+
+      # associate freq with a channel
+      CHANNELID=`grep -1 -i "$current_freq" $FREQUENCY_FILE |head -n 1 |tr -d "[]"`
+	  echo "Current Channel $CHANNELID  ($id)"
+	  done
+  fi
+  echo
+  exit
+fi
+
+# Increment Channel
+if [ $1 == "+" ]
+then
+  if [ -x /sys/class/pvrusb2/ ]
+  then
+    # find current frequency on each pvrusb2 device
+    ids=`find /sys/class/pvrusb2/ -maxdepth 1 -mindepth 1 -type d`
+	  for id in $ids
+	  do
+      current_freq=`cat $ids/ctl_frequency/cur_val`
+  
+      # adjust frequency for association with xawtv frequencies
+      current_freq=$(( $current_freq/1000 ))
+
+      # associate freq with a channel and increment channel
+      CHANNELID=`grep -1 -i "$current_freq" $FREQUENCY_FILE |head -n 1 |tr -d "[]"`
+      CHANNELID=$(( $CHANNELID+1 ))
+	  done
+  else
+    echo "PVR USB2 sysfs interface not found"
+  fi
 fi
 
+# Decrement Channel
+if [ $1 == "-" ]
+then
+  if [ -x /sys/class/pvrusb2/ ]
+  then
+    # find current frequency on each pvrusb2 device
+    ids=`find /sys/class/pvrusb2/ -maxdepth 1 -mindepth 1 -type d`
+	  for id in $ids
+	  do
+      current_freq=`cat $ids/ctl_frequency/cur_val`
+  
+      # adjust frequency for association with xawtv frequencies
+      current_freq=$(( $current_freq/1000 ))
+
+      # associate freq with a channel and decrement channel
+      CHANNELID=`grep -1 -i "$current_freq" $FREQUENCY_FILE |head -n 1 |tr -d "[]"`
+      CHANNELID=$(( $CHANNELID-1 ))
+	  done
+  else
+    echo "PVR USB2 sysfs interface not found"
+  fi
+fi
 
+# Change to Specified Channel
 freq=`grep  -1 -i "\[$CHANNELID\]" $FREQUENCY_FILE |tail -n 1|cut -d" " -f 3|tr -d " "`000
 
-#check if we got an empty string returned from grep,
-#that means the channel id was not found
+# check if we got an empty string returned from grep.
+# this means the Channel ID was not found.
 if [ $freq == "000" ]
 then
 echo "Could not find channel with id $CHANNELID"
@@ -84,7 +192,7 @@
 echo "Found frequency $freq for channel $CHANNELID"
 fi
 
-#Change the channel for all pvrusb2 cards to that of $freq
+# change the channel for all pvrusb2 cards to that of $freq
 if [ -x /sys/class/pvrusb2/ ]
 then
 ids=`find /sys/class/pvrusb2/ -maxdepth 1 -mindepth 1 -type d`
_______________________________________________
pvrusb2 mailing list
[email protected]
http://www.isely.net/cgi-bin/mailman/listinfo/pvrusb2

Reply via email to