User:Kerio/calibratebq27200

This script is supposed to be run overnight; lock the screen brightness at maximum, and disable screen blanking, then run the script, connect the wallcharger and wait. Discharging with the screen at maximum brightness takes about 5 hours, with the standard BL-5J.

THIS SCRIPT NEEDS THE BME REPLACEMENT!

#!/bin/sh

CHARGER_MODE="/sys/class/power_supply/bq24150a-0/mode"

if ! test -w ${CHARGER_MODE} || ! cd /sys/class/power_supply/bq27200-0 ; then
    echo "NOPE.jpg" >&2
    exit 1
fi

# returns success if VDQ is set, otherwise returns fail
vdq () {
    return $(( 1 - ( ( $( grep 0x0a= registers | cut -d= -f2 ) & 4 ) / 4 ) ))
}

# returns success if EDV1 is set, otherwise returns fail
edv1 () {
    return $(( 1 - ( ( $( grep 0x0a= registers | cut -d= -f2 ) & 2 ) / 2 ) ))
}

# lock the screen, as if the user pushed the lock slider
# taken from Phone_control
lock_screen () {
    /usr/bin/dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"locked"
}

print_info () {
    echo -n "$(( $( cat capacity ) ))%   "
    echo -n "VOLT: $(( $( cat voltage_now ) / 1000 )) mV   "
    echo "CUR: $(( $( cat current_now ) / 1000 )) mA"
}

if ! vdq ; then
    echo "Waiting for VDQ, connect the charger."

    while ! vdq ; do
        print_info
        sleep 10
    done
fi

echo "VDQ set, stopping charging and waiting for EDV1."
echo off > ${CHARGER_MODE}

while ! edv1 ; do
    print_info
    sleep 10
done

echo "EDV1 set, restarting charging."
echo auto > ${CHARGER_MODE}

lock_screen