Active Topics

 



Notices


Reply
Thread Tools
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#61
Indent your code!
Making debs is easy, hit me up with a PM if you have any problems
When you make a deb though you'll have to use sudo, so you should figure out why sudo gainroot doesn't work, prefix dbus and zenity lines with run-standalone.sh

Edit 2: who's # Copyright (c) 2010 OEM LTD (HE99116) #
Edit: indented code, I hate ugly scripts
Code:
#!/bin/sh

# Empty Frequencies Finder, find free/empty frequencies #
#                                                       #
#      Copyright (c) 2010 OEM LTD (HE99116)          #

send_request() 
{
  dbus-send --system --print-reply \
            --dest=de.pycage.FMRXEnabler \
            /de/pycage/FMRXEnabler\
            de.pycage.FMRXEnabler.request >/dev/null
}

find_sysfs_path() 
{
    F=`find /sys/class/i2c-adapter -name "fm_frequency"`
    echo `dirname ${F}`
}

power_on() 
{
    # switch on
    echo 1 >${SYSFS_PATH}/power_state
    # set DAC audio route 
    echo 16 >${SYSFS_PATH}/audio_route
    # set stereo
    echo 12 >${SYSFS_PATH}/dac_output
    # set preset tune mode
    echo 1 >${SYSFS_PATH}/fm_search_tune_mode
    # unmute
    echo 0 >${SYSFS_PATH}/mute
}

power_off() 
{
    echo "POWERED OFF" 
    # mute
    echo 1 >${SYSFS_PATH}/mute
    # switch off
    echo 0 >${SYSFS_PATH}/power_state
}

tune_in()
{
    FREQ=$1
    echo ${FREQ} >${SYSFS_PATH}/fm_frequency
}

change_frq()
{
    send_request
    SYSFS_PATH=`find_sysfs_path`
    power_on
    tune_in $cur_freq 
}


#Temporary file for saving empty frequencies
temp=`mktemp -t temp.XXXXXX`

#Print banner
ver="1.3.1"
zenity --info --text="E.F.F. (Emty Frequencies Finder)" --title="E.F.F-$ver"

#Vars
vars()
{
    max=`expr $max \* 100`
    min=`expr $min \* 100`
    range=`expr $max - $min`
    pers_var=`expr $range / 100`
    cur_freq=$min
    pers_cntr=0
    cnt_total=0
}

#Change testing frequency, calculate percentage of progress
change_tfrq()
{
    if [ $cur_freq -eq $max ] || [ $cur_freq -gt $max ]
        then 
            break
    fi
    pers_cntr=`expr $pers_cntr + 1`
    pers=`expr \( 100 \* $pers_cntr \) / $pers_var`
    cur_freq=`expr $cur_freq + 100`
    cnt=0
    change_frq
    if [ $guiyn -eq 0 ]
        then
            echo $pers
        else
            if [ $pers -lt 100 ]
                then
                    echo "Scanning...Found $cnt_total empty frequencies. $pers %"
                else
                    echo "Scanning...Found $cnt_total empty frequencies. 100 %"
            fi
    fi
    sleep 1
    if [ $guiyn -eq 0 ]
        then
            echo "# Scanning...Found $cnt_total empty frequencies"
    fi
}

#How much empty functions
hempty_a()
{
    if [ $cnt -eq 10 ]
        then
            sleep 1
    fi
}

hempty_b()
{
    if [ $cnt -eq 10 ] || [ $cnt -eq 45 ]
        then
            sleep 1
    fi
}

hempty_c()
{
    if [ $cnt -eq 5 ] || [ $cnt -eq 20 ] || [ $cnt -eq 60 ]
        then
            sleep 1
    fi
}

hempty_d()
{
    if [ $cnt -eq 5 ] || [ $cnt -eq 30 ] || [ $cnt -eq 60 ] || [ $cnt -eq 80 ]
        then
            sleep 1
    fi
}

#Zenity question to be root
quest_root()
{
    rans=$(zenity --entry --entry-text="root" --title="To run you must be root, if you agree type ok." --text="Press OK to continue or cancel to quit.")
    if [ $? -eq 0 ]
        then 
            eval $rans
        else
            zenity --error --text="You must be root!"
            exit 1
    fi
}

