Add function to read PWM control values
This commit is contained in:
16
app/include/CorrelatePwmRpm.h
Normal file
16
app/include/CorrelatePwmRpm.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef CORRELATEPWMRPM_H_
|
||||||
|
#define CORRELATEPWMRPM_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** What I need:
|
||||||
|
** - All system RPM sensors
|
||||||
|
** - All system PWM controls
|
||||||
|
**
|
||||||
|
** ToDo: Find which PWM controller affects which RPM sensor
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
class CorrelatePwmRpm {
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CORRELATEPWMRPM_H_
|
||||||
@@ -5,14 +5,19 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
typedef struct {
|
enum class PWM_CONTROL_PROPERTY { CONTROL, ENABLE, MODE };
|
||||||
|
|
||||||
|
struct PWM_CONTROL {
|
||||||
std::string control;
|
std::string control;
|
||||||
std::string enable;
|
std::string enable;
|
||||||
std::string mode;
|
std::string mode;
|
||||||
} PWM_CONTROL;
|
|
||||||
|
|
||||||
typedef enum { FULL_SPEED = 0, MANUAL_CONTROL, AUTOMATIC } PWM_ENABLE;
|
std::string initialEnable;
|
||||||
typedef enum { DC = 0, PWM } PWM_MODE;
|
std::string initialMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class PWM_ENABLE { FULL_SPEED = 0, MANUAL_CONTROL };
|
||||||
|
enum class PWM_MODE { DC = 0, PWM };
|
||||||
|
|
||||||
class PWM {
|
class PWM {
|
||||||
public:
|
public:
|
||||||
@@ -20,6 +25,7 @@ public:
|
|||||||
void dumpValues();
|
void dumpValues();
|
||||||
|
|
||||||
std::vector<PWM_CONTROL> getControls();
|
std::vector<PWM_CONTROL> getControls();
|
||||||
|
int readValue(PWM_CONTROL control, PWM_CONTROL_PROPERTY property);
|
||||||
|
|
||||||
void setEnable(PWM_CONTROL control, PWM_ENABLE value);
|
void setEnable(PWM_CONTROL control, PWM_ENABLE value);
|
||||||
void setMode(PWM_CONTROL control, PWM_MODE mode);
|
void setMode(PWM_CONTROL control, PWM_MODE mode);
|
||||||
|
|||||||
@@ -48,11 +48,12 @@ int main() {
|
|||||||
std::cout << "\nGPU Temp: " << temp << std::endl;
|
std::cout << "\nGPU Temp: " << temp << std::endl;
|
||||||
|
|
||||||
class PWM pwm;
|
class PWM pwm;
|
||||||
|
std::cout << '\n';
|
||||||
pwm.dumpValues();
|
pwm.dumpValues();
|
||||||
|
|
||||||
auto controls = pwm.getControls();
|
auto controls = pwm.getControls();
|
||||||
|
std::cout << pwm.readValue(controls[0], PWM_CONTROL_PROPERTY::ENABLE)
|
||||||
pwm.setEnable(controls[1], AUTOMATIC);
|
<< std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ PWM::PWM() {
|
|||||||
fs::path path_ctrl_mode(
|
fs::path path_ctrl_mode(
|
||||||
string(controlPath + string(PWM_POSTFIX_MODE)));
|
string(controlPath + string(PWM_POSTFIX_MODE)));
|
||||||
|
|
||||||
if (fs::exists(path_ctrl_enable) && fs::exists(path_ctrl_mode))
|
|
||||||
cout << control << endl;
|
|
||||||
|
|
||||||
mPwmControls.insert(
|
mPwmControls.insert(
|
||||||
{controlPath, PWM_CONTROL{controlPath, path_ctrl_enable.string(),
|
{controlPath, PWM_CONTROL{controlPath, path_ctrl_enable.string(),
|
||||||
path_ctrl_mode.string()}});
|
path_ctrl_mode.string()}});
|
||||||
@@ -59,8 +56,8 @@ void PWM::dumpValues() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<PWM_CONTROL> PWM::getControls() {
|
vector<PWM_CONTROL> PWM::getControls() {
|
||||||
std::vector<PWM_CONTROL> vec;
|
vector<PWM_CONTROL> vec;
|
||||||
|
|
||||||
for (auto elem : mPwmControls) {
|
for (auto elem : mPwmControls) {
|
||||||
vec.push_back(elem.second);
|
vec.push_back(elem.second);
|
||||||
@@ -71,8 +68,8 @@ std::vector<PWM_CONTROL> PWM::getControls() {
|
|||||||
|
|
||||||
void PWM::setEnable(PWM_CONTROL control, PWM_ENABLE value) {
|
void PWM::setEnable(PWM_CONTROL control, PWM_ENABLE value) {
|
||||||
cout << control.control << endl;
|
cout << control.control << endl;
|
||||||
std::ofstream ostrm(control.enable, std::ios::trunc);
|
ofstream ostrm(control.enable, ios::trunc);
|
||||||
ostrm << value;
|
ostrm << static_cast<int>(value);
|
||||||
ostrm.close();
|
ostrm.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,10 +77,33 @@ void PWM::setValuePwm(PWM_CONTROL control, int pwm) {
|
|||||||
if (pwm < 0 || pwm > 255)
|
if (pwm < 0 || pwm > 255)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::ofstream ostrm(control.control, std::ios::trunc);
|
ofstream ostrm(control.control, ios::trunc);
|
||||||
ostrm << pwm;
|
ostrm << pwm;
|
||||||
ostrm.close();
|
ostrm.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PWM::readValue(PWM_CONTROL control, PWM_CONTROL_PROPERTY property) {
|
||||||
|
int result;
|
||||||
|
ifstream istrm;
|
||||||
|
|
||||||
|
switch (property) {
|
||||||
|
case PWM_CONTROL_PROPERTY::CONTROL:
|
||||||
|
istrm.open(control.control, ios::in);
|
||||||
|
istrm >> result;
|
||||||
|
break;
|
||||||
|
case PWM_CONTROL_PROPERTY::ENABLE:
|
||||||
|
istrm.open(control.enable, ios::in);
|
||||||
|
istrm >> result;
|
||||||
|
break;
|
||||||
|
case PWM_CONTROL_PROPERTY::MODE:
|
||||||
|
istrm.open(control.mode, ios::in);
|
||||||
|
istrm >> result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void PWM::setValuePercent(PWM_CONTROL control, int percentage) {
|
void PWM::setValuePercent(PWM_CONTROL control, int percentage) {
|
||||||
setValuePwm(control, PWM_MAX_VALUE * percentage / 100);
|
setValuePwm(control, PWM_MAX_VALUE * percentage / 100);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user