Skip to content

Commit

Permalink
Add configurable idleThreshold, and update idle mode information
Browse files Browse the repository at this point in the history
  • Loading branch information
VR-25 committed Jul 30, 2022
1 parent 31c96ff commit 305db14
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ In interactive mode, it also asks the user whether they want to download and ins
```
#DC#
configVerCode=202207250
configVerCode=202207300
ampFactor=
battStatusWorkaround=true
Expand All @@ -249,6 +249,7 @@ cooldownRatio=()
currentWorkaround=false
dischargePolarity=
forceOff=false
idleThreshold=40
language=en
offMid=true
prioritizeBattIdleMode=true
Expand Down Expand Up @@ -377,6 +378,8 @@ runCmdOnPause=''
# forceOff=force_off=BOOLEAN
# idleThreshold=idle_threshold=MILLIAMPS
# language=lang=LANGUAGE_CODE NULLABLE
# maxChargingCurrent=max_charging_current=(MILLIAMPS CTRL_FILE1::RAW_VALUE::DEFAULT CTRL_FILE2::RAW_VALUE::DEFAULT...)
Expand Down Expand Up @@ -420,6 +423,7 @@ runCmdOnPause=''
# current_workaround cw
# discharge_polarity dp
# force_off fo
# idle_threshold it
# lang l
# max_charging_current mcc
# max_charging_voltage mcv
Expand Down Expand Up @@ -576,6 +580,10 @@ runCmdOnPause=''
# Some people "systemlessly" disable certain thermal daemons with Magisk. While this is not a general recommendation, they swear by it.
# idle_threshold (it) # Default: 40
# Current threshold (absolute value) in milliamps to consider _status=Idle.
# lang (l) # Default: en
# Display language, when null, English (en) is assumed.
Expand Down Expand Up @@ -1483,7 +1491,11 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu
It's the ability of running off the charger.
The battery behaves as if it were physically disconnected from the device.
The primary indicator of idle mode is charging current within -11 and 11 milliamps.
The primary indicator of idle mode is charging current around 0 mA. One can customize idleThreshold (absolute value).

Idle mode is great for extended device use (e.g., GPS navigation, gaming, server). Use it when the charger must be plugged for a long time (or permanently).

IMPORTANT: lithium batteries have the longest lifespan when kept about 40-60% charged (about 3.7-3.9ish Volts). That said, try not to use idle mode above 60% too often.

Not all devices support the "native" idle mode. Hence, variants of "emulated" idle mode are available:

Expand All @@ -1495,7 +1507,6 @@ Notes

- In idle mode, the battery does discharge, although very slowly. The same happens to a battery that is sitting on a shelf.
- In emulated idle mode, the battery tends to hold its charge, since it works as a "passthrough" device. Imagine pouring water into a glass that is already full.
- Regardless of the variant, idle mode is not recommended for highly charged batteries. Ideally, battery level shall be around 40-60%, and/or voltage between 3.7-3.9ish Volts.


> How do I enable "smart charging"?
Expand Down
27 changes: 15 additions & 12 deletions install/batt-interface.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
idle_discharging() {
[ $curThen != null ] && [ ${curNow#-} -le $idleThreshold ] && _status=Idle || {
case "${dischargePolarity-}" in
+) [ $curNow -ge 0 ] && _status=Discharging || _status=Charging;;
-) [ $curNow -lt 0 ] && _status=Discharging || _status=Charging;;
*) [ $curThen = null ] || {
tt "$curThen,$curNow" "-*,[0-9]*|[0-9]*,-*" && _status=Discharging || _status=Charging
};;
esac
[ ${curNow#-} -gt $idleThreshold ] || {
_status=Idle
return 0
}
case "${dischargePolarity-}" in
+) [ $curNow -ge 0 ] && _status=Discharging || _status=Charging;;
-) [ $curNow -lt 0 ] && _status=Discharging || _status=Charging;;
*) [ $curThen = null ] || {
tt "$curThen,$curNow" "-*,[0-9]*|[0-9]*,-*" && _status=Discharging || _status=Charging
};;
esac
}


Expand All @@ -17,11 +19,15 @@ not_charging() {
local nci=${nci:-15}
local switch=${flip-}; flip=
local curThen=$(cat $curThen)
local idleThreshold=$idleThreshold
local battStatusOverride="${battStatusOverride-}"
local battStatusWorkaround=${battStatusWorkaround-}

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

[ $currFile = $TMPDIR/.dummy-curr ] && battStatusWorkaround=false || {
[ ${ampFactor:-$ampFactor_} -eq 1000 ] || idleThreshold=${idleThreshold}000
}

if [ -z "${battStatusOverride-}" ] && [ -n "$switch" ]; then
for i in $(seq $nci); do
Expand Down Expand Up @@ -143,13 +149,11 @@ if ${init:-false}; then
}


idleThreshold=11 # mA
ampFactor=$(sed -n 's/^ampFactor=//p' $dataDir/config.txt 2>/dev/null || :)
ampFactor_=${ampFactor:-1000}

if [ $ampFactor_ -eq 1000000 ] || [ $(sed s/-// $currFile) -ge 16000 ]; then
ampFactor_=1000000
idleThreshold=${idleThreshold}000
fi

curThen=$TMPDIR/.curr
Expand All @@ -162,7 +166,6 @@ battCapacity=$batt/capacity
battStatus=$battStatus
currFile=$currFile
curThen=$curThen
idleThreshold=$idleThreshold
temp=$temp
voltNow=$voltNow" > $TMPDIR/.batt-interface.sh

Expand Down
10 changes: 9 additions & 1 deletion install/default-config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configVerCode=202207250
configVerCode=202207300

ampFactor=
battStatusWorkaround=true
Expand All @@ -8,6 +8,7 @@ cooldownRatio=()
currentWorkaround=false
dischargePolarity=
forceOff=false
idleThreshold=40
language=en
offMid=true
prioritizeBattIdleMode=true
Expand Down Expand Up @@ -136,6 +137,8 @@ runCmdOnPause=''

# forceOff=force_off=BOOLEAN

# idleThreshold=idle_threshold=MILLIAMPS

# language=lang=LANGUAGE_CODE NULLABLE

# maxChargingCurrent=max_charging_current=(MILLIAMPS CTRL_FILE1::RAW_VALUE::DEFAULT CTRL_FILE2::RAW_VALUE::DEFAULT...)
Expand Down Expand Up @@ -179,6 +182,7 @@ runCmdOnPause=''
# current_workaround cw
# discharge_polarity dp
# force_off fo
# idle_threshold it
# lang l
# max_charging_current mcc
# max_charging_voltage mcv
Expand Down Expand Up @@ -335,6 +339,10 @@ runCmdOnPause=''
# Some people "systemlessly" disable certain thermal daemons with Magisk. While this is not a general recommendation, they swear by it.


# idle_threshold (it) # Default: 40
# Current threshold (absolute value) in milliamps to consider _status=Idle.


# lang (l) # Default: en
# Display language, when null, English (en) is assumed.

Expand Down
1 change: 1 addition & 0 deletions install/print-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cooldown_temp=${temperature[0]}
current_workaround=$currentWorkaround
discharge_polarity=$dischargePolarity
force_off=$forceOff
idle_threshold=$idleThreshold
lang=$language
max_temp=${temperature[1]}
Expand Down
2 changes: 2 additions & 0 deletions install/write-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ct=${cooldown_temp-${ct-${temperature[0]}}}
cw=${current_workaround-${cw-$currentWorkaround}}
dp="${discharge_polarity-${dp-$dischargePolarity}}"
fo="${force_off-${fo-$forceOff}}"
it="${idle_threshold-${it-$idleThreshold}}"
l=${lang-${l-${language}}}
mcc="${max_charging_current-${mcc-${maxChargingCurrent[@]}}}"
mcv="${max_charging_voltage-${mcv-${maxChargingVoltage[@]}}}"
Expand Down Expand Up @@ -59,6 +60,7 @@ cooldownRatio=($cch $cp)
currentWorkaround=${cw:-false}
dischargePolarity=$dp
forceOff=${fo:-false}
idleThreshold=${it:-40}
language=${lang:-en}
offMid=${om:-true}
prioritizeBattIdleMode=${pbim:-true}
Expand Down

0 comments on commit 305db14

Please sign in to comment.