Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 16c7a930c2 | |||
| 95b6f248c8 |
4
PKGBUILD
4
PKGBUILD
@@ -1,5 +1,5 @@
|
|||||||
pkgname=fantasize
|
pkgname=fantasize
|
||||||
pkgver=0.1.0
|
pkgver=0.1.1
|
||||||
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'
|
||||||
@@ -7,7 +7,7 @@ source=("$pkgname-$pkgver.tar.gz::https://github.com/Tabascl/fantasize/archive/r
|
|||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
license=('GPL3')
|
license=('GPL3')
|
||||||
makedepends=('git' 'cmake' 'nlohmann-json' 'boost' 'cuda')
|
makedepends=('git' 'cmake' 'nlohmann-json' 'boost' 'cuda')
|
||||||
sha256sums=('69d61255edb49b66396f00b7bfadb39ce1220769838929ad74dc9f3301742ce7')
|
sha256sums=('SKIP')
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
cmake -S "$pkgname-$pkgver/app" -B build -DCMAKE_BUILD_TYPE=Release
|
cmake -S "$pkgname-$pkgver/app" -B build -DCMAKE_BUILD_TYPE=Release
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
project(fantasize VERSION 0.1.0)
|
project(fantasize VERSION 0.1.1)
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
find_package(nlohmann_json 3.11.2 REQUIRED)
|
find_package(nlohmann_json 3.11.2 REQUIRED)
|
||||||
find_package(Boost 1.80 COMPONENTS program_options REQUIRED)
|
find_package(Boost 1.80 COMPONENTS program_options log log_setup date_time REQUIRED)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/main.cxx
|
src/main.cxx
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ public:
|
|||||||
PWMControl(std::string controlPath);
|
PWMControl(std::string controlPath);
|
||||||
~PWMControl();
|
~PWMControl();
|
||||||
|
|
||||||
void pwm(int percent);
|
void Power(int percent);
|
||||||
int pwm();
|
int Power();
|
||||||
|
|
||||||
void EnableManualControl();
|
void EnableManualControl();
|
||||||
void Reset();
|
void Reset();
|
||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
json toJson() const override;
|
json toJson() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int readValue(std::string path);
|
int mCurrentValue;
|
||||||
|
|
||||||
std::string mControlPath;
|
std::string mControlPath;
|
||||||
std::string mEnablePath;
|
std::string mEnablePath;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ FanGenerator::FindFans(vector<shared_ptr<Sensor>> rpmSensors,
|
|||||||
cout << "Setting all fans to maximum speed" << endl;
|
cout << "Setting all fans to maximum speed" << endl;
|
||||||
for (auto c : pwmControls) {
|
for (auto c : pwmControls) {
|
||||||
c->EnableManualControl();
|
c->EnableManualControl();
|
||||||
c->pwm(100);
|
c->Power(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for fans to settle
|
// Wait for fans to settle
|
||||||
@@ -41,7 +41,7 @@ FanGenerator::FindFans(vector<shared_ptr<Sensor>> rpmSensors,
|
|||||||
for (auto c : pwmControls) {
|
for (auto c : pwmControls) {
|
||||||
cout << "Setting " << c->toString()
|
cout << "Setting " << c->toString()
|
||||||
<< " to 50% and wait for it to settle..." << endl;
|
<< " to 50% and wait for it to settle..." << endl;
|
||||||
c->pwm(50);
|
c->Power(50);
|
||||||
|
|
||||||
this_thread::sleep_for(chrono::seconds(SETTLE_TIMEOUT));
|
this_thread::sleep_for(chrono::seconds(SETTLE_TIMEOUT));
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ FanGenerator::FindFans(vector<shared_ptr<Sensor>> rpmSensors,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cout << "Setting fan back to 100%" << endl;
|
cout << "Setting fan back to 100%" << endl;
|
||||||
c->pwm(100);
|
c->Power(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapping;
|
return mapping;
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ HwmonFan::HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
|||||||
|
|
||||||
void HwmonFan::PWM(int percent) {
|
void HwmonFan::PWM(int percent) {
|
||||||
if (percent < mMinPWM) {
|
if (percent < mMinPWM) {
|
||||||
mPWMControl->pwm(mMinPWM);
|
mPWMControl->Power(mMinPWM);
|
||||||
} else {
|
} else {
|
||||||
mPWMControl->pwm(percent);
|
mPWMControl->Power(percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,27 @@
|
|||||||
|
#include <boost/log/expressions/formatters/named_scope.hpp>
|
||||||
|
#include <csignal>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||||
|
#include <boost/log/attributes/named_scope.hpp>
|
||||||
|
#include <boost/log/core.hpp>
|
||||||
|
#include <boost/log/expressions.hpp>
|
||||||
|
#include <boost/log/expressions/message.hpp>
|
||||||
|
#include <boost/log/support/date_time.hpp>
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
#include <boost/log/utility/setup.hpp>
|
||||||
|
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||||
|
#include <boost/log/utility/setup/console.hpp>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
#include <boost/program_options/options_description.hpp>
|
#include <boost/program_options/options_description.hpp>
|
||||||
#include <boost/program_options/parsers.hpp>
|
#include <boost/program_options/parsers.hpp>
|
||||||
#include <boost/program_options/value_semantic.hpp>
|
#include <boost/program_options/value_semantic.hpp>
|
||||||
#include <boost/program_options/variables_map.hpp>
|
#include <boost/program_options/variables_map.hpp>
|
||||||
#include <csignal>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
|
||||||
|
|
||||||
#include <App.h>
|
#include <App.h>
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
namespace logging = boost::log;
|
||||||
|
|
||||||
App app;
|
App app;
|
||||||
|
|
||||||
@@ -17,18 +29,50 @@ static int doInitialSetup = 0;
|
|||||||
|
|
||||||
void signal_handler(int s) { app.Shutdown(); }
|
void signal_handler(int s) { app.Shutdown(); }
|
||||||
|
|
||||||
|
void InitLogging(bool verbose) {
|
||||||
|
logging::add_console_log(
|
||||||
|
std::clog,
|
||||||
|
logging::keywords::format =
|
||||||
|
(logging::expressions::stream
|
||||||
|
<< "["
|
||||||
|
<< logging::expressions::format_date_time<boost::posix_time::ptime>(
|
||||||
|
"TimeStamp", "%Y-%m-%d %H:%M:%S")
|
||||||
|
<< "]["
|
||||||
|
<< logging::expressions::format_named_scope(
|
||||||
|
"Scope", logging::keywords::format = "%c")
|
||||||
|
<< "]"
|
||||||
|
<< "[" << logging::trivial::severity << "] "
|
||||||
|
<< logging::expressions::smessage));
|
||||||
|
|
||||||
|
logging::add_common_attributes();
|
||||||
|
logging::core::get()->add_global_attribute(
|
||||||
|
"Scope", logging::attributes::named_scope());
|
||||||
|
|
||||||
|
BOOST_LOG_FUNCTION();
|
||||||
|
|
||||||
|
if (!verbose) {
|
||||||
|
logging::core::get()->set_filter(logging::trivial::severity >=
|
||||||
|
logging::trivial::info);
|
||||||
|
} else {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Verbose logging enabled";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
signal(SIGINT, signal_handler);
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
po::options_description desc("Allowed options");
|
po::options_description desc("Allowed options");
|
||||||
desc.add_options()("help", "produce help message")("setup", po::bool_switch(),
|
desc.add_options()("help,h", "produce help message")(
|
||||||
"run initial setup");
|
"setup,s", po::bool_switch(),
|
||||||
|
"run initial setup")("verbose,v", po::bool_switch(), "print debug info");
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
po::notify(vm);
|
po::notify(vm);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
InitLogging(vm["verbose"].as<bool>());
|
||||||
|
|
||||||
if (vm.count("help")) {
|
if (vm.count("help")) {
|
||||||
std::cout << desc << "\n";
|
std::cout << desc << "\n";
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#include <boost/json/object.hpp>
|
#include <boost/log/attributes/named_scope.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
#include <pwm/PWMControl.h>
|
#include <pwm/PWMControl.h>
|
||||||
|
|
||||||
#define PWM_POSTFIX_ENABLE "_enable"
|
#define PWM_POSTFIX_ENABLE "_enable"
|
||||||
@@ -22,6 +24,8 @@ PWMControl::PWMControl(string controlPath) : mControlPath(controlPath) {
|
|||||||
|
|
||||||
ifstream istrm;
|
ifstream istrm;
|
||||||
|
|
||||||
|
mCurrentValue = Power();
|
||||||
|
|
||||||
istrm.open(mEnablePath);
|
istrm.open(mEnablePath);
|
||||||
istrm >> mInitialEnable;
|
istrm >> mInitialEnable;
|
||||||
istrm.close();
|
istrm.close();
|
||||||
@@ -36,22 +40,31 @@ PWMControl::~PWMControl() {
|
|||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWMControl::pwm(int percent) {
|
void PWMControl::Power(int percent) {
|
||||||
int pwmValue = PWM_MAX_VALUE * percent / 100;
|
BOOST_LOG_FUNCTION();
|
||||||
|
|
||||||
ofstream ostrm(mControlPath, ios::trunc);
|
int pwmValue = PWM_MAX_VALUE * (percent / 100);
|
||||||
ostrm << pwmValue;
|
|
||||||
ostrm.close();
|
if (percent != mCurrentValue) {
|
||||||
|
BOOST_LOG_TRIVIAL(trace) << "Updating control value to " << percent;
|
||||||
|
ofstream ostrm(mControlPath, ios::trunc);
|
||||||
|
ostrm << pwmValue;
|
||||||
|
ostrm.close();
|
||||||
|
|
||||||
|
mCurrentValue = percent;
|
||||||
|
} else {
|
||||||
|
BOOST_LOG_TRIVIAL(trace) << "Value unchanged, do nothing";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PWMControl::pwm() {
|
int PWMControl::Power() {
|
||||||
int value;
|
int value;
|
||||||
ifstream istrm;
|
ifstream istrm;
|
||||||
|
|
||||||
istrm.open(mControlPath);
|
istrm.open(mControlPath);
|
||||||
istrm >> value;
|
istrm >> value;
|
||||||
|
|
||||||
return value;
|
return (value / PWM_MAX_VALUE) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWMControl::EnableManualControl() {
|
void PWMControl::EnableManualControl() {
|
||||||
|
|||||||
Reference in New Issue
Block a user