PINE64
Detecting when charging and discharging - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: PinePhone (https://forum.pine64.org/forumdisplay.php?fid=120)
+--- Forum: PinePhone Software (https://forum.pine64.org/forumdisplay.php?fid=121)
+---- Forum: Arch Linux on PinePhone (https://forum.pine64.org/forumdisplay.php?fid=159)
+---- Thread: Detecting when charging and discharging (/showthread.php?tid=18925)



Detecting when charging and discharging - phobios - 12-04-2023

I tried using /sys/class/power_supply/axp20x-battery/status to deduce whether my phone was in charging or discharging mode. My goal is to write a script that can notify me when electricity is out. However, it seems that status goes to Discharging when it reaches 100%. Is there another way I can detect if I have a power cable with electricity plugged in to my device that works better than checking the status on the battery as I do above?


RE: Detecting when charging and discharging - phobios - 12-05-2023

Found now that there is 'present' and 'online' in /sys/class/power_supply/axp20x-usb/. Both correctly outputs 1 when there is electricity flowing and 0 when there is none. Is there anything that differs between them? Any of them preferable to use in the script?


RE: Detecting when charging and discharging - Kevin Kofler - 12-05-2023

Code:
if [ `qdbus-qt5 --system org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.OnBattery` == true ] ; then
  echo on battery
else
  echo plugged in
fi

You can also use dbus-send (with a slightly less user-friendly API), or scrape the upower --dump output.


RE: Detecting when charging and discharging - SchizoPinePhone225 - 01-10-2024

nice to add a low power OS, when a iPhone is "dead" it doesn't boot into the main OS instead it boots into that low power thing asking to be charged.
I want this feature really bad.


RE: Detecting when charging and discharging - Kevin Kofler - 01-10-2024

There is the pine64-pinephone-charging.img.xz from https://github.com/dreemurrs-embedded/Jumpdrive/releases, but you have to manually put in a microSD card with that image, it is not automatic. But it will help you if the battery is so low that the normal OS no longer boots. But as long as it boots, why do you need a different OS?