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:
#!/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.