-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensorData.cc
72 lines (55 loc) · 1.82 KB
/
SensorData.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <sensors/sensors.h>
#include "SensorData.hh"
#include <QRegExp>
#include <QDebug>
static QRegExp QREGEXP_NONWORD ("\\W+");
SensorData::SensorData()
{
if (sensors_init(NULL)) return;
versionId = libsensors_version;
}
SensorData::~SensorData()
{
sensors_cleanup();
}
const QVariantMap SensorData::getTemps() const
{
QVariantMap temps = QVariantMap();
sensors_chip_name const * cn;
char * str = new char[128];
for (int c = 0; (cn = sensors_get_detected_chips(0, &c)) ; )
{
if (sensors_snprintf_chip_name(str, 128, cn) <= 0)
{
continue;
}
sensors_feature const * feat;
for (int f = 0 ; (feat = sensors_get_features(cn, &f)) ; )
{
if (feat->type != SENSORS_FEATURE_TEMP) continue;
sensors_subfeature const * subfeat;
for (int sf = 0 ; (subfeat = sensors_get_all_subfeatures(cn, feat, &sf)) ; )
{
if (subfeat->type != SENSORS_SUBFEATURE_TEMP_INPUT) continue;
double val;
QString id = QString("%1.%2.%3").arg(str).arg(feat->name).arg(subfeat->name);
id.replace(QREGEXP_NONWORD, "_");
if (subfeat->flags & SENSORS_MODE_R)
{
int rc = sensors_get_value(cn, subfeat->number, &val);
if (rc >= 0)
{
//qDebug() << id << " = " << val;
temps.insert(id, QVariant(val));
}
else
{
qDebug() << id << " returned " << rc;
}
}
}
}
}
delete str;
return temps;
}