Skip to content

Commit

Permalink
Battery status workaround enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
VR-25 committed Jun 19, 2022
1 parent 3c988ff commit b1b02c3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 61 deletions.
16 changes: 14 additions & 2 deletions install/acc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ test_charging_switch() {
chargingSwitch=($@)

echo
echo "${chargingSwitch[@]}"
[ -n "${swCount-}" ] \
&& echo "$swCount/$swTotal: ${chargingSwitch[@]}" \
|| echo "${chargingSwitch[@]}"
flip_sw off

$blacklisted && {
Expand All @@ -152,10 +154,16 @@ test_charging_switch() {

if ! $failed && ! not_charging; then
print_switch_works
echo " idleMode=$idleMode"
echo " battIdleMode=$idleMode"
$idleMode && return 15 || return 0
else
print_switch_fails
! not_charging >/dev/null || {
print_resume
while not_charging; do #TODO
sleep 1
done
}
return 10
fi
}
Expand Down Expand Up @@ -523,11 +531,14 @@ case "${1-}" in
exit
fi
}
swCount=1
swTotal=$(wc -l ${1-$TMPDIR/ch-switches} | cut -d ' ' -f 1)
while read _chargingSwitch; do
echo "x$_chargingSwitch" | grep -Eq '^x$|^x#' && continue
[ -f "$(echo "$_chargingSwitch" | cut -d ' ' -f 1)" ] && {
{ test_charging_switch $_chargingSwitch; echo $? > $TMPDIR/.exitCode; } \
| tee -a /sdcard/Download/acc-t_output-${device}.log
swCount=$((swCount + 1))
exitCode_=$(cat $TMPDIR/.exitCode)
if [ -n "$parsed" ] && [ $exitCode_ -ne 10 ]; then
grep -q "^$_chargingSwitch$" $_parsed 2>/dev/null \
Expand All @@ -551,6 +562,7 @@ case "${1-}" in
esac

print_acct_info
echo
exit $exitCode
;;

Expand Down
2 changes: 1 addition & 1 deletion install/batt-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ batt_info() {
if [ -z "$factor" ]; then
case $1 in
0) factor=1;;
*) [ $1 -le 15000 ] && factor=1000 || factor=1000000;;
*) [ $1 -lt 16000 ] && factor=1000 || factor=1000000;;
esac
fi
}
Expand Down
73 changes: 37 additions & 36 deletions install/batt-interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ discharging() {


idle() {
#grep -iq 'Not charging' $battStatus || {
[ $curThen != null ] && {
if $plusChgPolarity; then
[ $curNow -ge -$idleThresholdL ] && [ $curNow -le $idleThresholdH ]
else
[ $curNow -le $idleThresholdL ] && [ $curNow -ge -$idleThresholdH ]
fi
} || return 1
#}
[ $curThen != null ] && {
if $_dischargePolarity; then
[ $curNow -ge -$idleThresholdL ] && [ $curNow -le $idleThresholdH ]
else
[ $curNow -le $idleThresholdL ] && [ $curNow -ge -$idleThresholdH ]
fi
} || return 1
_status=Idle
}

Expand All @@ -24,36 +22,34 @@ not_charging() {
local i=
local off=${flip-}; flip=
local curThen=$(cat $curThen)
local plusChgPolarity=true
local seqCount=${seqCount:-16} ###
local seqCount=${seqCount:-16}
local battStatusOverride="${battStatusOverride-}"
local battStatusWorkaround=${battStatusWorkaround-}

case "${dischargePolarity-}" in
+) plusChgPolarity=false;;
-) :;;
*) [ $curThen != null ] && [ $curThen -lt 0 ] && plusChgPolarity=false || :;;
+) _dischargePolarity=false;;
-) _dischargePolarity=true;;
esac

tt "${chargingSwitch[$*]-}" "*\ --" || battStatusOverride=
[ $currFile != $TMPDIR/.dummy-curr ] || battStatusWorkaround=false

if [ -z "${battStatusOverride-}" ] && [ -n "$off" ]; then
[ $off = off ] && off=true || off=false
if [ $currFile = $TMPDIR/.dummy-curr ] || [ -z "${_dischargePolarity-}" ]; then
battStatusWorkaround=false
fi

if [ -z "${battStatusOverride-}" ] && [ "$off" = off ]; then
for i in $(seq $seqCount); do
if $off; then
! status ${1-} || return 0
[ $i -lt 5 ] || {
if $plusChgPolarity; then
[ $(cat $currFile) -lt $((curThen / 100 * 90)) ] || return 1
else
[ $(cat $currFile) -gt $((curThen / 100 * 90)) ] || return 1
fi
}
else
status ${1-} || return 1
! status ${1-} || return 0
if $battStatusWorkaround && [ $i -ge 5 ]; then
if $_dischargePolarity; then
[ $(cat $currFile) -lt $((curThen / 100 * 90)) ] || return 1
else
[ $(cat $currFile) -gt $((curThen / 100 * 90)) ] || return 1
fi
fi
[ $i = $seqCount ] || sleep 1
done
$off && return 1 || return 0
return 1
else
status ${1-}
fi
Expand All @@ -66,7 +62,7 @@ status() {
local curNow=$(cat $currFile)

_status=$(sed 's/Not charging/Idle/' $battStatus)
[ -z "${exitCode_-}" ] || echo " curr=$curThen,$curNow off=${off:-false} status=$_status"
[ -z "${exitCode_-}" ] || echo " curr:$curThen,$curNow switch:${off:-on} status:$_status"

if [ -n "${battStatusOverride-}" ]; then
if tt "$battStatusOverride" "Discharging|Idle"; then
Expand All @@ -75,11 +71,9 @@ status() {
_status=$(set -eu; eval '$battStatusOverride') || :
fi
elif $battStatusWorkaround; then
#idle || discharging || :
case $_status in
Charging) idle || discharging || :;;
Discharging) idle || :;;
esac
! tt "$_status" "Charging|Discharging" || {
idle || discharging || :
}
fi

