Add Fan stubs, rework Sensors classes
This commit is contained in:
10
app/include/Fan.h
Normal file
10
app/include/Fan.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef FAN_H_
|
||||||
|
#define FAN_H_
|
||||||
|
|
||||||
|
class Fan {
|
||||||
|
public:
|
||||||
|
virtual void PWM(int value) = 0;
|
||||||
|
virtual int RPM() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FAN_H_
|
||||||
12
app/include/HwmonFan.h
Normal file
12
app/include/HwmonFan.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef HWMONFAN_H_
|
||||||
|
#define HWMONFAN_H_
|
||||||
|
|
||||||
|
#include <Fan.h>
|
||||||
|
|
||||||
|
class HwmonFan : public Fan {
|
||||||
|
public:
|
||||||
|
void PWM(int value) override;
|
||||||
|
int RPM() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // HWMONFAN_H_
|
||||||
@@ -7,8 +7,10 @@
|
|||||||
|
|
||||||
class HwmonTemperatureSensor : public TemperatureSensor {
|
class HwmonTemperatureSensor : public TemperatureSensor {
|
||||||
public:
|
public:
|
||||||
|
HwmonTemperatureSensor(sensors_chip_name chipName,
|
||||||
|
sensors_subfeature subfeature);
|
||||||
|
|
||||||
int getTemperature() override;
|
int getTemperature() override;
|
||||||
std::string toJson() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sensors_chip_name mChipName;
|
sensors_chip_name mChipName;
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#ifndef TEMPERATURESENSOR_H_
|
#ifndef TEMPERATURESENSOR_H_
|
||||||
#define TEMPERATURESENSOR_H_
|
#define TEMPERATURESENSOR_H_
|
||||||
|
|
||||||
|
#include <boost/json.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class TemperatureSensor {
|
class TemperatureSensor {
|
||||||
public:
|
public:
|
||||||
virtual int getTemperature() = 0;
|
virtual int getTemperature() = 0;
|
||||||
virtual std::string toJson() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEMPERATURESENSOR_H_
|
#endif // TEMPERATURESENSOR_H_
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#include <boost/json.hpp>
|
|
||||||
#include <boost/json/parse.hpp>
|
|
||||||
#include <sensors/sensors.h>
|
#include <sensors/sensors.h>
|
||||||
|
|
||||||
#include <HwmonTemperatureSensor.h>
|
#include <HwmonTemperatureSensor.h>
|
||||||
|
|
||||||
using namespace boost::json;
|
using namespace std;
|
||||||
|
|
||||||
#define SENSOR_TYPE_STRING "HWMON"
|
HwmonTemperatureSensor::HwmonTemperatureSensor(sensors_chip_name chipName,
|
||||||
|
sensors_subfeature subfeature)
|
||||||
|
: mChipName(chipName), mSubFeature(subfeature) {}
|
||||||
|
|
||||||
int HwmonTemperatureSensor::getTemperature() {
|
int HwmonTemperatureSensor::getTemperature() {
|
||||||
double *value;
|
double *value;
|
||||||
@@ -14,20 +14,3 @@ int HwmonTemperatureSensor::getTemperature() {
|
|||||||
|
|
||||||
return static_cast<int>(*value);
|
return static_cast<int>(*value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tag_invoke(value_from_tag, value &jv, sensors_bus_id &c) {
|
|
||||||
jv = {{"type", c.type}, {"nr", c.nr}};
|
|
||||||
}
|
|
||||||
|
|
||||||
void tag_invoke(value_from_tag, value &jv, sensors_chip_name &c) {
|
|
||||||
jv = {{"prefix", c.prefix},
|
|
||||||
{"sensors_bus_id", value_from(c.bus)},
|
|
||||||
{"addr", c.addr},
|
|
||||||
{"path", c.path}};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string HwmonTemperatureSensor::toJson() {
|
|
||||||
value jv = {{SENSOR_TYPE_STRING, {"ChipName", value_from(mChipName)}}};
|
|
||||||
|
|
||||||
return serialize(jv);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,7 +16,14 @@ int main() {
|
|||||||
int c = 0;
|
int c = 0;
|
||||||
for (const sensors_chip_name *i;
|
for (const sensors_chip_name *i;
|
||||||
(i = sensors_get_detected_chips(0, &c)) != NULL;) {
|
(i = sensors_get_detected_chips(0, &c)) != NULL;) {
|
||||||
std::cout << i->prefix << std::endl;
|
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 *j; (j = sensors_get_features(i, &d)) != NULL;) {
|
||||||
|
|||||||
Reference in New Issue
Block a user