From 596a30b76a44d7a89f021c431dac65c2ae82e16c Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 10 Oct 2022 00:25:09 +0200 Subject: [PATCH] Improve logic to handle fans stopping --- PKGBUILD | 2 +- app/CMakeLists.txt | 2 +- app/include/fan/Fan.h | 1 + app/include/fan/HwmonFan.h | 6 +++++- app/src/fan/FanCurve.cxx | 4 +--- app/src/fan/HwmonFan.cxx | 25 ++++++++++++++++++++----- app/src/main.cxx | 2 +- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 3b4dc04..a824d30 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,5 +1,5 @@ pkgname=fantasize -pkgver=0.1.5 +pkgver=0.1.6 pkgrel=1 pkgdesc='C++ fan control for Linux' url='https://github.com/Tabascl/fantasize.git' diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 451f83d..27032d4 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -project(fantasize VERSION 0.1.5) +project(fantasize VERSION 0.1.6) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/app/include/fan/Fan.h b/app/include/fan/Fan.h index 8096d79..15611e3 100644 --- a/app/include/fan/Fan.h +++ b/app/include/fan/Fan.h @@ -18,6 +18,7 @@ public: virtual int StartPWM() = 0; virtual void FindPWMLimits() = 0; + virtual void AdjustPWMLimits() = 0; }; #endif // FAN_H_ diff --git a/app/include/fan/HwmonFan.h b/app/include/fan/HwmonFan.h index 3d3e8fb..671e1fb 100644 --- a/app/include/fan/HwmonFan.h +++ b/app/include/fan/HwmonFan.h @@ -1,9 +1,11 @@ #ifndef HWMONFAN_H_ #define HWMONFAN_H_ -#include +#include #include +#include + #include #include #include @@ -25,6 +27,7 @@ public: int StartPWM() override; void FindPWMLimits() override; + void AdjustPWMLimits() override; json toJson() const override; @@ -37,6 +40,7 @@ private: int mMinPWM; int mStartPWM; + std::chrono::time_point mLastAdjustmentTime; }; #endif // HWMONFAN_H_ diff --git a/app/src/fan/FanCurve.cxx b/app/src/fan/FanCurve.cxx index 03dd1f0..e7067f3 100644 --- a/app/src/fan/FanCurve.cxx +++ b/app/src/fan/FanCurve.cxx @@ -44,9 +44,7 @@ void FanCurve::DoFanControl() { if (f->RPM() <= 0) { BOOST_LOG_TRIVIAL(warning) << "Fan stopped completely!"; f->PWM(f->StartPWM()); - - BOOST_LOG_TRIVIAL(info) << "Adjusting minPWM of fan " << f->toString(); - f->MinPWM(f->MinPWM() + 2); + f->AdjustPWMLimits(); } else { f->PWM(targetFanPower); } diff --git a/app/src/fan/HwmonFan.cxx b/app/src/fan/HwmonFan.cxx index ee7d38c..254aa7a 100644 --- a/app/src/fan/HwmonFan.cxx +++ b/app/src/fan/HwmonFan.cxx @@ -1,11 +1,12 @@ -#include #include #include #include -#include "pwm/PWMControl.h" -#include +#include +#include + #include +#include #define TIMEOUT 10 #define STEP 2 @@ -34,10 +35,10 @@ void HwmonFan::MinPWM(int value) { mMinPWM = value; } int HwmonFan::MinPWM() { return mMinPWM; } -int HwmonFan::StartPWM() { return mStartPWM; } - void HwmonFan::StartPWM(int value) { mStartPWM = value; } +int HwmonFan::StartPWM() { return mStartPWM; } + void HwmonFan::FindPWMLimits() { cout << "Looking for minimal PWM" << endl; int minPWM = 0; @@ -78,6 +79,20 @@ void HwmonFan::FindPWMLimits() { } } +void HwmonFan::AdjustPWMLimits() { + BOOST_LOG_FUNCTION() + + chrono::time_point now = chrono::steady_clock::now(); + + if ((now - mLastAdjustmentTime) > + chrono::duration(chrono::seconds(TIMEOUT))) { + BOOST_LOG_TRIVIAL(info) << "Increasing minimal fan speed"; + + mLastAdjustmentTime = now; + mMinPWM += 2; + } +} + json HwmonFan::toJson() const { json obj; obj = {mPWMControl->toJson(), diff --git a/app/src/main.cxx b/app/src/main.cxx index 95ae21f..a303b26 100644 --- a/app/src/main.cxx +++ b/app/src/main.cxx @@ -20,7 +20,7 @@ #include -#define PROJECT_VERSION "v0.1.5" +#define PROJECT_VERSION "v0.1.6" namespace po = boost::program_options; namespace logging = boost::log;