Add logic to label fans, some cleanup
This commit is contained in:
@@ -18,6 +18,7 @@ add_executable(app
|
|||||||
src/pwm/PWMControlFacade.cxx
|
src/pwm/PWMControlFacade.cxx
|
||||||
src/fan/HwmonFan.cxx
|
src/fan/HwmonFan.cxx
|
||||||
src/fan/FanCurve.cxx
|
src/fan/FanCurve.cxx
|
||||||
|
src/fan/FanLabeler.cxx
|
||||||
src/FanGenerator.cxx
|
src/FanGenerator.cxx
|
||||||
src/Serializer.cxx
|
src/Serializer.cxx
|
||||||
src/sensor/SensorManager.cxx
|
src/sensor/SensorManager.cxx
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ public:
|
|||||||
virtual void PWM(int percent) = 0;
|
virtual void PWM(int percent) = 0;
|
||||||
virtual int RPM() = 0;
|
virtual int RPM() = 0;
|
||||||
|
|
||||||
|
virtual void Label(std::string label) = 0;
|
||||||
|
virtual void MinPWM(int value) = 0;
|
||||||
|
virtual void StartPWM(int value) = 0;
|
||||||
|
|
||||||
virtual void FindMinPWM() = 0;
|
virtual void FindMinPWM() = 0;
|
||||||
virtual void FindStartPWM() = 0;
|
virtual void FindStartPWM() = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
14
app/include/fan/FanLabeler.h
Normal file
14
app/include/fan/FanLabeler.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef FANLABELER_H_
|
||||||
|
#define FANLABELER_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fan/Fan.h>
|
||||||
|
|
||||||
|
class FanLabeler {
|
||||||
|
public:
|
||||||
|
void RunFanLabelInteraction(std::vector<std::shared_ptr<Fan>> fans);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FANLABELER_H_
|
||||||
@@ -11,12 +11,15 @@
|
|||||||
class HwmonFan : public Fan {
|
class HwmonFan : public Fan {
|
||||||
public:
|
public:
|
||||||
HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
||||||
std::shared_ptr<Sensor> rpmSensor, std::string label = "",
|
std::shared_ptr<Sensor> rpmSensor);
|
||||||
int minPWM = 0, int startPWM = 0);
|
|
||||||
|
|
||||||
void PWM(int percent) override;
|
void PWM(int percent) override;
|
||||||
int RPM() override;
|
int RPM() override;
|
||||||
|
|
||||||
|
void Label(std::string label) override;
|
||||||
|
void MinPWM(int value) override;
|
||||||
|
void StartPWM(int value) override;
|
||||||
|
|
||||||
void FindMinPWM() override;
|
void FindMinPWM() override;
|
||||||
void FindStartPWM() override;
|
void FindStartPWM() override;
|
||||||
|
|
||||||
|
|||||||
8
app/src/Controller.hxx
Normal file
8
app/src/Controller.hxx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef CONTROLLER_H_
|
||||||
|
#define CONTROLLER_H_
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONTROLLER_H_
|
||||||
@@ -46,6 +46,9 @@ Serializer::DeserializeFans(vector<shared_ptr<Sensor>> availableSensors) {
|
|||||||
auto pwmControl = make_shared<PWMControl>(el.value()["PWMControl"]);
|
auto pwmControl = make_shared<PWMControl>(el.value()["PWMControl"]);
|
||||||
auto rpmSensor = sensorMap[el.value()["LMSensor"]];
|
auto rpmSensor = sensorMap[el.value()["LMSensor"]];
|
||||||
|
|
||||||
|
int minPWM = el.value()["MinPWM"];
|
||||||
|
string label = el.value()["Label"];
|
||||||
|
|
||||||
mapping.push_back(make_shared<HwmonFan>(pwmControl, rpmSensor));
|
mapping.push_back(make_shared<HwmonFan>(pwmControl, rpmSensor));
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
@@ -58,7 +61,7 @@ void Serializer::WriteJson(json o) {
|
|||||||
json obj;
|
json obj;
|
||||||
|
|
||||||
if (fs::exists(fs::path(SERIALIZATION_DIR) / FANS_JSON_FILENAME)) {
|
if (fs::exists(fs::path(SERIALIZATION_DIR) / FANS_JSON_FILENAME)) {
|
||||||
auto obj = ReadJson();
|
obj = ReadJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &[key, value] : o.items()) {
|
for (auto &[key, value] : o.items()) {
|
||||||
|
|||||||
41
app/src/fan/FanLabeler.cxx
Normal file
41
app/src/fan/FanLabeler.cxx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <fan/FanLabeler.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void FanLabeler::RunFanLabelInteraction(
|
||||||
|
std::vector<std::shared_ptr<Fan>> fans) {
|
||||||
|
cout << "Setting all fans to their minimum value" << endl;
|
||||||
|
|
||||||
|
for (auto f : fans) {
|
||||||
|
f->PWM(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
for (auto f : fans) {
|
||||||
|
cout << "Setting fan to max power" << endl;
|
||||||
|
|
||||||
|
f->PWM(100);
|
||||||
|
|
||||||
|
cout << "Look inside your PC and check which fan is\n"
|
||||||
|
"spinning fastest and enter a name for it.\n"
|
||||||
|
"Just press enter to skip."
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
getline(cin, name);
|
||||||
|
|
||||||
|
if (!name.empty()) {
|
||||||
|
cout << "Setting " << name << " as label for this fan." << endl;
|
||||||
|
f->Label(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Resetting fan to lowest value\n\n" << endl;
|
||||||
|
f->PWM(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Done!\n" << endl;
|
||||||
|
}
|
||||||
@@ -12,19 +12,31 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
HwmonFan::HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
HwmonFan::HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
||||||
std::shared_ptr<Sensor> rpmSensor, std::string label,
|
std::shared_ptr<Sensor> rpmSensor)
|
||||||
int minPWM, int startPWM)
|
: mPWMControl(pwmControl), mRpmSensor(rpmSensor) {
|
||||||
: mPWMControl(pwmControl), mRpmSensor(rpmSensor), mLabel(label),
|
cout << "Enabling manual control" << endl;
|
||||||
mMinPWM(minPWM), mStartPWM(startPWM) {
|
|
||||||
mPWMControl->EnableManualControl();
|
mPWMControl->EnableManualControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HwmonFan::PWM(int percent) { mPWMControl->pwm(percent); }
|
void HwmonFan::PWM(int percent) {
|
||||||
|
if (percent < mMinPWM) {
|
||||||
|
mPWMControl->pwm(mMinPWM);
|
||||||
|
} else {
|
||||||
|
mPWMControl->pwm(percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int HwmonFan::RPM() { return mRpmSensor->value(); }
|
int HwmonFan::RPM() { return mRpmSensor->value(); }
|
||||||
|
|
||||||
|
void HwmonFan::Label(std::string label) { mLabel = label; }
|
||||||
|
|
||||||
|
void HwmonFan::MinPWM(int value) { mMinPWM = value; }
|
||||||
|
|
||||||
|
void HwmonFan::StartPWM(int value) { mStartPWM = value; }
|
||||||
|
|
||||||
void HwmonFan::FindMinPWM() {
|
void HwmonFan::FindMinPWM() {
|
||||||
int minPWM = 0;
|
int minPWM = 0;
|
||||||
|
mMinPWM = 0;
|
||||||
|
|
||||||
for (int curPWM = 100; curPWM > 0; curPWM -= 5) {
|
for (int curPWM = 100; curPWM > 0; curPWM -= 5) {
|
||||||
PWM(curPWM);
|
PWM(curPWM);
|
||||||
@@ -52,7 +64,7 @@ json HwmonFan::toJson() const {
|
|||||||
json obj;
|
json obj;
|
||||||
obj = {mPWMControl->toJson(),
|
obj = {mPWMControl->toJson(),
|
||||||
mRpmSensor->toJson(),
|
mRpmSensor->toJson(),
|
||||||
{"label", mLabel},
|
{"Label", mLabel},
|
||||||
{"MinPWM", mMinPWM}};
|
{"MinPWM", mMinPWM}};
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <FanGenerator.h>
|
#include <FanGenerator.h>
|
||||||
#include <Serializer.h>
|
#include <Serializer.h>
|
||||||
#include <fan/Fan.h>
|
#include <fan/Fan.h>
|
||||||
|
#include <fan/FanLabeler.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <pstl/glue_execution_defs.h>
|
#include <pstl/glue_execution_defs.h>
|
||||||
#include <pwm/PWMControlFacade.h>
|
#include <pwm/PWMControlFacade.h>
|
||||||
@@ -26,7 +27,14 @@ int main() {
|
|||||||
// s.SerializeFans(fans);
|
// s.SerializeFans(fans);
|
||||||
fans = s.DeserializeFans(pwmSensors);
|
fans = s.DeserializeFans(pwmSensors);
|
||||||
|
|
||||||
auto curves = s.DeserializeFanCurves(tempSensors, fans);
|
std::for_each(std::execution::par, std::begin(fans), std::end(fans),
|
||||||
|
[](auto &&f) { f->FindMinPWM(); });
|
||||||
|
|
||||||
|
// auto curves = s.DeserializeFanCurves(tempSensors, fans);
|
||||||
|
FanLabeler labeler;
|
||||||
|
labeler.RunFanLabelInteraction(fans);
|
||||||
|
|
||||||
|
s.SerializeFans(fans);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user