Implement min PWM finding logic
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#include "FanGenerator.h"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
@@ -1,20 +1,59 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <thread>
|
||||
|
||||
#include "pwm/PWMControl.h"
|
||||
#include <boost/json/object.hpp>
|
||||
#include <fan/HwmonFan.h>
|
||||
|
||||
#define TIMEOUT 5
|
||||
|
||||
using namespace std;
|
||||
|
||||
HwmonFan::HwmonFan(shared_ptr<PWMControl> pwmControl,
|
||||
shared_ptr<Sensor> rpmSensor)
|
||||
: mPWMControl(pwmControl), mRpmSensor(rpmSensor) {}
|
||||
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) {
|
||||
mPWMControl->EnableManualControl();
|
||||
}
|
||||
|
||||
void HwmonFan::pwm(int percent) { mPWMControl->pwm(percent); }
|
||||
void HwmonFan::PWM(int percent) { mPWMControl->pwm(percent); }
|
||||
|
||||
int HwmonFan::rpm() { return mRpmSensor->value(); }
|
||||
int HwmonFan::RPM() { return mRpmSensor->value(); }
|
||||
|
||||
void HwmonFan::FindMinPWM() {
|
||||
int minPWM = 0;
|
||||
|
||||
for (int curPWM = 100; curPWM > 0; curPWM -= 5) {
|
||||
PWM(curPWM);
|
||||
this_thread::sleep_for(chrono::seconds(TIMEOUT));
|
||||
|
||||
int curRPM = RPM();
|
||||
|
||||
if (curRPM <= 0) {
|
||||
minPWM = curPWM + 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (minPWM == 0) {
|
||||
cout << "Fan never stopped. ";
|
||||
}
|
||||
cout << "Setting minimal PWM: " << minPWM << endl;
|
||||
|
||||
mMinPWM = minPWM;
|
||||
}
|
||||
|
||||
void HwmonFan::FindStartPWM() {}
|
||||
|
||||
json HwmonFan::toJson() const {
|
||||
json obj;
|
||||
obj = {mPWMControl->toJson(), mRpmSensor->toJson(), mLabel};
|
||||
obj = {mPWMControl->toJson(),
|
||||
mRpmSensor->toJson(),
|
||||
{"label", mLabel},
|
||||
{"MinPWM", mMinPWM}};
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include <execution>
|
||||
#include <iostream>
|
||||
|
||||
#include <FanGenerator.h>
|
||||
#include <Serializer.h>
|
||||
#include <fan/Fan.h>
|
||||
#include <memory>
|
||||
#include <pstl/glue_execution_defs.h>
|
||||
#include <pwm/PWMControlFacade.h>
|
||||
#include <sensor/SensorManager.h>
|
||||
|
||||
@@ -18,11 +21,14 @@ int main() {
|
||||
|
||||
std::vector<std::shared_ptr<Fan>> fans;
|
||||
|
||||
fans = m.FindFans(pwmSensors, controls);
|
||||
// fans = m.FindFans(pwmSensors, controls);
|
||||
// s.SerializeFans(fans);
|
||||
fans = s.DeserializeFans(pwmSensors);
|
||||
|
||||
for (auto f : fans) {
|
||||
std::cout << f->toString() << std::endl;
|
||||
}
|
||||
std::for_each(std::execution::par, std::begin(fans), std::end(fans),
|
||||
[](auto &&f) { f->FindMinPWM(); });
|
||||
|
||||
s.SerializeFans(fans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ const string LMSensor::toString() const {
|
||||
}
|
||||
|
||||
json LMSensor::toJson() const {
|
||||
json obj = {"HwmonSensor", toString()};
|
||||
json obj = {"LMSensor", toString()};
|
||||
return obj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user