Author Topic: Successfully created a script to control battery charging behaviour  (Read 1546 times)

forcella

  • Newbie
  • *
  • Posts: 6
    • View Profile
In case that someone wants to limit the charging threshold in Linux (to reduce battery wear), I'd like to post my solution how I did it. In Android, I use the AccA app (https://f-droid.org/en/packages/mattecarra.accapp/) to control the charging behaviour.

To do this with Gemian on cosmo, I wrote this simple script:

Code: [Select]
#!/bin/sh

threshold=70 # stop charging at this percentage threshold

p="$(upower -d|grep -m1 percentage|cut -d: -f2 | tr -d "%")"

if [ "$p" -gt "$threshold" ] ; then
  echo "0 1" > /proc/mtk_battery_cmd/current_cmd
else
  echo "0 0" > /proc/mtk_battery_cmd/current_cmd
fi


When called by cron (root user), the script periodically checks (via upower) whether the battery percentage is higher or lower than the specified threshold, stops charging in the first case and starts charging in the latter. When the charger is plugged off, the device goes into discharging mode as usual and returns into the custom charge mode when the charger is plugged in again.

There is one uncertainty though, I do not know if the cosmo is truly energized directly by the charging cable if charging is paused. In AccA, you can manually enable this option, otherwise the current still takes the detour through the battery. But on the cosmo the app says that the Android kernel is not compiled for this direct power supplying.

Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1266
    • View Profile
Re: Successfully created a script to control battery charging behaviour
« Reply #1 on: January 31, 2022, 04:28:06 am »
Thanks for this script! I believe it will be useful for Gemini users too.
You have also given me some hope in resurrecting my Gemini (only holds battery charge for 10 minutes, tried to replace the battery, reflashed Android, tried also to recalibrate the battery countless times). I have tried many battery apps, now I'll flash a rooted Android and see if AccA will help me understanding what's going on with the recharging circuit.

Varti
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!