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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/* ksim - a system monitor for kde
*
* Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SENSORBASE_H
#define SENSORBASE_H
#include <tqobject.h>
#include <tqvaluelist.h>
#include <tqcstring.h>
class TQTimer;
class KLibrary;
class SensorInfo
{
public:
SensorInfo() {}
SensorInfo(int id,
const TQString &sensorValue,
const TQString &sensorName,
const TQString &sensorType,
const TQString &chipsetName,
const TQString &sensorUnit)
: m_id(id), m_sensor(sensorValue),
m_sensorName(sensorName),
m_sensorType(sensorType),
m_chipsetName(chipsetName),
m_sensorUnit(sensorUnit) {}
/**
* @return the sensor Id
*/
int sensorId() const { return m_id; }
/**
* @return the current value, eg: 5000
*/
const TQString &sensorValue() const { return m_sensor; }
/**
* @return the sensor name, eg: temp1, fan2
*/
const TQString &sensorName() const { return m_sensorName; }
/**
* @return the sensor type name, eg: w83782d
*/
const TQString &sensorType() const { return m_sensorType; }
/**
* @return the chipset name, eg: w83782d-i2c-0-2d
*/
const TQString &chipsetName() const { return m_chipsetName; }
/**
* @return the unit name, eg: RPM, °C or °F if display fahrenheit is enabled
*/
const TQString &sensorUnit() const { return m_sensorUnit; }
private:
int m_id;
TQString m_sensor;
TQString m_sensorName;
TQString m_sensorType;
TQString m_chipsetName;
TQString m_sensorUnit;
};
class SensorList : public TQValueList<SensorInfo>
{
public:
SensorList() {}
SensorList(const SensorList &sensorList)
: TQValueList<SensorInfo>(sensorList) {}
SensorList(const TQValueList<SensorInfo> &sensorList)
: TQValueList<SensorInfo>(sensorList) {}
SensorList(const SensorInfo &sensor) { append(sensor); }
};
class SensorBase : public TQObject
{
TQ_OBJECT
public:
static SensorBase *self();
const SensorList &sensorsList() const { return m_sensorList; }
bool fahrenheit() { return m_fahrenheit; }
signals:
void updateSensors(const SensorList&);
public slots:
void setUpdateSpeed(uint);
void setDisplayFahrenheit(bool fah) { m_fahrenheit = fah; }
private slots:
void update();
protected:
SensorBase();
~SensorBase();
private:
SensorBase(const SensorBase &);
SensorBase &operator=(const SensorBase &);
static void cleanup();
struct ChipName
{
char *prefix;
int bus;
int addr;
char *busname;
};
struct FeatureData
{
int number;
const char *name;
int mapping;
int unused;
int mode;
};
enum { ProcError=4, NoMapping=-1, BusISA=-1 };
typedef void (*Cleanup)();
typedef int (*Init)(FILE *);
typedef const char *(*Error)(int);
typedef const ChipName *(GetDetectedChips)(int *);
typedef const FeatureData *(GetAllFeatures)(ChipName, int *, int *);
typedef int (*Label)(ChipName, int, char **);
typedef int (*Feature)(ChipName, int, double *);
bool init();
float toFahrenheit(float value);
TQString sensorType(const TQString &name);
TQString chipsetString(const ChipName *c);
float formatValue(const TQString &label, float value);
TQString formatString(const TQString &label, float value);
SensorList m_sensorList;
TQTimer *m_updateTimer;
KLibrary *m_library;
TQCString m_libLocation;
bool m_loaded;
bool m_fahrenheit;
bool m_hasNVControl;
Init m_init;
Error m_error;
GetDetectedChips *m_detectedChips;
GetAllFeatures *m_allFeatures;
Label m_label;
Feature m_feature;
Cleanup m_cleanup;
static SensorBase *m_self;
};
inline float SensorBase::toFahrenheit(float value)
{
return fahrenheit() ? (value * (9.0F / 5.0F) + 32.0F) : value;
}
#endif // SENSORBASE_H
|