summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/simple/q-power_supply.nix32
1 files changed, 29 insertions, 3 deletions
diff --git a/pkgs/simple/q-power_supply.nix b/pkgs/simple/q-power_supply.nix
index 5e7cd0d..b7e5aaa 100644
--- a/pkgs/simple/q-power_supply.nix
+++ b/pkgs/simple/q-power_supply.nix
@@ -7,11 +7,25 @@ writeDashBin "q-power_supply" ''
eval "$(${gnused}/bin/sed -n '
s/^\([A-Z_]\+=[0-9A-Za-z_-]*\)$/export \1/p
' $uevent)"
- case $POWER_SUPPLY_NAME in
- AC|Mains)
- exit # not battery
+ case $POWER_SUPPLY_TYPE in
+ Battery)
+ power_supply_battery "$uevent"
+ ;;
+ Mains)
+ power_supply_mains "$uevent"
+ ;;
+ UPS|USB|Wireless)
+ echo "$uevent: warning: unsuppoerted type: $POWER_SUPPLY_TYPE" >&2
+ exit 1
+ ;;
+ *)
+ echo "$uevent: warning: unknown type: $POWER_SUPPLY_TYPE" >&2
+ exit 2
;;
esac
+ )}
+
+ power_supply_battery() {(
exec </dev/null
exec ${gawk}/bin/awk '
function die(s) {
@@ -146,6 +160,18 @@ writeDashBin "q-power_supply" ''
'
)}
+ power_supply_mains() {(
+ set -efu
+ uevent=$1
+ case $POWER_SUPPLY_ONLINE in
+ 0) printf '%s: offline\n' "$POWER_SUPPLY_NAME";;
+ 1) printf '%s: online\n' "$POWER_SUPPLY_NAME";;
+ 2) printf '%s: online\n' "$POWER_SUPPLY_NAME";;
+ *) printf '%s: unknown VBUS state: %s\n' "$POWER_SUPPLY_NAME" "$POWER_SUPPLY_ONLINE";;
+ esac
+ )}
+
+
for uevent in /sys/class/power_supply/*/uevent; do
power_supply "$uevent" || :
done