Compare commits
2 Commits
e2509cea8b
...
8ff1d8be9d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ff1d8be9d | ||
|
|
78b2a62643 |
2
PKGBUILD
2
PKGBUILD
@@ -1,5 +1,5 @@
|
|||||||
pkgname=fantasize
|
pkgname=fantasize
|
||||||
pkgver=0.2.0
|
pkgver=0.3.0
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc='C++ fan control for Linux'
|
pkgdesc='C++ fan control for Linux'
|
||||||
url='https://github.com/Tabascl/fantasize.git'
|
url='https://github.com/Tabascl/fantasize.git'
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ public:
|
|||||||
void DoFanControl();
|
void DoFanControl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int AggregateTemperature();
|
|
||||||
void PrintInfo();
|
void PrintInfo();
|
||||||
bool ExceedsHysteresis(int temperature);
|
bool ExceedsHysteresis(int temperature);
|
||||||
void ApplyFanPower(std::shared_ptr<Fan> fan, int targetFanPower);
|
void ApplyFanPower(std::shared_ptr<Fan> fan, int targetFanPower);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ enum class PWM_MODE { DC = 0, PWM };
|
|||||||
|
|
||||||
class PWMControl : public Printable, public Serializable {
|
class PWMControl : public Printable, public Serializable {
|
||||||
public:
|
public:
|
||||||
PWMControl(std::string controlPath);
|
PWMControl(std::string controlPath, int deviceIndex);
|
||||||
~PWMControl();
|
~PWMControl();
|
||||||
|
|
||||||
void SetPower(int percent);
|
void SetPower(int percent);
|
||||||
@@ -26,9 +26,11 @@ public:
|
|||||||
json toJson() const override;
|
json toJson() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string mConfigPath;
|
||||||
std::string mControlPath;
|
std::string mControlPath;
|
||||||
std::string mEnablePath;
|
std::string mEnablePath;
|
||||||
std::string mModePath;
|
std::string mModePath;
|
||||||
|
int mDeviceIndex;
|
||||||
|
|
||||||
std::string mInitialEnable;
|
std::string mInitialEnable;
|
||||||
std::string mInitialMode;
|
std::string mInitialMode;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
project('fantasize', 'cpp', version : '0.2.1', default_options : ['cpp_std=c++20'])
|
project('fantasize', 'cpp', version : '0.3.0', default_options : 'cpp_std=c++20')
|
||||||
|
|
||||||
src = [
|
src = [
|
||||||
'src/main.cxx',
|
'src/main.cxx',
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <fan/HwmonFan.h>
|
#include <fan/HwmonFan.h>
|
||||||
#include <pwm/PWMControl.h>
|
#include <pwm/PWMControl.h>
|
||||||
|
|
||||||
#define SETTLE_TIMEOUT 10
|
#define SETTLE_TIMEOUT 30
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ Serializer::DeserializeFans(vector<shared_ptr<Sensor>> availableSensors) {
|
|||||||
|
|
||||||
vector<shared_ptr<Fan>> fans;
|
vector<shared_ptr<Fan>> fans;
|
||||||
|
|
||||||
// Create a for the sensors first, then searching becomes cheaper
|
// Create a map for the sensors first, then searching becomes cheaper
|
||||||
map<string, shared_ptr<Sensor>> sensorMap;
|
map<string, shared_ptr<Sensor>> sensorMap;
|
||||||
for (auto s : availableSensors) {
|
for (auto s : availableSensors) {
|
||||||
sensorMap[s->toString()] = s;
|
sensorMap[s->toString()] = s;
|
||||||
@@ -46,7 +46,7 @@ Serializer::DeserializeFans(vector<shared_ptr<Sensor>> availableSensors) {
|
|||||||
auto data = ReadJson();
|
auto data = ReadJson();
|
||||||
try {
|
try {
|
||||||
for (auto &el : data["fans"].items()) {
|
for (auto &el : data["fans"].items()) {
|
||||||
auto pwmControl = make_shared<PWMControl>(el.value()["PWMControl"]);
|
auto pwmControl = make_shared<PWMControl>(el.value()["PWMControl"]["Path"], el.value()["PWMControl"]["Index"]);
|
||||||
auto rpmSensor = sensorMap[el.value()["LMSensor"]];
|
auto rpmSensor = sensorMap[el.value()["LMSensor"]];
|
||||||
|
|
||||||
int minPWM = el.value()["MinPWM"];
|
int minPWM = el.value()["MinPWM"];
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void FanCurve::DoFanControl() {
|
|||||||
for (auto s : mTempSensors)
|
for (auto s : mTempSensors)
|
||||||
BOOST_LOG_TRIVIAL(trace) << s->toString();
|
BOOST_LOG_TRIVIAL(trace) << s->toString();
|
||||||
|
|
||||||
int temp = AggregateTemperature();
|
int temp = mAggregator->aggregate(mTempSensors);
|
||||||
|
|
||||||
int t0 = 0, t1 = 0, p0 = 0, p1 = 0;
|
int t0 = 0, t1 = 0, p0 = 0, p1 = 0;
|
||||||
int targetFanPower;
|
int targetFanPower;
|
||||||
@@ -71,10 +71,6 @@ void FanCurve::DoFanControl() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FanCurve::AggregateTemperature() {
|
|
||||||
return mAggregator->aggregate(mTempSensors);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FanCurve::PrintInfo() {
|
void FanCurve::PrintInfo() {
|
||||||
BOOST_LOG_FUNCTION()
|
BOOST_LOG_FUNCTION()
|
||||||
|
|
||||||
@@ -123,7 +119,7 @@ void FanCurve::ApplyFanPower(std::shared_ptr<Fan> fan, int targetFanPower) {
|
|||||||
BOOST_LOG_FUNCTION();
|
BOOST_LOG_FUNCTION();
|
||||||
|
|
||||||
if (!fan->ZeroFanModeSupported() && fan->RPM() <= 0) {
|
if (!fan->ZeroFanModeSupported() && fan->RPM() <= 0) {
|
||||||
BOOST_LOG_TRIVIAL(warning) << "Fan stopped completely!";
|
BOOST_LOG_TRIVIAL(warning) << "Fan " << fan->toString() << " stopped completely!";
|
||||||
fan->PWM(fan->StartPWM());
|
fan->PWM(fan->StartPWM());
|
||||||
fan->AdjustPWMLimits();
|
fan->AdjustPWMLimits();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <App.h>
|
#include <App.h>
|
||||||
|
|
||||||
#define PROJECT_VERSION "v0.2.1"
|
#define PROJECT_VERSION "v0.3.0"
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
namespace logging = boost::log;
|
namespace logging = boost::log;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include <boost/log/attributes/named_scope.hpp>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/log/attributes/named_scope.hpp>
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
#include <pwm/PWMControl.h>
|
#include <pwm/PWMControl.h>
|
||||||
@@ -15,12 +15,24 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
namespace fs = filesystem;
|
namespace fs = filesystem;
|
||||||
|
|
||||||
PWMControl::PWMControl(string controlPath) : mControlPath(controlPath) {
|
PWMControl::PWMControl(string controlPath, int deviceIndex)
|
||||||
fs::path pathEnable(mControlPath + PWM_POSTFIX_ENABLE);
|
: mConfigPath(controlPath), mDeviceIndex(deviceIndex) {
|
||||||
fs::path pathMode(mControlPath + PWM_POSTFIX_MODE);
|
auto path = fs::path{controlPath};
|
||||||
|
|
||||||
mEnablePath = pathEnable;
|
int fileCount =
|
||||||
mModePath = pathMode;
|
distance(fs::directory_iterator(path), fs::directory_iterator{});
|
||||||
|
if (fileCount != 1)
|
||||||
|
throw runtime_error("More than one HWMON device present, unsupported");
|
||||||
|
|
||||||
|
for (auto de : fs::directory_iterator(path)) {
|
||||||
|
auto testPath = de.path();
|
||||||
|
mControlPath =
|
||||||
|
fs::path{de.path() / (string("pwm").append(to_string(deviceIndex)))}
|
||||||
|
.string();
|
||||||
|
}
|
||||||
|
|
||||||
|
mEnablePath = fs::path{mControlPath + PWM_POSTFIX_ENABLE}.string();
|
||||||
|
mModePath = fs::path{mControlPath + PWM_POSTFIX_MODE}.string();
|
||||||
|
|
||||||
ifstream istrm;
|
ifstream istrm;
|
||||||
|
|
||||||
@@ -85,6 +97,6 @@ void PWMControl::Reset() {
|
|||||||
const string PWMControl::toString() const { return fs::path(mControlPath); }
|
const string PWMControl::toString() const { return fs::path(mControlPath); }
|
||||||
|
|
||||||
json PWMControl::toJson() const {
|
json PWMControl::toJson() const {
|
||||||
json obj = {"PWMControl", mControlPath};
|
json obj = {"PWMControl", {{"Path", mConfigPath}, {"Index", mDeviceIndex}}};
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <pwm/PWMControlFacade.h>
|
#include <pwm/PWMControlFacade.h>
|
||||||
|
|
||||||
@@ -20,14 +21,20 @@ vector<shared_ptr<PWMControl>> PWMControlFacade::PWMControls() {
|
|||||||
for (const fs::directory_entry &hwmon_device :
|
for (const fs::directory_entry &hwmon_device :
|
||||||
fs::directory_iterator{HWMON_BASE_PATH}) {
|
fs::directory_iterator{HWMON_BASE_PATH}) {
|
||||||
|
|
||||||
|
// Resolve symlink to get device path instead of hwmon path, the latter of
|
||||||
|
// which can change
|
||||||
|
fs::path actual_path =
|
||||||
|
fs::canonical(HWMON_BASE_PATH / fs::read_symlink(hwmon_device));
|
||||||
|
|
||||||
for (const fs::directory_entry &control :
|
for (const fs::directory_entry &control :
|
||||||
fs::directory_iterator{hwmon_device}) {
|
fs::directory_iterator{actual_path}) {
|
||||||
auto filename = control.path().filename().string();
|
auto filename = control.path().filename().string();
|
||||||
|
|
||||||
if (regex_match(filename, re_ctrl)) {
|
if (regex_match(filename, re_ctrl)) {
|
||||||
auto controlPath = control.path().string();
|
auto controlIndex = filename.back() - '0';
|
||||||
|
auto controlPath = actual_path.parent_path();
|
||||||
|
|
||||||
controls.push_back(make_shared<PWMControl>(controlPath));
|
controls.push_back(make_shared<PWMControl>(controlPath, controlIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user