Detecting when charging and discharging
#1
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?
  Reply
#2
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?
  Reply
#3
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.
  Reply
#4
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.
  Reply
#5
There is the pine64-pinephone-charging.img.xz from https://github.com/dreemurrs-embedded/Ju...e/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?
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  /dev and etcher not detecting pinephone for writing pineuser0 2 2,372 09-13-2021, 03:10 PM
Last Post: pineuser0

Forum Jump:


Users browsing this thread: 2 Guest(s)