From 3fbe39d48030e6f2d6b2d9e07e15a15d8b183a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Bi=C3=A7er?= Date: Sat, 22 Oct 2022 22:45:39 +0200 Subject: [PATCH] add suspend hooks to stop fans on sleep --- config.json | 7 +++++++ fanctrl.py | 4 ++++ install.sh | 20 +++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index d280b86..41759fc 100644 --- a/config.json +++ b/config.json @@ -3,6 +3,13 @@ "strategyOnDischarging" : "", "batteryChargingStatusPath" : "", "strategies": { + "sleep": { + "fanSpeedUpdateFrequency": 5, + "movingAverageInterval": 40, + "speedCurve": [ + { "temp": 0, "speed": 0 } + ] + }, "lazyest": { "fanSpeedUpdateFrequency": 5, "movingAverageInterval": 40, diff --git a/fanctrl.py b/fanctrl.py index d8af1b7..44e5c61 100644 --- a/fanctrl.py +++ b/fanctrl.py @@ -85,6 +85,10 @@ def strategyLiveUpdate(self): strategy = fp.read() fp.seek(0) fp.truncate + + if strategy == "defaultStrategy": + strategy = self.config["defaultStrategy"] + if strategy in self.config["strategies"]: self.setStrategy(self.config["strategies"][strategy]) else: diff --git a/install.sh b/install.sh index f022104..09a9f95 100755 --- a/install.sh +++ b/install.sh @@ -18,6 +18,7 @@ if [ "$1" = "remove" ]; then ectool --interface=lpc autofanctrl # restore default fan manager rm /usr/local/bin/ectool rm -rf /home/$(logname)/.config/fw-fanctrl + rm /usr/lib/systemd/system-sleep/fw-fanctrl-suspend echo "fw-fanctrl has been removed successfully from system" elif [ -z $1 ]; then @@ -56,6 +57,23 @@ ExecStart=/usr/bin/python3 /usr/local/bin/fw-fanctrl --config /home/$(logname)/. WantedBy=multi-user.target EOF + + # create suspend hooks + echo "Creating suspend hooks" + + sudo cat > /lib/systemd/system-sleep/fw-fanctrl-suspend << EOF +#!/bin/sh + +case \$1 in + pre) runuser -l $(logname) -c "fw-fanctrl sleep" ;; + post) runuser -l $(logname) -c "fw-fanctrl defaultStrategy" ;; +esac + +EOF + + # make the suspend hook executable + sudo chmod +x /lib/systemd/system-sleep/fw-fanctrl-suspend + # restart daemon, enable and start service echo "Reloading daemon and enabling service" sudo systemctl daemon-reload @@ -67,4 +85,4 @@ else echo "Unknown command $1" exit fi -exit 0 \ No newline at end of file +exit 0