Expand SensorWrapper
This commit is contained in:
@@ -1,17 +1,29 @@
|
|||||||
#ifndef SENSORSWRAPPER_H_
|
#ifndef SENSORSWRAPPER_H_
|
||||||
#define SENSORSWRAPPER_H_
|
#define SENSORSWRAPPER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <sensors/sensors.h>
|
#include <sensors/sensors.h>
|
||||||
|
|
||||||
|
struct Sensor {
|
||||||
|
sensors_chip_name chipName;
|
||||||
|
sensors_feature feature;
|
||||||
|
sensors_subfeature subFeature;
|
||||||
|
};
|
||||||
|
|
||||||
class SensorsWrapper {
|
class SensorsWrapper {
|
||||||
public:
|
public:
|
||||||
SensorsWrapper();
|
SensorsWrapper();
|
||||||
|
~SensorsWrapper();
|
||||||
|
|
||||||
|
std::vector<Sensor> getTemperatureSensors();
|
||||||
|
int getValue(Sensor sensor);
|
||||||
|
std::string getLabel(Sensor sensor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<const sensors_subfeature *> mTemperatureSensors;
|
std::vector<Sensor> mTemperatureSensors;
|
||||||
std::vector<const sensors_subfeature *> mFanSensors;
|
std::vector<Sensor> mFanSensors;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SENSORSWRAPPER_H_
|
#endif // SENSORSWRAPPER_H_
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ PWM::PWM() {
|
|||||||
|
|
||||||
void PWM::dumpValues() {
|
void PWM::dumpValues() {
|
||||||
for (auto control : mPwmControls) {
|
for (auto control : mPwmControls) {
|
||||||
cout << control.second.control << ", " << control.second.enable << ", "
|
cout << control.second.control << ", " << control.second.enable << ": "
|
||||||
<< control.second.mode << endl;
|
<< control.second.mode << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sensors/sensors.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <SensorsWrapper.h>
|
#include <SensorsWrapper.h>
|
||||||
@@ -24,12 +25,34 @@ SensorsWrapper::SensorsWrapper() {
|
|||||||
auto tempFeature = sensors_get_subfeature(chipName, feature,
|
auto tempFeature = sensors_get_subfeature(chipName, feature,
|
||||||
SENSORS_SUBFEATURE_TEMP_INPUT);
|
SENSORS_SUBFEATURE_TEMP_INPUT);
|
||||||
if (tempFeature)
|
if (tempFeature)
|
||||||
mTemperatureSensors.push_back(tempFeature);
|
mTemperatureSensors.push_back(
|
||||||
|
Sensor{*chipName, *feature, *tempFeature});
|
||||||
|
|
||||||
auto fanFeature = sensors_get_subfeature(chipName, feature,
|
auto fanFeature = sensors_get_subfeature(chipName, feature,
|
||||||
SENSORS_SUBFEATURE_FAN_INPUT);
|
SENSORS_SUBFEATURE_FAN_INPUT);
|
||||||
if (fanFeature)
|
if (fanFeature)
|
||||||
mFanSensors.push_back(fanFeature);
|
mFanSensors.push_back(Sensor{*chipName, *feature, *fanFeature});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SensorsWrapper::~SensorsWrapper() { sensors_cleanup(); }
|
||||||
|
|
||||||
|
std::vector<Sensor> SensorsWrapper::getTemperatureSensors() {
|
||||||
|
return mTemperatureSensors;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SensorsWrapper::getValue(Sensor sensor) {
|
||||||
|
double value;
|
||||||
|
const sensors_chip_name *chipName = &sensor.chipName;
|
||||||
|
|
||||||
|
sensors_get_value(chipName, sensor.subFeature.number, &value);
|
||||||
|
|
||||||
|
return (int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string SensorsWrapper::getLabel(Sensor sensor) {
|
||||||
|
const sensors_chip_name *chipName = &sensor.chipName;
|
||||||
|
const sensors_feature *feature = &sensor.feature;
|
||||||
|
return string(sensors_get_label(chipName, feature));
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <Nvidia.h>
|
#include <Nvidia.h>
|
||||||
#include <Pwm.h>
|
#include <Pwm.h>
|
||||||
|
#include <SensorsWrapper.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto config = std::fopen("/etc/conf.d/sensors", "r");
|
auto config = std::fopen("/etc/conf.d/sensors", "r");
|
||||||
@@ -56,5 +57,15 @@ int main() {
|
|||||||
std::cout << pwm.readValue(controls[0], PWM_CONTROL_PROPERTY::ENABLE)
|
std::cout << pwm.readValue(controls[0], PWM_CONTROL_PROPERTY::ENABLE)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
SensorsWrapper sens;
|
||||||
|
auto sensors = sens.getTemperatureSensors();
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
|
||||||
|
for (auto sensor : sensors) {
|
||||||
|
std::cout << sens.getLabel(sensor) << ": " << sens.getValue(sensor)
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user