Cleanup main, use new sensor implementation
This commit is contained in:
@@ -7,14 +7,14 @@
|
|||||||
|
|
||||||
class HwmonTemperatureSensor : public TemperatureSensor {
|
class HwmonTemperatureSensor : public TemperatureSensor {
|
||||||
public:
|
public:
|
||||||
HwmonTemperatureSensor(sensors_chip_name chipName,
|
HwmonTemperatureSensor(const sensors_chip_name *chipName,
|
||||||
sensors_subfeature subfeature);
|
const sensors_subfeature *subfeature);
|
||||||
|
|
||||||
int getTemperature() override;
|
int getTemperature() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sensors_chip_name mChipName;
|
const sensors_chip_name *mChipName;
|
||||||
sensors_subfeature mSubFeature;
|
const sensors_subfeature *mSubFeature;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HWMONTEMPERATURESENSOR_H_
|
#endif // HWMONTEMPERATURESENSOR_H_
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef TEMPERATURESENSOR_H_
|
#ifndef TEMPERATURESENSOR_H_
|
||||||
#define TEMPERATURESENSOR_H_
|
#define TEMPERATURESENSOR_H_
|
||||||
|
|
||||||
#include <boost/json.hpp>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class TemperatureSensor {
|
class TemperatureSensor {
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
HwmonTemperatureSensor::HwmonTemperatureSensor(sensors_chip_name chipName,
|
HwmonTemperatureSensor::HwmonTemperatureSensor(
|
||||||
sensors_subfeature subfeature)
|
const sensors_chip_name *chipName, const sensors_subfeature *subfeature)
|
||||||
: mChipName(chipName), mSubFeature(subfeature) {}
|
: mChipName(chipName), mSubFeature(subfeature) {}
|
||||||
|
|
||||||
int HwmonTemperatureSensor::getTemperature() {
|
int HwmonTemperatureSensor::getTemperature() {
|
||||||
double *value;
|
double *value;
|
||||||
sensors_get_value(&mChipName, mSubFeature.number, value);
|
sensors_get_value(mChipName, mSubFeature->number, value);
|
||||||
|
|
||||||
return static_cast<int>(*value);
|
return static_cast<int>(*value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,43 @@
|
|||||||
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <sensors/sensors.h>
|
#include <sensors/sensors.h>
|
||||||
|
|
||||||
|
#include <HwmonTemperatureSensor.h>
|
||||||
#include <Nvidia.h>
|
#include <Nvidia.h>
|
||||||
#include <Pwm.h>
|
#include <Pwm.h>
|
||||||
#include <SensorsWrapper.h>
|
|
||||||
|
|
||||||
int main() {
|
#define CONFIG_FILE "/etc/conf.d/sensors"
|
||||||
auto config = std::fopen("/etc/conf.d/sensors", "r");
|
|
||||||
|
std::vector<std::shared_ptr<TemperatureSensor>> sensors() {
|
||||||
|
std::vector<std::shared_ptr<TemperatureSensor>> sensors;
|
||||||
|
|
||||||
|
auto config = fopen(CONFIG_FILE, "r");
|
||||||
if (sensors_init(config) != 0) {
|
if (sensors_init(config) != 0) {
|
||||||
std::cout << "Fuck" << std::endl;
|
throw std::runtime_error("Config file doesn't exist");
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (const sensors_chip_name *i;
|
for (const sensors_chip_name *chipName;
|
||||||
(i = sensors_get_detected_chips(0, &c)) != NULL;) {
|
(chipName = sensors_get_detected_chips(0, &c)) != NULL;) {
|
||||||
std::cout << "Prefix: " << i->prefix << std::endl;
|
|
||||||
|
|
||||||
size_t size;
|
|
||||||
char *string;
|
|
||||||
|
|
||||||
sensors_snprintf_chip_name(string, size, i);
|
|
||||||
|
|
||||||
std::cout << std::string(string) << std::endl;
|
|
||||||
|
|
||||||
int d = 0;
|
int d = 0;
|
||||||
for (const sensors_feature *j; (j = sensors_get_features(i, &d)) != NULL;) {
|
for (const sensors_feature *feature;
|
||||||
const sensors_subfeature *temp_feature =
|
(feature = sensors_get_features(chipName, &d)) != NULL;) {
|
||||||
sensors_get_subfeature(i, j, SENSORS_SUBFEATURE_TEMP_INPUT);
|
auto tempFeature = sensors_get_subfeature(chipName, feature,
|
||||||
if (temp_feature) {
|
SENSORS_SUBFEATURE_TEMP_INPUT);
|
||||||
std::cout << sensors_get_label(i, j);
|
if (tempFeature)
|
||||||
|
sensors.push_back(
|
||||||
double value;
|
std::make_shared<HwmonTemperatureSensor>(chipName, tempFeature));
|
||||||
if (sensors_get_value(i, temp_feature->number, &value) == 0)
|
|
||||||
std::cout << ": " << value << " C" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sensors_subfeature *fan_feature =
|
|
||||||
sensors_get_subfeature(i, j, SENSORS_SUBFEATURE_FAN_INPUT);
|
|
||||||
|
|
||||||
if (fan_feature) {
|
|
||||||
std::cout << sensors_get_label(i, j);
|
|
||||||
|
|
||||||
double value;
|
|
||||||
if (sensors_get_value(i, fan_feature->number, &value) == 0)
|
|
||||||
std::cout << ": " << value << " RPM" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
return sensors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
Nvidia nv;
|
Nvidia nv;
|
||||||
auto temp = nv.get_gpu_temperature();
|
auto temp = nv.get_gpu_temperature();
|
||||||
std::cout << "\nGPU Temp: " << temp << std::endl;
|
std::cout << "\nGPU Temp: " << temp << std::endl;
|
||||||
@@ -64,14 +50,10 @@ 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 tempSensors = sensors();
|
||||||
auto sensors = sens.getTemperatureSensors();
|
|
||||||
|
|
||||||
std::cout << "\n";
|
for (auto s : tempSensors) {
|
||||||
|
std::cout << s->getTemperature() << std::endl;
|
||||||
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