Implement fan curves and extend serialization logic
This commit is contained in:
@@ -17,6 +17,7 @@ add_executable(app
|
|||||||
src/pwm/PWMControl.cxx
|
src/pwm/PWMControl.cxx
|
||||||
src/pwm/PWMControlFacade.cxx
|
src/pwm/PWMControlFacade.cxx
|
||||||
src/fan/HwmonFan.cxx
|
src/fan/HwmonFan.cxx
|
||||||
|
src/fan/FanCurve.cxx
|
||||||
src/FanGenerator.cxx
|
src/FanGenerator.cxx
|
||||||
src/Serializer.cxx
|
src/Serializer.cxx
|
||||||
src/sensor/SensorManager.cxx
|
src/sensor/SensorManager.cxx
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#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 <fan/Fan.h>
|
#include <fan/Fan.h>
|
||||||
|
#include <fan/FanCurve.h>
|
||||||
#include <sensor/Sensor.h>
|
#include <sensor/Sensor.h>
|
||||||
|
|
||||||
#define SERIALIZATION_DIR "/etc/fantasize"
|
#define SERIALIZATION_DIR "/etc/fantasize"
|
||||||
@@ -20,10 +22,9 @@ public:
|
|||||||
void SerializeFans(std::vector<std::shared_ptr<Fan>> fans);
|
void SerializeFans(std::vector<std::shared_ptr<Fan>> fans);
|
||||||
std::vector<std::shared_ptr<Fan>>
|
std::vector<std::shared_ptr<Fan>>
|
||||||
DeserializeFans(std::vector<std::shared_ptr<Sensor>> availableSensors);
|
DeserializeFans(std::vector<std::shared_ptr<Sensor>> availableSensors);
|
||||||
|
std::vector<std::shared_ptr<FanCurve>>
|
||||||
void SerializeTempSensors(std::vector<std::shared_ptr<Sensor>> senors);
|
DeserializeFanCurves(std::vector<std::shared_ptr<Sensor>> availableSensors,
|
||||||
std::vector<std::shared_ptr<Sensor>>
|
std::vector<std::shared_ptr<Fan>> availableFans);
|
||||||
DeserializeTempSensors(std::vector<std::shared_ptr<Sensor>> availableSensors);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteJson(json o);
|
void WriteJson(json o);
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ struct FanStep {
|
|||||||
|
|
||||||
class FanCurve {
|
class FanCurve {
|
||||||
public:
|
public:
|
||||||
|
FanCurve(std::vector<FanStep> steps,
|
||||||
|
std::vector<std::shared_ptr<Sensor>> sensors,
|
||||||
|
std::vector<std::shared_ptr<Fan>> fans);
|
||||||
|
|
||||||
void DoFanControl();
|
void DoFanControl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -21,7 +25,7 @@ private:
|
|||||||
|
|
||||||
std::vector<FanStep> mSteps;
|
std::vector<FanStep> mSteps;
|
||||||
std::vector<std::shared_ptr<Sensor>> mTempSensors;
|
std::vector<std::shared_ptr<Sensor>> mTempSensors;
|
||||||
std::vector<std::shared_ptr<HwmonFan>> mFans;
|
std::vector<std::shared_ptr<Fan>> mFans;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FANCURVE_H_
|
#endif // FANCURVE_H_
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "fan/FanCurve.h"
|
||||||
|
#include "sensor/Sensor.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -72,16 +74,42 @@ json Serializer::ReadJson() {
|
|||||||
return json::parse(istrm);
|
return json::parse(istrm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serializer::SerializeTempSensors(vector<shared_ptr<Sensor>> sensors) {
|
vector<shared_ptr<FanCurve>> Serializer::DeserializeFanCurves(
|
||||||
json obj;
|
std::vector<std::shared_ptr<Sensor>> availableSensors,
|
||||||
|
std::vector<std::shared_ptr<Fan>> availableFans) {
|
||||||
|
auto data = ReadJson();
|
||||||
|
|
||||||
for (auto s : sensors) {
|
map<string, shared_ptr<Sensor>> sensorMap;
|
||||||
obj["tempSensors"].push_back(s->toJson());
|
for (auto s : availableSensors) {
|
||||||
|
sensorMap[s->toString()] = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteJson(obj);
|
map<string, shared_ptr<Fan>> fanMap;
|
||||||
}
|
for (auto f : availableFans) {
|
||||||
vector<shared_ptr<Sensor>>
|
fanMap[f->toString()] = f;
|
||||||
DeserializeTempSensors(vector<shared_ptr<Sensor>> availableSensors) {
|
}
|
||||||
return vector<shared_ptr<Sensor>>();
|
|
||||||
|
vector<shared_ptr<FanCurve>> curves;
|
||||||
|
|
||||||
|
for (auto &el : data["fancurves"].items()) {
|
||||||
|
vector<FanStep> steps;
|
||||||
|
vector<shared_ptr<Sensor>> sensors;
|
||||||
|
vector<shared_ptr<Fan>> fans;
|
||||||
|
|
||||||
|
for (auto &step : el.value()["FanSteps"].items()) {
|
||||||
|
FanStep fanStep{step.value()[0], step.value()[1]};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &sensor : el.value()["Sensors"].items()) {
|
||||||
|
sensors.push_back(sensorMap[sensor.value()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &fan : el.value()["Fans"].items()) {
|
||||||
|
fans.push_back(fanMap[fan.value()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
curves.push_back(make_shared<FanCurve>(steps, sensors, fans));
|
||||||
|
}
|
||||||
|
|
||||||
|
return curves;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
FanCurve::FanCurve(std::vector<FanStep> steps,
|
||||||
|
std::vector<std::shared_ptr<Sensor>> sensors,
|
||||||
|
std::vector<std::shared_ptr<Fan>> fans)
|
||||||
|
: mSteps(steps), mTempSensors(sensors), mFans(fans) {}
|
||||||
|
|
||||||
void FanCurve::DoFanControl() {
|
void FanCurve::DoFanControl() {
|
||||||
int temp = AggregateTemperature();
|
int temp = AggregateTemperature();
|
||||||
|
|
||||||
@@ -30,7 +35,7 @@ void FanCurve::DoFanControl() {
|
|||||||
int targetFanSpeed = p0 + ((p1 - p0) / (t1 - t0)) * (temp - t0);
|
int targetFanSpeed = p0 + ((p1 - p0) / (t1 - t0)) * (temp - t0);
|
||||||
|
|
||||||
for (auto f : mFans) {
|
for (auto f : mFans) {
|
||||||
f->pwm(targetFanSpeed);
|
f->PWM(targetFanSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
int main() {
|
int main() {
|
||||||
SensorManager sensorManager;
|
SensorManager sensorManager;
|
||||||
auto pwmSensors = sensorManager.RPMSensors();
|
auto pwmSensors = sensorManager.RPMSensors();
|
||||||
|
auto tempSensors = sensorManager.TemperatureSensors();
|
||||||
|
|
||||||
PWMControlFacade pwmControlFacade;
|
PWMControlFacade pwmControlFacade;
|
||||||
auto controls = pwmControlFacade.PWMControls();
|
auto controls = pwmControlFacade.PWMControls();
|
||||||
@@ -25,10 +26,7 @@ int main() {
|
|||||||
// s.SerializeFans(fans);
|
// s.SerializeFans(fans);
|
||||||
fans = s.DeserializeFans(pwmSensors);
|
fans = s.DeserializeFans(pwmSensors);
|
||||||
|
|
||||||
std::for_each(std::execution::par, std::begin(fans), std::end(fans),
|
auto curves = s.DeserializeFanCurves(tempSensors, fans);
|
||||||
[](auto &&f) { f->FindMinPWM(); });
|
|
||||||
|
|
||||||
s.SerializeFans(fans);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user