Add logic to label fans, some cleanup
This commit is contained in:
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;
|
||||
|
||||
HwmonFan::HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
||||
std::shared_ptr<Sensor> rpmSensor, std::string label,
|
||||
int minPWM, int startPWM)
|
||||
: mPWMControl(pwmControl), mRpmSensor(rpmSensor), mLabel(label),
|
||||
mMinPWM(minPWM), mStartPWM(startPWM) {
|
||||
std::shared_ptr<Sensor> rpmSensor)
|
||||
: mPWMControl(pwmControl), mRpmSensor(rpmSensor) {
|
||||
cout << "Enabling manual control" << endl;
|
||||
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(); }
|
||||
|
||||
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() {
|
||||
int minPWM = 0;
|
||||
mMinPWM = 0;
|
||||
|
||||
for (int curPWM = 100; curPWM > 0; curPWM -= 5) {
|
||||
PWM(curPWM);
|
||||
@@ -52,7 +64,7 @@ json HwmonFan::toJson() const {
|
||||
json obj;
|
||||
obj = {mPWMControl->toJson(),
|
||||
mRpmSensor->toJson(),
|
||||
{"label", mLabel},
|
||||
{"Label", mLabel},
|
||||
{"MinPWM", mMinPWM}};
|
||||
return obj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user