[Desire Android Development] twicejr:
Battery saving enhanced

I modified the original rookeemod-oxygen script, so that you can supply limits in array form, eg:

LIMITS=( [10]=384000 [30]=691200 [50]=806400 [75]=998400)

It is attached to this post :)

First time i used bash, so if it isnt correct, please correct me ;)

#!/system/bin/sh
#
# screenstate_scaling - switch CPU frequency governor on screen state change
# originally by florian.schaefer@gmail.com (FloHimself)
# mod teppic74 / xda - 12/10/2010
# Changelog:
# * Test for battery charging/full - if so, use alternative settings.
# * Allow for alternative frequencies when battery is below 30, 20 and 10%
# Modified by twicejr / xda - 15/01/2011 - made alternative frequencies work with an array, for more dynamic configurability.
# Modifications Copyright 2010
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.

AWAKE_GOVERNOR="interactive"
AWAKE_GOVERNOR_FREQENCY_MAX="1113600"
AWAKE_GOVERNOR_FREQENCY_MIN="245000"
AWAKE_SAMPLING_RATE="40000"
AWAKE_CHARGING_GOVERNOR="interactive"
AWAKE_GOVERNOR_CHARGING_MAX="1113600"
AWAKE_GOVERNOR_CHARGING_MIN="499200"

SLEEP_GOVERNOR="interactive"
# irrelevant max for powersave
SLEEP_GOVERNOR_FREQENCY_MAX="245000"
SLEEP_GOVERNOR_FREQENCY_MIN="245000"

LIMITS=( [10]=384000 [30]=691200 [50]=806400 [75]=998400 )

SETCPU="com.mhuang.overclocking"

(while [ 1 ]
do
LIMIT_REACHED="0"
AWAKE=`cat /sys/power/wait_for_fb_wake`
BSTAT=`cat /sys/class/power_supply/battery/status`
if [ "$BSTAT" = "Charging" ] || [ "$BSTAT" = "Full" ] && [ ! "`pidof $SETCPU`" ]; then
echo $AWAKE_GOVERNOR_CHARGING_MIN > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo $AWAKE_GOVERNOR_CHARGING_MAX > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo $AWAKE_CHARGING_GOVERNOR > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
log -p i -t screenstate_scaling "*** awake ***: $BSTAT - switching CPU frequency governor to -> $AWAKE_CHARGING_GOVERNOR"
elif [ $AWAKE = "awake" ] && [ ! "`pidof $SETCPU`" ]; then
echo $AWAKE_GOVERNOR_FREQENCY_MIN > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo $AWAKE_GOVERNOR > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
BATT=`cat /sys/class/power_supply/battery/capacity`
for PERCENTAGE in ${!LIMITS[@]} ;
do
if [ $BATT -lt $PERCENTAGE ]; then
echo ${LIMITS[$PERCENTAGE]} > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
LIMIT_REACHED="1"
break
fi
done
if [ $LIMIT_REACHED = "0"]
echo $AWAKE_GOVERNOR_FREQENCY_MAX > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi
if [ $AWAKE_GOVERNOR = "ondemand" ]; then
echo $AWAKE_SAMPLING_RATE > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
fi
log -p i -t screenstate_scaling "*** awake ***: switching CPU frequency governor to -> $AWAKE_GOVERNOR"
AWAKE=
fi
SLEEPING=`cat /sys/power/wait_for_fb_sleep`
if [ $SLEEPING = "sleeping" ] && [ ! "`pidof $SETCPU`" ]; then
echo $SLEEP_GOVERNOR_FREQENCY_MIN > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo $SLEEP_GOVERNOR_FREQENCY_MAX > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo $SLEEP_GOVERNOR > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
log -p i -t screenstate_scaling "*** sleeping ***: switching CPU frequency governor to -> $SLEEP_GOVERNOR"
SLEEPING=
fi
done &)