Add Fan stubs, rework Sensors classes

This commit is contained in:
2022-09-11 18:34:56 +02:00
parent 20cb22de01
commit 2208aa8672
6 changed files with 40 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
#include <boost/json.hpp>
#include <boost/json/parse.hpp>
#include <sensors/sensors.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() {
double *value;
@@ -14,20 +14,3 @@ int HwmonTemperatureSensor::getTemperature() {
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);
}

View File

@@ -16,7 +16,14 @@ int main() {
int c = 0;
for (const sensors_chip_name *i;
(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;
for (const sensors_feature *j; (j = sensors_get_features(i, &d)) != NULL;) {