Implement min PWM finding logic
This commit is contained in:
@@ -22,7 +22,7 @@ add_executable(app
|
|||||||
src/sensor/SensorManager.cxx
|
src/sensor/SensorManager.cxx
|
||||||
)
|
)
|
||||||
|
|
||||||
set_property(TARGET app PROPERTY CXX_STANDARD 17)
|
set_property(TARGET app PROPERTY CXX_STANDARD 20)
|
||||||
|
|
||||||
target_include_directories(app PUBLIC include /opt/cuda)
|
target_include_directories(app PUBLIC include /opt/cuda)
|
||||||
target_link_libraries(app PUBLIC sensors nvidia-ml nlohmann_json::nlohmann_json)
|
target_link_libraries(app PUBLIC sensors nvidia-ml nlohmann_json::nlohmann_json tbb)
|
||||||
|
|||||||
@@ -6,8 +6,11 @@
|
|||||||
|
|
||||||
class Fan : public Serializable, public Printable {
|
class Fan : public Serializable, public Printable {
|
||||||
public:
|
public:
|
||||||
virtual void pwm(int percent) = 0;
|
virtual void PWM(int percent) = 0;
|
||||||
virtual int rpm() = 0;
|
virtual int RPM() = 0;
|
||||||
|
|
||||||
|
virtual void FindMinPWM() = 0;
|
||||||
|
virtual void FindStartPWM() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FAN_H_
|
#endif // FAN_H_
|
||||||
|
|||||||
@@ -11,10 +11,14 @@
|
|||||||
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::shared_ptr<Sensor> rpmSensor, std::string label = "",
|
||||||
|
int minPWM = 0, int startPWM = 0);
|
||||||
|
|
||||||
void pwm(int percent) override;
|
void PWM(int percent) override;
|
||||||
int rpm() override;
|
int RPM() override;
|
||||||
|
|
||||||
|
void FindMinPWM() override;
|
||||||
|
void FindStartPWM() override;
|
||||||
|
|
||||||
json toJson() const override;
|
json toJson() const override;
|
||||||
|
|
||||||
@@ -24,6 +28,9 @@ private:
|
|||||||
std::shared_ptr<PWMControl> mPWMControl;
|
std::shared_ptr<PWMControl> mPWMControl;
|
||||||
std::shared_ptr<Sensor> mRpmSensor;
|
std::shared_ptr<Sensor> mRpmSensor;
|
||||||
std::string mLabel;
|
std::string mLabel;
|
||||||
|
|
||||||
|
int mMinPWM;
|
||||||
|
int mStartPWM;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HWMONFAN_H_
|
#endif // HWMONFAN_H_
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "FanGenerator.h"
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|||||||
@@ -1,20 +1,59 @@
|
|||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "pwm/PWMControl.h"
|
#include "pwm/PWMControl.h"
|
||||||
#include <boost/json/object.hpp>
|
#include <boost/json/object.hpp>
|
||||||
#include <fan/HwmonFan.h>
|
#include <fan/HwmonFan.h>
|
||||||
|
|
||||||
|
#define TIMEOUT 5
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
HwmonFan::HwmonFan(shared_ptr<PWMControl> pwmControl,
|
HwmonFan::HwmonFan(std::shared_ptr<PWMControl> pwmControl,
|
||||||
shared_ptr<Sensor> rpmSensor)
|
std::shared_ptr<Sensor> rpmSensor, std::string label,
|
||||||
: mPWMControl(pwmControl), mRpmSensor(rpmSensor) {}
|
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 HwmonFan::toJson() const {
|
||||||
json obj;
|
json obj;
|
||||||
obj = {mPWMControl->toJson(), mRpmSensor->toJson(), mLabel};
|
obj = {mPWMControl->toJson(),
|
||||||
|
mRpmSensor->toJson(),
|
||||||
|
{"label", mLabel},
|
||||||
|
{"MinPWM", mMinPWM}};
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
#include <execution>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <FanGenerator.h>
|
#include <FanGenerator.h>
|
||||||
#include <Serializer.h>
|
#include <Serializer.h>
|
||||||
#include <fan/Fan.h>
|
#include <fan/Fan.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <pstl/glue_execution_defs.h>
|
||||||
#include <pwm/PWMControlFacade.h>
|
#include <pwm/PWMControlFacade.h>
|
||||||
#include <sensor/SensorManager.h>
|
#include <sensor/SensorManager.h>
|
||||||
|
|
||||||
@@ -18,11 +21,14 @@ int main() {
|
|||||||
|
|
||||||
std::vector<std::shared_ptr<Fan>> fans;
|
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::for_each(std::execution::par, std::begin(fans), std::end(fans),
|
||||||
std::cout << f->toString() << std::endl;
|
[](auto &&f) { f->FindMinPWM(); });
|
||||||
}
|
|
||||||
|
s.SerializeFans(fans);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ const string LMSensor::toString() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
json LMSensor::toJson() const {
|
json LMSensor::toJson() const {
|
||||||
json obj = {"HwmonSensor", toString()};
|
json obj = {"LMSensor", toString()};
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user