#Check if the frequency is empty 
check_frq()
{
    while [ 1 ]
        do
            #unmake the following from comment to is if its working
            #echo "# `cat /sys/class/i2c-adapter/i2c-3/3-0022/fm_frequency` `cat /sys/class/i2c-adapter/i2c-3/3-0022/fm_rssi`"
            #echo "# `echo $hempty $cnt`"
            if [ $cnt -eq `expr 60 * $hempty` ]
                then
                    cnt_total=`expr $cnt_total + 1`
                    msg=1
                    echo $cur_freq >> $temp
                    break
            fi
    case $hempty in
        1)
        hempty_a ;;
        2)
        hempty_b ;;
        3)
        hempty_c ;;
        4)
        hempty_d ;;
    esac
    if [ `cat /sys/class/i2c-adapter/i2c-3/3-0022/fm_rssi` = "-112" ]
        then
            cnt=`expr $cnt + 1`
        else
            break
    fi
    done
}

#Stop with zenity cancell button
zcancel()
{
    if [ $? -eq 1 ]
        then
            power_off
            exit 1
    fi
}

#Mesage on $temp, function
tmsg()
{
    if [ $guiyn -eq 1 ]
        then
            echo "You searched from $min to $max, with $hempty emty value. Found $cnt_total empty frequencies:" 
            cat $temp
        fi
}

#MAIN

if [ `cat /sys/devices/platform/gpio-switch/headphone/state` = "disconnected" ]
    then 
        zenity --error --title="ERROR" --text="Headphones are not pluged in!"
        exit 1
fi

if [ `id -u` = "0" ]
    then
        hempty=$(zenity --scale --min-value=1 --max-value=4 --value=1 --text="Note that higher value requires more scaning time!" --title="Search for: 1=Slightly-empty 2=Empty 3=Very-empty 4=Extremely-empty")
        if [ $? -eq 1 ]
            then
                zenity --error --title="ERROR" --text="You must select a value!Aborting..."
                exit 1
        fi

        min=$(zenity --scale --min-value=875 --max-value=1080 --value=875 --title="Search from:" --text="Select min value (ex. 991=99.1 , 1034=103.4)")
        zcancel
        max=$(zenity --scale --min-value=875 --max-value=1080 --value=875 --title="From $min to:" --text="Select max value (ex. 991=99.1 , 1034=103.4)")
        zcancel
        zenity --question --title="Do you want gui during scanning?" --text="If you type "YES" you will not be able to multitask." --ok-label="YES"

        if [ $? -eq 1 ]
            then
                guiyn=1
            else
                guiyn=0
        fi
        vars
        if [ $min -lt $max ]
            then
                if [ $guiyn -eq 0 ]
                    then
                        (while [ 1 ]
                        do
                        change_tfrq
                        check_frq
                        done
                        ) | zenity --progress --text="Scaning..." --auto-close
                        zcancel
                    else
                        while [ 1 ]
                        do
                        change_tfrq
                        check_frq
                        done
                fi
                tmsg
                zenity --text-info --filename=$temp
                power_off
            else
                zenity --error --text="Max value must be greater than min value!"
        fi 
    else
        zenity --error --text="You must be root!"
fi

Last edited by MohammadAG; 2010-09-29 at 14:52.
 
BLIZZARD's Avatar
Posts: 194 | Thanked: 266 times | Joined on May 2010
#62
@MohammadAG

i will change that line with copyright (a friend of me told me to write that..nonsense). I will butify the script .

GUYS I THING I SOLVED YOUR PROBLEM, TRY THIS:

1.4.0 http://www.mediafire.com/?m5xq81w58n7512v
__________________
I LOVE THESE GAMES: STARCRAFT/STARCRAFT2
I LOVE N900 I LOVE C++ I LOVE UBUNTU
E.F.F, (QT) E.F.F EMPTY FREQUENCIES FINDER, CRAPS, T-CONTROL
 
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#63
Script isn't working, keeps erroring out:
Code:
BusyBox v1.10.2 (Debian 3:1.10.2.legal-1osso30+0m5) multi-call binary

Usage: dirname FILENAME

expr: syntax error
sh: -eq: argument expected
cat: can't open '/sys/class/i2c-adapter/i2c-3/3-0022/fm_rssi': No such file or directory
sh: -112: unknown operand
 
