Various fixes

- Change unit path
- Rename method
- Make CurrentPWM method return its value in PWM instead of percent
This commit is contained in:
2023-10-08 13:50:33 +02:00
parent 0a6bab36be
commit e2509cea8b
5 changed files with 12 additions and 12 deletions

View File

@@ -15,8 +15,8 @@ public:
PWMControl(std::string controlPath);
~PWMControl();
void Power(int percent);
int Power();
void SetPower(int percent);
int CurrentPWM();
void EnableManualControl();
void Reset();

View File

@@ -34,4 +34,4 @@ exe = executable('fantasize',
install: true,
include_directories: inc)
install_data('unit/fantasize.service', install_dir : 'usr/lib/systemd/system')
install_data('unit/fantasize.service', install_dir : '/usr/lib/systemd/system')

View File

@@ -22,7 +22,7 @@ FanGenerator::FindFans(vector<shared_ptr<Sensor>> rpmSensors,
cout << "Setting all fans to maximum speed" << endl;
for (auto c : pwmControls) {
c->EnableManualControl();
c->Power(100);
c->SetPower(100);
}
// Wait for fans to settle
@@ -41,7 +41,7 @@ FanGenerator::FindFans(vector<shared_ptr<Sensor>> rpmSensors,
for (auto c : pwmControls) {
cout << "Setting " << c->toString()
<< " to 50% and wait for it to settle..." << endl;
c->Power(50);
c->SetPower(50);
this_thread::sleep_for(chrono::seconds(SETTLE_TIMEOUT));
@@ -53,7 +53,7 @@ FanGenerator::FindFans(vector<shared_ptr<Sensor>> rpmSensors,
}
cout << "Setting fan back to 100%" << endl;
c->Power(100);
c->SetPower(100);
}
return mapping;

View File

@@ -53,7 +53,7 @@ bool HwmonFan::InhibitStopPeriodExpired() {
}
void HwmonFan::SetPower(int percent) {
mPWMControl->Power(percent);
mPWMControl->SetPower(percent);
mSetValue = percent;
}
@@ -129,7 +129,7 @@ void HwmonFan::AdjustPWMLimits() {
}
}
void HwmonFan::EnforceSetValue() { mPWMControl->Power(mSetValue); }
void HwmonFan::EnforceSetValue() { mPWMControl->SetPower(mSetValue); }
json HwmonFan::toJson() const {
json obj;

View File

@@ -40,12 +40,12 @@ PWMControl::~PWMControl() {
Reset();
}
void PWMControl::Power(int percent) {
void PWMControl::SetPower(int percent) {
BOOST_LOG_FUNCTION();
int pwmValue = (PWM_MAX_VALUE * percent) / 100;
if (percent != Power()) {
if (pwmValue != CurrentPWM()) {
BOOST_LOG_TRIVIAL(trace) << "Updating control value of " << toString()
<< " to " << percent << "% (" << pwmValue << ")";
ofstream ostrm(mControlPath, ios::trunc);
@@ -54,14 +54,14 @@ void PWMControl::Power(int percent) {
}
}
int PWMControl::Power() {
int PWMControl::CurrentPWM() {
int value;
ifstream istrm;
istrm.open(mControlPath);
istrm >> value;
return (value * 100) / PWM_MAX_VALUE;
return value;
}
void PWMControl::EnableManualControl() {