Skip to content

Commit

Permalink
Add voltage support to -e and -d options
Browse files Browse the repository at this point in the history
  • Loading branch information
VR-25 committed Jul 10, 2022
1 parent 5a63ada commit 4240644
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,11 @@ Options
acc -c less
acc -c cat
-d|--disable [#%, #s, #m or #h (optional)] Disable charging
-d|--disable [#%, #s, #m, #h or #mv (optional)] Disable charging
e.g.,
acc -d 70% (do not recharge until capacity <= 70%)
acc -d 1h (do not recharge until 1 hour has passed)
acc -d 4000mv (do not recharge until battery voltage <= 4000mV)
-D|--daemon Print daemon status, (and if running) version and PID
e.g., acc -D (alias: "accd,")
Expand All @@ -710,10 +711,11 @@ Options
acc -D restart (alias: accd)
accd -D stop (alias: "accd.")
-e|--enable [#%, #s, #m or #h (optional)] Enable charging
-e|--enable [#%, #s, #m, #h or #mv (optional)] Enable charging
e.g.,
acc -e 75% (recharge to 75%)
acc -e 30m (recharge for 30 minutes)
acc -e 4000mv (recharge to 4000mV)
-f|--force|--full [capacity] Charge once to a given capacity (default: 100%), without restrictions
e.g.,
Expand Down
22 changes: 7 additions & 15 deletions install/accd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ! $init; then

_ge_cooldown_cap() {
if t ${capacity[1]} -gt 3000; then
t $(grep -o '^....' $voltage_now) -ge ${capacity[1]}
t $(volt_now) -ge ${capacity[1]}
else
t $(cat $battCapacity) -ge ${capacity[1]}
fi
Expand All @@ -36,7 +36,7 @@ if ! $init; then

_ge_pause_cap() {
if t ${capacity[3]} -gt 3000; then
t $(grep -o '^....' $voltage_now) -ge ${capacity[3]}
t $(volt_now) -ge ${capacity[3]}
else
t $(cat $battCapacity) -ge ${capacity[3]}
fi
Expand All @@ -45,7 +45,7 @@ if ! $init; then

_lt_pause_cap() {
if t ${capacity[3]} -gt 3000; then
t $(grep -o '^....' $voltage_now) -lt ${capacity[3]}
t $(volt_now) -lt ${capacity[3]}
else
t $(cat $battCapacity) -lt ${capacity[3]}
fi
Expand All @@ -54,7 +54,7 @@ if ! $init; then

_gt_resume_cap() {
if t ${capacity[2]} -gt 3000; then
t $(grep -o '^....' $voltage_now) -gt ${capacity[2]}
t $(volt_now) -gt ${capacity[2]}
else
t $(cat $battCapacity) -gt ${capacity[2]}
fi
Expand All @@ -63,7 +63,7 @@ if ! $init; then

_le_resume_cap() {
if t ${capacity[2]} -gt 3000; then
t $(grep -o '^....' $voltage_now) -le ${capacity[2]}
t $(volt_now) -le ${capacity[2]}
else
t $(cat $battCapacity) -le ${capacity[2]}
fi
Expand All @@ -72,7 +72,7 @@ if ! $init; then

_le_shutdown_cap() {
if t ${capacity[0]} -gt 3000; then
t $(grep -o '^....' $voltage_now) -le ${capacity[0]}
t $(volt_now) -le ${capacity[0]}
else
t $(cat $battCapacity) -le ${capacity[0]}
fi
Expand Down Expand Up @@ -347,7 +347,7 @@ if ! $init; then
# warnings
! $shutdownWarnings || {
if t ${capacity[0]} -gt 3000; then
! t $(grep -o '^..' $voltage_now) -eq $(( ${capacity[0]%??} + 1 )) \
! t $(grep -o '^..' $voltNow) -eq $(( ${capacity[0]%??} + 1 )) \
|| ! notif "⚠️ WARNING: ~100mV to auto shutdown, plug the charger!" \
|| sleep ${loopDelay[1]}
else
Expand Down Expand Up @@ -493,14 +493,6 @@ if ! $init; then
src_cfg


voltage_now=$batt/voltage_now
t -f $voltage_now || voltage_now=$batt/batt_vol
if ! t -f $voltage_now; then
echo 3900 > $TMPDIR/.voltage_now
voltage_now=$TMPDIR/.voltage_now
fi


apply_on_boot
touch $TMPDIR/.minCapMax
ctrl_charging
Expand Down
19 changes: 16 additions & 3 deletions install/batt-interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ status() {
}


volt_now() {
grep -o '^....' $voltNow
}


if ${init:-false}; then

for batt in maxfg/capacity */capacity; do
Expand Down Expand Up @@ -130,6 +135,15 @@ if ${init:-false}; then
[ ! -f $currFile ] || break
done


voltNow=$batt/voltage_now
[ -f $voltNow ] || voltNow=$batt/batt_vol
[ -f $voltNow ] || {
echo 3900 > $TMPDIR/.voltage_now
voltNow=$TMPDIR/.voltage_now
}


idleThreshold=95 # mA
ampFactor=$(sed -n 's/^ampFactor=//p' $dataDir/config.txt 2>/dev/null || :)
ampFactor_=${ampFactor:-1000}
Expand All @@ -143,16 +157,15 @@ if ${init:-false}; then
rm $curThen 2>/dev/null || :


echo "
ampFactor_=$ampFactor_
echo "ampFactor_=$ampFactor_
batt=$batt
battCapacity=$batt/capacity
battStatus=$battStatus
currFile=$currFile
curThen=$curThen
idleThreshold=$idleThreshold
temp=$temp
" > $TMPDIR/.batt-interface.sh
voltNow=$voltNow" > $TMPDIR/.batt-interface.sh

init=false

Expand Down
28 changes: 23 additions & 5 deletions install/misc-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ disable_charging() {
*%)
print_charging_disabled_until $1
echo
(until [ $(cat $battCapacity) -le ${1%\%} ]; do
(set +x
until [ $(cat $battCapacity) -le ${1%\%} ]; do
sleep ${loopDelay[1]}
set +x
done)
enable_charging
;;
Expand All @@ -163,6 +163,15 @@ disable_charging() {
esac
enable_charging
;;
*m[vV])
print_charging_disabled_until $1 v
echo
(set +x
until [ $(volt_now) -le ${1%m*} ]; do
sleep ${loopDelay[1]}
done)
enable_charging
;;
*)
print_charging_disabled
;;
Expand Down Expand Up @@ -222,9 +231,9 @@ enable_charging() {
*%)
print_charging_enabled_until $1
echo
(until [ $(cat $battCapacity) -ge ${1%\%} ]; do
sleep ${loopDelay[1]}
set +x
(set +x
until [ $(cat $battCapacity) -ge ${1%\%} ]; do
sleep ${loopDelay[0]}
done)
disable_charging
;;
Expand All @@ -238,6 +247,15 @@ enable_charging() {
esac
disable_charging
;;
*m[vV])
print_charging_enabled_until $1 v
echo
(set +x
until [ $(volt_now) -ge ${1%m*} ]; do
sleep ${loopDelay[0]}
done)
disable_charging
;;
*)
print_charging_enabled
;;
Expand Down
10 changes: 6 additions & 4 deletions install/strings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ print_invalid_switch() {
}

print_charging_disabled_until() {
echo "Charging disabled until battery capacity <= $1"
echo "Charging disabled until battery $([ ${2:-.} = v ] && echo "voltage" || echo "capacity") <= $1"
}

print_charging_disabled_for() {
Expand All @@ -45,7 +45,7 @@ print_charging_disabled() {
}

print_charging_enabled_until() {
echo "Charging enabled until battery capacity >= $1"
echo "Charging enabled until battery $([ ${2:-.} = v ] && echo "voltage" || echo "capacity") >= $1"
}

print_charging_enabled_for() {
Expand Down Expand Up @@ -123,10 +123,11 @@ Options
acc -c less
acc -c cat
-d|--disable [#%, #s, #m or #h (optional)] Disable charging
-d|--disable [#%, #s, #m, #h or #mv (optional)] Disable charging
e.g.,
acc -d 70% (do not recharge until capacity <= 70%)
acc -d 1h (do not recharge until 1 hour has passed)
acc -d 4000mv (do not recharge until battery voltage <= 4000mV)
-D|--daemon Print daemon status, (and if running) version and PID
e.g., acc -D (alias: "accd,")
Expand All @@ -137,10 +138,11 @@ Options
acc -D restart (alias: accd)
accd -D stop (alias: "accd.")
-e|--enable [#%, #s, #m or #h (optional)] Enable charging
-e|--enable [#%, #s, #m, #h or #mv (optional)] Enable charging
e.g.,
acc -e 75% (recharge to 75%)
acc -e 30m (recharge for 30 minutes)
acc -e 4000mv (recharge to 4000mV)
-f|--force|--full [capacity] Charge once to a given capacity (default: 100%), without restrictions
e.g.,
Expand Down

0 comments on commit 4240644

Please sign in to comment.