From 424064492151f711403f9cf22efdc2ee7561743b Mon Sep 17 00:00:00 2001 From: VR-25 <28943176+VR-25@users.noreply.github.com> Date: Sun, 10 Jul 2022 13:32:53 +0100 Subject: [PATCH] Add voltage support to -e and -d options --- README.md | 6 ++++-- install/accd.sh | 22 +++++++--------------- install/batt-interface.sh | 19 ++++++++++++++++--- install/misc-functions.sh | 28 +++++++++++++++++++++++----- install/strings.sh | 10 ++++++---- 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d798c61..219eb03 100644 --- a/README.md +++ b/README.md @@ -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,") @@ -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., diff --git a/install/accd.sh b/install/accd.sh index 6312b67..31e302e 100644 --- a/install/accd.sh +++ b/install/accd.sh @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/install/batt-interface.sh b/install/batt-interface.sh index 77f2659..a4bf62b 100644 --- a/install/batt-interface.sh +++ b/install/batt-interface.sh @@ -97,6 +97,11 @@ status() { } +volt_now() { + grep -o '^....' $voltNow +} + + if ${init:-false}; then for batt in maxfg/capacity */capacity; do @@ -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} @@ -143,8 +157,7 @@ if ${init:-false}; then rm $curThen 2>/dev/null || : - echo " -ampFactor_=$ampFactor_ + echo "ampFactor_=$ampFactor_ batt=$batt battCapacity=$batt/capacity battStatus=$battStatus @@ -152,7 +165,7 @@ currFile=$currFile curThen=$curThen idleThreshold=$idleThreshold temp=$temp -" > $TMPDIR/.batt-interface.sh +voltNow=$voltNow" > $TMPDIR/.batt-interface.sh init=false diff --git a/install/misc-functions.sh b/install/misc-functions.sh index abc6e98..ecaa84d 100644 --- a/install/misc-functions.sh +++ b/install/misc-functions.sh @@ -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 ;; @@ -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 ;; @@ -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 ;; @@ -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 ;; diff --git a/install/strings.sh b/install/strings.sh index 23f2cc2..3a4cd02 100644 --- a/install/strings.sh +++ b/install/strings.sh @@ -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() { @@ -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() { @@ -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,") @@ -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.,