distribution/packages/sysutils/powerstate/sources/powerstate.sh
fewtarius 4acb3fe902
* Continue to work on improving power consumption on battery.
* Update emulators and cores.
* Improve logging in some scripts.
2023-01-19 21:30:33 -05:00

50 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2022-present Fewtarius (https://github.com/fewtarius)
###
### Normally this would be a udev rule, but some devices like the AyaNeo Air
### do not properly report the applied power state to udev, and we can't use
### inotifyd to watch the status in /sys.
###
. /etc/profile
while true
do
STATUS="$(cat /sys/class/power_supply/{BAT*,bat*}/status 2>/dev/null)"
${DEBUG} && echo "Status: ${STATUS}"
if [ ! "${STATUS}" = "${CURRENT_MODE}" ]
then
${DEBUG} && echo "Status changed."
case ${STATUS} in
Disch*)
log $0 "Switching to battery mode."
if [ "$(get_setting system.powersave)" = 1 ]
then
audio_powersave 1
perftune battery
performance_level auto
power_dpm_state battery
pcie_aspm_policy powersave
device_powersave 1
fi
;;
*)
log $0 "Switching to performance mode."
if [ "$(get_setting system.powersave)" = 1 ]
then
audio_powersave 0
perftune performance
performance_level profile_peak
power_dpm_state performance
pcie_aspm_policy default
device_powersave 0
fi
;;
esac
fi
CURRENT_MODE="${STATUS}"
${DEBUG} && echo "Current Mode: ${CURRENT_MODE}"
sleep 2
done