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
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/***************************************************************************
sensor.cpp - description
-------------------
begin : mié abr 24 2002
copyright : (C) 2002 by Miguel Novas
email : michaell@teleline.es
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <kglobal.h>
#include "sensor.h"
#include "sensorslist.h"
Sensor::Sensor(SensorsList *parent,const char *name): QObject(parent,name)
{
description = "";
compensation = 0;
multiplicator= 1;
monitorize = false;
}
Sensor::~Sensor(){
}
Sensor::SensorClass Sensor::getClass()
{
return ((SensorsList *)parent())->getClass();
}
QString Sensor::getPrintMask(bool addSufix)
{
return getSensorPrintMask(type, addSufix, ((SensorsList*)parent())->getTempScale() );
}
const char *Sensor::getSensorPrintMask(int sensorType, bool addSufix, TempScale temp)
{
if(addSufix) {
switch(sensorType) {
case Sensor::lmTemp:
switch(temp) {
case dgCelsius : return "%.0lf C";
case dgFahrenheit: return "%.0lf F";
case dgKelvin : return "%.0lf K";
}
break;
case Sensor::lmFan: return "%.0lf rpm";
case Sensor::lmVoltage: return "%.2lfV";
}
}
return sensorType==Sensor::lmVoltage ? ".2lf" : ".0lf";
}
bool Sensor::monitorized()
{
return monitorize;
}
void Sensor::setMonitorized(bool enable)
{
if( monitorize!=enable ) monitorize= enable;
}
void Sensor::setValueIdeal(double value, TempScale scale)
{
valIdeal= toCelsius(value, scale);
}
void Sensor::setValueMax(double value, TempScale scale)
{
valMax= toCelsius(value,scale);
}
void Sensor::setValueMin(double value, TempScale scale)
{
valMin= toCelsius(value,scale);
}
void Sensor::setCompensation(double value, TempScale scale)
{
compensation= toCelsiusDiff(value,scale);
}
void Sensor::setMultiplicator(double value)
{
multiplicator= value;
}
void Sensor::setDescription(const QString &str)
{
description= str;
}
void Sensor::setValue(double newVal, TempScale scale, bool ajust)
{
newVal= toCelsius(newVal,scale);
if (ajust) newVal= adjustValue(newVal);
if(val!=newVal) {
valPrevious= val;
val = newVal;
emit valueChanged( celsiusTo(val) );
}
}
void Sensor::writeConfig()
{
KConfig *ksConfig= KGlobal::config();
if(ksConfig) {
ksConfig->setGroup( QString(name()) );
ksConfig->writeEntry("description" ,description);
ksConfig->writeEntry("valueIdeal" ,valIdeal);
ksConfig->writeEntry("valueMax" ,valMax);
ksConfig->writeEntry("valueMin" ,valMin);
ksConfig->writeEntry("compensation" ,compensation);
ksConfig->writeEntry("multiplicator",multiplicator);
ksConfig->writeEntry("monitorize" ,monitorize);
emit configChanged();
}
}
void Sensor::readConfig()
{
KConfig *ksConfig= KGlobal::config();
if(ksConfig) {
ksConfig->setGroup( QString(name()) );
valMax = ksConfig->readDoubleNumEntry("valueMax" ,valMax);
valMin = ksConfig->readDoubleNumEntry("valueMin" ,valMin);
compensation = ksConfig->readDoubleNumEntry("compensation" ,compensation);
multiplicator= ksConfig->readDoubleNumEntry("multiplicator",multiplicator);
description = ksConfig->readEntry ("description" ,description);
valIdeal = ksConfig->readDoubleNumEntry("valueIdeal" ,valIdeal);
setMonitorized( ksConfig->readBoolEntry ("monitorize" ,monitorize) );
}
}
double Sensor::toCelsius(double val, TempScale scale)
{
if(type!=lmTemp) return val;
switch( scale == dgDefault ? getTempScale(): scale ) {
case dgCelsius : return val;
case dgFahrenheit: return (5.0/9.0)*(val-32.0);
}
return val - 273.16; // Kelvin to Celsius
}
double Sensor::celsiusTo(double val, TempScale scale)
{
if(type!=lmTemp) return val;
switch( scale==dgDefault ? getTempScale() : scale ) {
case dgCelsius : return val;
case dgFahrenheit: return (9.0/5.0)*val+32.0;
}
return val + 273.16; // Celsius to Kelvin
}
double Sensor::toCelsiusDiff(double val, TempScale scale)
{
if(scale==dgDefault) scale= getTempScale();
if(type!=lmTemp || scale!=dgFahrenheit ) return val;
return val*(5.0/9.0);
}
double Sensor::celsiusToDiff(double val, TempScale scale)
{
if(scale==dgDefault) scale= getTempScale();
if(type!=lmTemp || scale!=dgFahrenheit ) return val;
return val*(9.0/5.0);
}
Sensor::TempScale Sensor::getTempScale()
{
return ((SensorsList *)parent())->getTempScale();
}
|