for i in Discharging DischargingDischarging Idle IdleIdle; do
Expand Down Expand Up @@ -138,11 +132,18 @@ if ${init:-false}; then
rm $curThen 2>/dev/null || :


case "$(cat $battStatus)$(cat $currFile)" in
Discharging-*|Charging[0-9]*) _dischargePolarity=true;;
Discharging[0-9]*|Charging-*) _dischargePolarity=false;;
esac


echo "
_dischargePolarity=$_dischargePolarity
ampFactor_=$ampFactor_
batt=$batt
battCapacity=$batt/capacity
battStatus=\"$battStatus\"
battStatus=$battStatus
currFile=$currFile
curThen=$curThen
idleThresholdL=$idleThresholdL
Expand Down
11 changes: 1 addition & 10 deletions install/misc-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,7 @@ flip_sw() {
fi
}

[ $flip = on ] || {
# cn=$(cat $currFile)
# ct=$(cat $curThen)
# case $ct in
# -*) [ $cn -lt $ct ] || ct=n;;
# [0-9]*) [ $cn -gt $ct ] || ct=n;;
# esac
# [ $ct = n ] || cat $currFile > $curThen
cat $currFile > $curThen
}
[ $flip = on ] || cat $currFile > $curThen

write \$$flip $1 || return 1

Expand Down
19 changes: 13 additions & 6 deletions install/strings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,17 @@ print_acct_info() {
echo "
💡Notes/Tips:
- Some switches -- notably those that control current and voltage -- are prone to inconsistencies. If a switch works at least twice, assume it's functional.
Some switches -- notably those that control current and voltage -- are prone to inconsistencies. If a switch works at least twice, assume it's functional.
- Results may vary with different power supplies and conditions, as stated in \"readme > troubleshooting > charging switch\".
Results may vary with different power supplies and conditions, as stated in \"readme > troubleshooting > charging switch\".
- Want to test all potential switches? \"acc -t p\" parses them from the power supply log (as \"acc -p\"), tests all, and adds the working ones to the list of known switches.
Want to test all potential switches? \"acc -t p\" parses them from the power supply log (as \"acc -p\"), tests all, and adds the working ones to the list of known switches.
- To set charging switches, run acc -ss (wizard) or acc -s s=\"switches go here --\".
To set charging switches, run acc -ss (wizard) or acc -s s=\"switches go here --\".
- idleMode: whether the device can run directly off the charger.
battIdleMode: whether the device can run directly off the charger.
- The output of this command is saved to /sdcard/Download/acc-t_output-${device}.log."
The output of this command is saved to /sdcard/Download/acc-t_output-${device}.log."
}


Expand All @@ -523,3 +523,10 @@ Some problematic control files are blacklisted automatically, based on known pat
Do you want to see/edit the list of potential switches before testing?
a: abort operation | n: no | y: yes (default) "
}


print_resume() {
echo " Waiting for charging to resume..."
echo " If it's not happening, try re-plugging the charger."
echo " In extreme cases, one shall comment out this switch in $dataDir/logs/write.log, reboot, and re-run the test."
}
12 changes: 6 additions & 6 deletions install/translations/tr/strings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -504,19 +504,19 @@ print_acct_info() {
echo "
💡Notlar/Tavsiyeler:
- Bazı portlar -- özellikle akım ve voltaj kontrol edenlerde -- dengesizlikler kaçınılmaz. Eğer bir port en az iki kere çalıştıysa, iş gördüğünü
Bazı portlar -- özellikle akım ve voltaj kontrol edenlerde -- dengesizlikler kaçınılmaz. Eğer bir port en az iki kere çalıştıysa, iş gördüğünü
varsayın.
- Sonuçlar farklı koşullara ve güç kaynaklarına göre değişebilir, \"readme > troubleshooting > charging switch\" kısmında da bahsedildiği gibi.
Sonuçlar farklı koşullara ve güç kaynaklarına göre değişebilir, \"readme > troubleshooting > charging switch\" kısmında da bahsedildiği gibi.
- Bütün portları test mi etmek istiyorsunuz? \"acc -t p\" güç kaynağı loglarından hepsini alıyor (as \"acc -p\"), test ediyor, ve çalışanları bilindik
Bütün portları test mi etmek istiyorsunuz? \"acc -t p\" güç kaynağı loglarından hepsini alıyor (as \"acc -p\"), test ediyor, ve çalışanları bilindik
portlar listesine ekliyor.
- Şarj portlarını test etmek için, acc -ss (asistan) veya acc -s s=\"portlar buraya yazılıyor --\" kodlarını çalıştırın.
Şarj portlarını test etmek için, acc -ss (asistan) veya acc -s s=\"portlar buraya yazılıyor --\" kodlarını çalıştırın.
- idleMod: cihazın yalnızca şarjdan beslenerek çalışıp/çalışamayacağını ifade eder.
battIdleMode: cihazın yalnızca şarjdan beslenerek çalışıp/çalışamayacağını ifade eder.
- Bu komutun çıktısı /sdcard/Download/acc-t_output.txt dizinine kaydedilir."
Bu komutun çıktısı /sdcard/Download/acc-t_output.txt dizinine kaydedilir."
}


Expand Down

0 comments on commit b1b02c3

Please sign in to comment.