[Share Experiences] Matebook16s在Deepin v23/UOS v20 1070下使用tlp开启电池保养功能
Tofloor
poster avatar
MeGusta
deepin
2024-08-18 22:56
Author

安装tlp

sudo apt install tlp -y
sudo systemctl enable --now tlp

然后去掉下面两行的注释,然后执行 tlp start应用修改。

#START_CHARGE_THRESH_BAT0=75
#STOP_CHARGE_THRESH_BAT0=80

有一个小问题,就是如果设置 STOP_CHARGE_THRESH_BAT0=80,那么电池在显示充电到79%的时候就会停止充电,看起来有点奇怪,可以修改成 STOP_CHARGE_THRESH_BAT0=81,这样就会在充电到80%的时候停止充电。

另外,如果马上带着电脑出门,临时要充满电,可以执行以下命令

sudo tlp fullcharge BAT0

下面是完整脚本:

#!/bin/bash

echo "matebook16s设置电池保养功能-root.sh"

# 检查用户是否具有root/sudo权限
if [ "$(id -u)" != "0" ]; then
   echo -e "\033[31m请以root/sudo用户身份运行此脚本。\033[0m" 1>&2
   # 按任意键退出
   echo "按任意键退出..."
   read -n 1
   exit 1
fi

apt install tlp -y
systemctl enable --now tlp

# 定义文件路径
FILE="/etc/tlp.conf"

# 显示电池信息
clear
echo -e "\033[31m电池详情如下:\033[0m"
tlp-stat -b
echo "-------------------------------------------------"

# 复制文件
cp /etc/tlp.conf /etc/tlp.conf.bak

# 检查是否已经存在修改后的这两行
if grep -Fxq "START_CHARGE_THRESH_BAT0=75" /etc/tlp.conf && grep -Fxq "STOP_CHARGE_THRESH_BAT0=81" /etc/tlp.conf
then
    echo -e "\033[31m电池保养功能已开启,电池将在低于75%时充电,高于80%时停止充电\033[0m"
else
    # 修改文件
    sed -i 's/#START_CHARGE_THRESH_BAT0=75/START_CHARGE_THRESH_BAT0=75/g' /etc/tlp.conf
    sed -i 's/#STOP_CHARGE_THRESH_BAT0=80/STOP_CHARGE_THRESH_BAT0=81/g' /etc/tlp.conf

    # 检查是否修改成功
    if grep -Fxq "START_CHARGE_THRESH_BAT0=75" /etc/tlp.conf && grep -Fxq "STOP_CHARGE_THRESH_BAT0=81" /etc/tlp.conf
    then
        # 执行tlp start
        tlp start > /dev/null
        echo -e "\033[31m电池保养功能已开启,电池将在低于75%时充电,高于80%时停止充电\033[0m"
    else
        echo -e "\033[31m/etc/tlp.conf修改失败,请检查该文件...\033[0m"
    fi
fi

echo "想要临时完全充满电池,请运行sudo tlp fullcharge BAT0"
# 按任意键退出
echo "按任意键退出..."
read -n 1
exit 0
Reply Favorite View the author
All Replies

No replies yet