View Single Post
slavikko's Avatar
Posts: 20 | Thanked: 15 times | Joined on Nov 2009 @ Turku, Finland
#100
Wrote the following quick & dirty script to use with desktop-cmd-exec

Create a file with the following code to /usr/local/bin/toggleradio.sh

Code:
#!/bin/bash
fmtx_client|grep disabled > /dev/null
if [ $? -eq 0 ]; then
   fmtx_client -p 1 > /dev/null
   fmtx_client -f 106900 > /dev/null
   echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/power_level
   echo "RF Enabled @106.90 with power `cat /sys/class/i2c-adapter/i2c-2/2-0063/power_level`"
else
   fmtx_client -p 0
   echo "RF Disabled"
fi
exit 0
chmod 755 /usr/local/bin/toggleradio.sh
add
Code:
user ALL = NOPASSWD: /usr/local/bin/toggleradio.sh
to /etc/sudoers

This will enable the rf transmitter if it's disabled and raise the power and disabled it if it's enabled. Configure desktop-cmd-exec to run it on click. The command line to insert to desktop-cmd-exec is 'sudo /usr/local/bin/toggleradio.sh'

Note, needs bash which you can get by
Code:
apt-get install bash
NOTE: there's seemingly a bug in the desktop-cmd-exec right now which causes it to run the script when you return to the desktop even though it's set to run on-click. I contacted the dev and hope that it'll be sorted out soon.

Made a new version of the script that's not dependent on bash & has some optional parameters to set the xmit power / freq
Code:
#!/bin/sh
#N900 FM transmitter toggler

#Establishing funtions
enableFM () {
   fmtx_client -p1 > /dev/null
   if [ $freq ]; then
        fmtx_client -f$freq > /dev/null
   fi
   echo $power > /sys/class/i2c-adapter/i2c-2/2-0063/power_level
   freq=`fmtx_client |grep frequency=|awk '{print int(substr($1,11))/1000};'`
   echo "RF Enabled @"$freq" with power `cat /sys/class/i2c-adapter/i2c-2/2-0063/power_level`"
   return 0
}

disableFM () {
   fmtx_client -p 0 > /dev/null
   echo "RF Disabled"
   return 0
}

usage () {
        echo "Usage:"
        echo " By default the script sets the power to 118 and does not mess with your default frequency, if you just run it."
        echo " Optional parameter one let's you define the transmission power manually"
        echo " Optional parameter two let's you define the frequency manually (eg. 106900 for 106.9)"
 exit 0
}



#Very simple command line parsing
case "$1" in
        [0-9]* )        power=$1;;
        [A-Za-z\-]* )   usage;;
        * )             power=118;;
esac
case "$2" in
        [0-9]* )        freq=$2;;
        * )
esac

fmtx_client|grep disabled > /dev/null
if [ $? = 0 ]; then
  enableFM
else
  disableFM
fi
exit 0

Last edited by slavikko; 2010-01-04 at 14:20. Reason: and again a new version with better command line parsing.
 

The Following 8 Users Say Thank You to slavikko For This Useful Post: