Compare commits
2 Commits
v0.1.6
...
OptionalLi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4e234f307 | ||
| f718f82ad1 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,6 +3,6 @@ compile_commands.json
|
|||||||
.cache/
|
.cache/
|
||||||
pkg/
|
pkg/
|
||||||
rel_oot/
|
rel_oot/
|
||||||
src/
|
./src
|
||||||
*.pkg.tar.zst
|
*.pkg.tar.zst
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
|||||||
2
PKGBUILD
2
PKGBUILD
@@ -1,5 +1,5 @@
|
|||||||
pkgname=fantasize
|
pkgname=fantasize
|
||||||
pkgver=0.1.6
|
pkgver=0.1.7
|
||||||
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'
|
||||||
|
|||||||
1
app/.clang-format
Normal file
1
app/.clang-format
Normal file
@@ -0,0 +1 @@
|
|||||||
|
BasedOnStyle: Google
|
||||||
@@ -1,18 +1,32 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
project(fantasize VERSION 0.1.6)
|
project(fantasize VERSION 0.1.7)
|
||||||
|
|
||||||
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.7 REQUIRED)
|
||||||
find_package(Boost 1.80 COMPONENTS program_options log log_setup date_time REQUIRED)
|
find_package(Boost 1.80 COMPONENTS program_options log log_setup date_time REQUIRED)
|
||||||
|
|
||||||
|
find_library(NVML_LIB nvidia-ml)
|
||||||
|
|
||||||
|
set(ADDITIONAL_LIBS)
|
||||||
|
|
||||||
|
if (NVML_LIB)
|
||||||
|
set(HAVE_NVML)
|
||||||
|
|
||||||
|
add_library(nvidia-sensor-lib STATIC
|
||||||
|
src/sensor/NvidiaSensor.cxx
|
||||||
|
src/sensor/GPUSensorsFacade.cxx)
|
||||||
|
|
||||||
|
target_link_libraries(nvidia-sensor-lib PUBLIC NVML_LIB)
|
||||||
|
|
||||||
|
list(APPEND ADDITIONAL_LIBS nvidia-sensor-lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/main.cxx
|
src/main.cxx
|
||||||
src/sensor/LMSensorsFacade.cxx
|
src/sensor/LMSensorsFacade.cxx
|
||||||
src/sensor/GPUSensorsFacade.cxx
|
|
||||||
src/sensor/Sensor.cxx
|
src/sensor/Sensor.cxx
|
||||||
src/sensor/NvidiaSensor.cxx
|
|
||||||
src/sensor/LMSensor.cxx
|
src/sensor/LMSensor.cxx
|
||||||
src/pwm/PWMControl.cxx
|
src/pwm/PWMControl.cxx
|
||||||
src/pwm/PWMControlFacade.cxx
|
src/pwm/PWMControlFacade.cxx
|
||||||
@@ -23,13 +37,15 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/Serializer.cxx
|
src/Serializer.cxx
|
||||||
src/sensor/SensorManager.cxx
|
src/sensor/SensorManager.cxx
|
||||||
src/Controller.cxx
|
src/Controller.cxx
|
||||||
|
src/Settings.cxx
|
||||||
src/App.cxx
|
src/App.cxx
|
||||||
)
|
)
|
||||||
|
|
||||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
|
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC include /opt/cuda)
|
target_include_directories(${PROJECT_NAME} PUBLIC include /opt/cuda)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC sensors nvidia-ml nlohmann_json::nlohmann_json tbb ${Boost_LIBRARIES})
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC sensors nlohmann_json::nlohmann_json tbb ${Boost_LIBRARIES} ${ADDITIONAL_LIBS})
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} DESTINATION usr/local/bin)
|
install(TARGETS ${PROJECT_NAME} DESTINATION usr/local/bin)
|
||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/unit/fantasize.service DESTINATION usr/lib/systemd/system)
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/unit/fantasize.service DESTINATION usr/lib/systemd/system)
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ private:
|
|||||||
FanLabeler mFanLabeler;
|
FanLabeler mFanLabeler;
|
||||||
FanGenerator mFanGenerator;
|
FanGenerator mFanGenerator;
|
||||||
|
|
||||||
|
std::shared_ptr<Settings> mSettings;
|
||||||
|
|
||||||
std::unique_ptr<Controller> mController;
|
std::unique_ptr<Controller> mController;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Fan>> mFans;
|
std::vector<std::shared_ptr<Fan>> mFans;
|
||||||
|
|||||||
@@ -5,11 +5,13 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <Settings.h>
|
||||||
#include <fan/FanCurve.h>
|
#include <fan/FanCurve.h>
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
public:
|
public:
|
||||||
Controller(std::vector<std::shared_ptr<FanCurve>> curves);
|
Controller(std::shared_ptr<Settings> settings,
|
||||||
|
std::vector<std::shared_ptr<FanCurve>> curves);
|
||||||
~Controller();
|
~Controller();
|
||||||
|
|
||||||
void StartFanControlLoop();
|
void StartFanControlLoop();
|
||||||
@@ -18,6 +20,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void Loop();
|
void Loop();
|
||||||
|
|
||||||
|
int mTimeout;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<FanCurve>> mFanCurves;
|
std::vector<std::shared_ptr<FanCurve>> mFanCurves;
|
||||||
std::atomic<bool> mRun;
|
std::atomic<bool> mRun;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#ifndef SERIALIZER_H_
|
#ifndef SERIALIZER_H_
|
||||||
#define SERIALIZER_H_
|
#define SERIALIZER_H_
|
||||||
|
|
||||||
#include "fan/HwmonFan.h"
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include <Settings.h>
|
||||||
#include <fan/Fan.h>
|
#include <fan/Fan.h>
|
||||||
#include <fan/FanCurve.h>
|
#include <fan/FanCurve.h>
|
||||||
#include <sensor/Sensor.h>
|
#include <sensor/Sensor.h>
|
||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
std::vector<std::shared_ptr<FanCurve>>
|
std::vector<std::shared_ptr<FanCurve>>
|
||||||
DeserializeFanCurves(std::vector<std::shared_ptr<Sensor>> availableSensors,
|
DeserializeFanCurves(std::vector<std::shared_ptr<Sensor>> availableSensors,
|
||||||
std::vector<std::shared_ptr<Fan>> availableFans);
|
std::vector<std::shared_ptr<Fan>> availableFans);
|
||||||
|
std::shared_ptr<Settings> DeserializeSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteJson(json o);
|
void WriteJson(json o);
|
||||||
|
|||||||
17
app/include/Settings.h
Normal file
17
app/include/Settings.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef SETTINGS_H_
|
||||||
|
#define SETTINGS_H_
|
||||||
|
|
||||||
|
#define FREQUENCY_DEFAULT 1
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
public:
|
||||||
|
Settings(int frequency);
|
||||||
|
|
||||||
|
int Frequency() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void LogSettings();
|
||||||
|
int mFrequency;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SETTINGS_H_
|
||||||
@@ -10,7 +10,9 @@ void App::Init() {
|
|||||||
auto fanCurves = mSerializer.DeserializeFanCurves(
|
auto fanCurves = mSerializer.DeserializeFanCurves(
|
||||||
mSensorManager.TemperatureSensors(), mFans);
|
mSensorManager.TemperatureSensors(), mFans);
|
||||||
|
|
||||||
mController = make_unique<Controller>(fanCurves);
|
mSettings = mSerializer.DeserializeSettings();
|
||||||
|
|
||||||
|
mController = make_unique<Controller>(mSettings, fanCurves);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::InitialSetup() {
|
void App::InitialSetup() {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define TIMEOUT 500
|
Controller::Controller(shared_ptr<Settings> settings,
|
||||||
|
vector<shared_ptr<FanCurve>> curves)
|
||||||
Controller::Controller(vector<shared_ptr<FanCurve>> curves)
|
: mTimeout((1 / settings->Frequency()) * 1000), mFanCurves(curves),
|
||||||
: mFanCurves(curves), mRun(false) {}
|
mRun(false) {}
|
||||||
|
|
||||||
Controller::~Controller() { StopFanControlLoop(); }
|
Controller::~Controller() { StopFanControlLoop(); }
|
||||||
|
|
||||||
@@ -32,6 +32,6 @@ void Controller::Loop() {
|
|||||||
c->DoFanControl();
|
c->DoFanControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(TIMEOUT));
|
this_thread::sleep_for(chrono::milliseconds(mTimeout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "fan/FanCurve.h"
|
#include "Settings.h"
|
||||||
#include "sensor/Sensor.h"
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -124,3 +123,18 @@ vector<shared_ptr<FanCurve>> Serializer::DeserializeFanCurves(
|
|||||||
|
|
||||||
return curves;
|
return curves;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<Settings> Serializer::DeserializeSettings() {
|
||||||
|
int frequency = FREQUENCY_DEFAULT;
|
||||||
|
|
||||||
|
auto data = ReadJson();
|
||||||
|
|
||||||
|
if (data.contains("settings")) {
|
||||||
|
auto items = data["settings"];
|
||||||
|
|
||||||
|
if (items.contains("frequency"))
|
||||||
|
frequency = items["frequency"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return make_shared<Settings>(frequency);
|
||||||
|
}
|
||||||
|
|||||||
17
app/src/Settings.cxx
Normal file
17
app/src/Settings.cxx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/log/attributes/named_scope.hpp>
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
#include <Settings.h>
|
||||||
|
|
||||||
|
Settings::Settings(int frequency) : mFrequency(frequency) { LogSettings(); }
|
||||||
|
|
||||||
|
int Settings::Frequency() const { return mFrequency; }
|
||||||
|
|
||||||
|
void Settings::LogSettings() {
|
||||||
|
BOOST_LOG_FUNCTION();
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "### Settings";
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Frequency: " << mFrequency << "Hz";
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
#include <boost/log/attributes/named_scope.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <boost/log/trivial.hpp>
|
|
||||||
|
|
||||||
#include <fan/FanCurve.h>
|
#include <fan/FanCurve.h>
|
||||||
|
|
||||||
|
#include <boost/log/attributes/named_scope.hpp>
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
FanCurve::FanCurve(std::vector<FanStep> steps,
|
FanCurve::FanCurve(std::vector<FanStep> steps,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#include <boost/json/object.hpp>
|
#ifdef HAVE_NVML
|
||||||
#include <include/nvml.h>
|
|
||||||
|
|
||||||
|
#include <include/nvml.h>
|
||||||
#include <sensor/NvidiaSensor.h>
|
#include <sensor/NvidiaSensor.h>
|
||||||
|
|
||||||
|
#include <boost/json/object.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
NvidiaSensor::NvidiaSensor() { nvmlInit_v2(); }
|
NvidiaSensor::NvidiaSensor() { nvmlInit_v2(); }
|
||||||
@@ -25,3 +27,5 @@ json NvidiaSensor::toJson() const {
|
|||||||
json obj = {"NvidiaSensor", toString()};
|
json obj = {"NvidiaSensor", toString()};
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -3,20 +3,26 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
SensorManager::SensorManager()
|
SensorManager::SensorManager()
|
||||||
: mLMSensorsFacade(make_unique<LMSensorsFacade>()),
|
: mLMSensorsFacade(make_unique<LMSensorsFacade>())
|
||||||
mGPUSensorsFacade(make_unique<GPUSensorsFacade>()) {}
|
, mGPUSensorsFacade(make_unique<GPUSensorsFacade>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
vector<shared_ptr<Sensor>> SensorManager::TemperatureSensors() {
|
vector<shared_ptr<Sensor>> SensorManager::TemperatureSensors()
|
||||||
|
{
|
||||||
vector<shared_ptr<Sensor>> tempSensors;
|
vector<shared_ptr<Sensor>> tempSensors;
|
||||||
|
|
||||||
tempSensors = mLMSensorsFacade->TemperatureSensors();
|
tempSensors = mLMSensorsFacade->TemperatureSensors();
|
||||||
|
|
||||||
|
#ifdef HAVE_NVML
|
||||||
auto gpuSensors = mGPUSensorsFacade->TemperatureSensors();
|
auto gpuSensors = mGPUSensorsFacade->TemperatureSensors();
|
||||||
tempSensors.insert(tempSensors.end(), gpuSensors.begin(), gpuSensors.end());
|
tempSensors.insert(tempSensors.end(), gpuSensors.begin(), gpuSensors.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
return tempSensors;
|
return tempSensors;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<shared_ptr<Sensor>> SensorManager::RPMSensors() {
|
vector<shared_ptr<Sensor>> SensorManager::RPMSensors()
|
||||||
|
{
|
||||||
return mLMSensorsFacade->RPMSensors();
|
return mLMSensorsFacade->RPMSensors();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user