summaryrefslogtreecommitdiffstats
path: root/src/sensor.h
blob: c79237c8ad4be7c2e94b3eaeada4fbd9982992de (plain)
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
/***************************************************************************
                          sensor.h  -  description
                             -------------------
    begin                : mi� abr 24 2002
    copyright            : (C) 2002 by Miguel Novas
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SENSOR_H
#define SENSOR_H

#include <ntqobject.h>
#include <tdeconfig.h>
#include <ntqstring.h>
#include <ntqcstring.h>

/**
  *@author Miguel Novas
  */

//

class SensorsList;

class Sensor : public TQObject  {
  Q_OBJECT

  friend class SensorsList;

public:

  enum SensorClass { lmSensor, hdSensor };

  enum TempScale { dgCelsius, dgFahrenheit, dgKelvin, dgDefault };

  enum SensorType { lmTemp, lmFan, lmVoltage };

  Sensor(SensorsList *parent=0, const char *name=0);
	~Sensor();

  inline void setType(SensorType newType)    { type= newType; };
  void   setValue(double newVal, TempScale scale= dgDefault, bool ajust=true);

  inline SensorType  getType()              { return type; };
  inline const TQString &getDescription()    { return description;   };
  inline double getValue() 							    { return celsiusTo(val); };
  inline double getValuePrevious() 			    { return celsiusTo(valPrevious);   };
  inline double getValueIdeal()             { return celsiusTo(valIdeal);      };
  inline double getValueMax()               { return celsiusTo(valMax);        };
  inline double getValueMin()               { return celsiusTo(valMin);        };
  inline double getCompensation()           { return celsiusToDiff(compensation);  };
  inline double getMultiplicator()          { return multiplicator; };
  inline bool   getAlarm()                  { return (val<valMin || val>valMax); };
  inline bool   getAlarmPrevious()          { return (valPrevious<valMin || valPrevious>valMax); };
  inline bool   getMonitorize()						  { return monitorize;   };
  inline bool   isAlarmValue(double value)  { value= toCelsius(value); return (value<valMin || value>valMax); };

  bool monitorized();
  void setMonitorized  (bool enable);
  void setDescription  (const TQString &str);
  void setValueIdeal   (double value, TempScale scale= dgDefault);
  void setValueMax     (double value, TempScale scale= dgDefault);
  void setValueMin     (double value, TempScale scale= dgDefault);
  void setCompensation (double value, TempScale scale= dgDefault);
  void setMultiplicator(double value);

  SensorClass getClass();
  TempScale getTempScale();
  double toCelsius(double val, TempScale scale= dgDefault);
  double celsiusTo(double val, TempScale scale= dgDefault);
  double toCelsiusDiff(double val, TempScale scale= dgDefault);
  double celsiusToDiff(double val, TempScale scale= dgDefault);

  TQString getPrintMask(bool addSufix);

public slots:

  void readConfig();
  void writeConfig();

signals:

  void valueChanged(double);
  void configChanged();

private:

   SensorType  type;
   TQString    description;
   double     val;
   double     valPrevious;
   double     compensation;
   double     multiplicator;
   double     valMax;
   double     valMin;
   double     valIdeal;
   bool       monitorize;

   inline double adjustValue(double value)      { return value * multiplicator + compensation; };
   const char *getSensorPrintMask(int sensorType, bool addSufix, TempScale temp);

};

#endif