2020年5月15日金曜日

ThinkPadR61eの互換バッテリーを買ったので

この2020年にThinkPadR61eもないだろうけど(笑)

ThinkPadR61eのバッテリーが長いこと死んでいたのだが、とうとう互換バッテリーに手を出してしまった。。。
発火すると怖いけどネ。充電したままにしないように気をつけないと)

現在ThinkPadR61eはLubuntuで運用してるのだが、バッテリー保護のためしきい値の設定がしたいのでいろいろと世の中を探していたら・・・

ありましたよ!
tp_smapiという素敵なデバイスドライバが!!(喜)

Lubuntuじゃないけど、ArchLinuxのWikiの情報いつも色々と役に立つなぁ。
お世話になってます。

ひとまず、デバドラをインストールしよう!
「tp-smapi-dkms」をインストールすればいいらしい!

$ sudo -i
# apt install tp-smapi-dkms
# modprobe tp_smapi

次に設定してみる。
バッテリー値が75%になったら充電を停止して、
65%になったら再び充電を開始するように設定する。

# echo 75 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
# echo 65 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

次に読み出してみる

# cat /sys/devices/platform/smapi/BAT0/start_charge_thresh
75
# cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh
65

これで、めでたしめでたしでもいいのですが、バッテリーを外すとこの値がリセットされてしまうらしいので、起動時に起動するようにしておくといいらしい。。。

ドライバを起動時に自動で組み込まれるようにする。# chmod 744 /usr/sbin/set_battery_thresholds
これは、/etc/modules-load.d/に組み込むドライバのファイルを作成する。
今回は「tp_smapi.conf」というファイルを作成してみる。
# ThinkPad SMAPI
tp_smapi

最後に、スクリプトの作成と起動スクリプトを準備しないと・・・
今は面倒なのでまたあとで。。。


※つづき

スクリプトも準備した。もちろん、ArchLinuxのWikiをパクってね。
こんな感じ

/usr/sbin/bat_thresh
#!/bin/sh # ThinkPad SMAPI Battery Threshold # for ThinkPad R61e # Require "tp_smapi" device driver START_TH="/sys/devices/platform/smapi/BAT0/start_charge_thresh" STOP_TH="/sys/devices/platform/smapi/BAT0/stop_charge_thresh" STATUS="/sys/devices/platform/smapi/BAT0/state" PERCENT="/sys/devices/platform/smapi/BAT0/remaining_percent" if [ $# -ne 2 ]; then echo "usage: $0 [start_threshold] [stop_threshold]" echo "Current:" echo " Start threshold : "`cat $START_TH`"%" echo " Stop threshold : "`cat $STOP_TH`"%" echo " Status : "`cat $STATUS` echo " Remain : "`cat $PERCENT`"%" exit 0 fi echo $1 > $START_TH echo $2 > $STOP_TH
バッテリーは1個しかないので、BAT0に固定した。
そして、実行属性を付加する。
# chmod 744 /usr/sbin/bat_thresh

で、最後にsystemdに起動スクリプトを追加する。。。
今回は65%で充電開始、75%で充電停止にしてみる。
/etc/systemd/system/bat_thresh.service
[Unit] Description=ThinkPad Battery Threshold [Service] Type=oneshot ExecStart=/usr/sbin/bat_thresh 65 75 RemainAfterExit=yes [Install] WantedBy=multi-user.target
このサービスを有効にする。
# systemctl enable bat_thresh.service

では、再起動!!!
んで、確認。。。
$ bat_thresh
usage: /usr/sbin/bat_thresh [start_threshold] [stop_threshold]
Current:
  Start threshold : 65%
  Stop threshold  : 75%
  Status          : idle
  Remain          : 73%

よくできました。めでたし、めでたし!

ふんどしの持ち主


0 件のコメント:

コメントを投稿