BLIZZARD's Avatar
Posts: 194 | Thanked: 266 times | Joined on May 2010
#64
Originally Posted by MohammadAG View Post
Script isn't working, keeps erroring out:
Code:
BusyBox v1.10.2 (Debian 3:1.10.2.legal-1osso30+0m5) multi-call binary

Usage: dirname FILENAME

expr: syntax error
sh: -eq: argument expected
cat: can't open '/sys/class/i2c-adapter/i2c-3/3-0022/fm_rssi': No such file or directory
sh: -112: unknown operand
Did you tried 1.4.0 ?
__________________
I LOVE THESE GAMES: STARCRAFT/STARCRAFT2
I LOVE N900 I LOVE C++ I LOVE UBUNTU
E.F.F, (QT) E.F.F EMPTY FREQUENCIES FINDER, CRAPS, T-CONTROL
 
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#65
Code:
Nokia-N900:/sys/class/i2c-adapter/i2c-3/3-0022# ls
bus        modalias   name       power      subsystem  uevent
 
BLIZZARD's Avatar
Posts: 194 | Thanked: 266 times | Joined on May 2010
#66
Originally Posted by MohammadAG View Post
Code:
Nokia-N900:/sys/class/i2c-adapter/i2c-3/3-0022# ls
bus        modalias   name       power      subsystem  uevent
Are you talking about 1.4.0?
__________________
I LOVE THESE GAMES: STARCRAFT/STARCRAFT2
I LOVE N900 I LOVE C++ I LOVE UBUNTU
E.F.F, (QT) E.F.F EMPTY FREQUENCIES FINDER, CRAPS, T-CONTROL
 
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#67
Uh, does it matter? The kernel module is responsible on creating those files, not your script.
cat: can't open '/sys/class/i2c-adapter/i2c-3/3-0022/fm_rssi': No such file or directory
Your script tries to read that file ^ which doesn't exist on the stock kernel (or kernels based on it)
 
BLIZZARD's Avatar
Posts: 194 | Thanked: 266 times | Joined on May 2010
#68
Originally Posted by MohammadAG View Post
Uh, does it matter? The kernel module is responsible on creating those files, not your script.
cat: can't open '/sys/class/i2c-adapter/i2c-3/3-0022/fm_rssi': No such file or directory
Your script tries to read that file ^ which doesn't exist on the stock kernel (or kernels based on it)
When you turn on reciever these files are created automattialy. The script works fine on my n900. Tested 1.4.0 on my n900 and works with sudo gainroot too.
__________________
I LOVE THESE GAMES: STARCRAFT/STARCRAFT2
I LOVE N900 I LOVE C++ I LOVE UBUNTU
E.F.F, (QT) E.F.F EMPTY FREQUENCIES FINDER, CRAPS, T-CONTROL
 
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#69
Originally Posted by BLIZZARD View Post
When you turn on reciever these files are created automattialy. The script works fine on my n900. Tested 1.4.0 on my n900 and works with sudo gainroot too.
Not really, which kernel are you on?
Code:
Nokia-N900:/sys/class/i2c-adapter/i2c-3/3-0022# fmtx_client -p1
Usage:
------
-f<uint>    Set frequency (in kHz)
-s<string>    Set RDS station name
-t<string>    Set RDS info text
-p<uint>    Turn fmtx on (1) or off (0)

Current settings (Frequencies in kHz):
--------------------------------------
version=1
frequency=107500
freq_min=76000
freq_max=107900
freq_step=100
state=enabled
rds_ps=Nokia   
rds_text= 
Nokia-N900:/sys/class/i2c-adapter/i2c-3/3-0022# ls
bus        modalias   name       power      subsystem  uevent
 
BLIZZARD's Avatar
Posts: 194 | Thanked: 266 times | Joined on May 2010
#70
Ffmtx_client is for controlling transmitter. I said that when you turn on reciever, these files are created automatically. Try opening FM RADIO app and you will see that the files will be created
I had power kernel installed but i flashed my n900 a week ago.
__________________
I LOVE THESE GAMES: STARCRAFT/STARCRAFT2
I LOVE N900 I LOVE C++ I LOVE UBUNTU
E.F.F, (QT) E.F.F EMPTY FREQUENCIES FINDER, CRAPS, T-CONTROL
 
Reply


 
Forum Jump


All times are GMT. The time now is 17:10.