2022-12-21 00:29:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Copyright (C) 2022-present Fewtarius (https://github.com/fewtarius)
|
|
|
|
|
2022-12-21 22:24:01 +00:00
|
|
|
###
|
|
|
|
### 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.
|
|
|
|
###
|
|
|
|
|
2022-12-21 00:29:08 +00:00
|
|
|
. /etc/profile
|
|
|
|
|
2022-12-21 22:24:01 +00:00
|
|
|
while true
|
|
|
|
do
|
2023-01-23 02:38:25 +00:00
|
|
|
if [ "$(get_setting system.powersave)" = 1 ]
|
2022-12-21 22:24:01 +00:00
|
|
|
then
|
2023-01-23 02:38:25 +00:00
|
|
|
STATUS="$(cat /sys/class/power_supply/{BAT*,bat*}/status 2>/dev/null)"
|
|
|
|
if [ ! "${STATUS}" = "${CURRENT_MODE}" ]
|
|
|
|
then
|
|
|
|
case ${STATUS} in
|
|
|
|
Disch*)
|
|
|
|
log $0 "Switching to battery mode."
|
|
|
|
if [ -e "/tmp/.gpuperf" ]
|
|
|
|
then
|
|
|
|
GPUMODE=$(cat /tmp/.gpuperf)
|
|
|
|
else
|
|
|
|
GPUMODE=$(get_setting system.gpuperf)
|
|
|
|
if [ -z "${GPUMODE}" ]
|
|
|
|
then
|
|
|
|
GPUMODE=auto
|
|
|
|
set_setting system.gpuperf auto
|
|
|
|
fi
|
|
|
|
fi
|
2023-02-06 17:16:00 +00:00
|
|
|
ledcontrol
|
2023-01-19 11:14:52 +00:00
|
|
|
audio_powersave 1
|
2023-01-20 13:09:45 +00:00
|
|
|
cpu_perftune battery
|
2023-01-23 02:38:25 +00:00
|
|
|
gpu_performance_level ${GPUMODE}
|
2023-01-20 13:09:45 +00:00
|
|
|
gpu_power_profile 1
|
2023-01-19 11:14:52 +00:00
|
|
|
pcie_aspm_policy powersave
|
|
|
|
device_powersave 1
|
2023-01-23 02:38:25 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
log $0 "Switching to performance mode."
|
2023-02-06 17:16:00 +00:00
|
|
|
ledcontrol
|
2023-01-19 11:14:52 +00:00
|
|
|
audio_powersave 0
|
2023-01-20 13:09:45 +00:00
|
|
|
cpu_perftune performance
|
|
|
|
gpu_performance_level profile_standard
|
|
|
|
gpu_power_profile 1
|
2022-12-21 22:24:01 +00:00
|
|
|
pcie_aspm_policy default
|
2023-01-19 11:14:52 +00:00
|
|
|
device_powersave 0
|
2023-01-23 02:38:25 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
CURRENT_MODE="${STATUS}"
|
2022-12-21 22:24:01 +00:00
|
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
done
|