• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
sensorsensor.cpp
1/***************************************************************************
2 * Copyright (C) 2003 by Hans Karlsson *
3 * karlsson.h@home.se *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10#include "sensorsensor.h"
11#include <tqglobal.h>
12
13SensorSensor::SensorSensor(int interval, char tempUnit) : Sensor( interval )
14{
15#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
16 sensorMapBSD["VCore 1"] = "VC0";
17 sensorMapBSD["VCore 2"] = "VC1";
18 sensorMapBSD["+3.3V"] = "V33";
19 sensorMapBSD["+5V"] = "V50P";
20 sensorMapBSD["+12V"] = "V12P";
21 sensorMapBSD["-12V"] = "V12N";
22 sensorMapBSD["-5V"] = "V50N";
23 sensorMapBSD["fan1"] = "FAN0";
24 sensorMapBSD["fan2"] = "FAN1";
25 sensorMapBSD["fan3"] = "FAN2";
26 sensorMapBSD["temp1"] = "TEMP0";
27 sensorMapBSD["temp2"] = "TEMP1";
28 sensorMapBSD["temp3"] = "TEMP2";
29#endif
30 if(tempUnit == 'F')
31 extraParams = " -f";
32 connect(&ksp, TQ_SIGNAL(receivedStdout(TDEProcess *, char *, int )),
33 this,TQ_SLOT(receivedStdout(TDEProcess *, char *, int )));
34 connect(&ksp, TQ_SIGNAL(processExited(TDEProcess *)),
35 this,TQ_SLOT(processExited( TDEProcess * )));
36
37 // readValues();
38}
39
40
41SensorSensor::~SensorSensor()
42{
43}
44
45void SensorSensor::receivedStdout(TDEProcess *, char *buffer, int len )
46{
47 buffer[len] = 0;
48 sensorResult += TQString( TQCString(buffer) );
49}
50
51void SensorSensor::processExited(TDEProcess *)
52{
53 TQStringList stringList = TQStringList::split('\n',sensorResult);
54 sensorResult = "";
55 TQStringList::Iterator it = stringList.begin();
56#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
57 TQRegExp rx( "^(\\S+)\\s+:\\s+[\\+\\-]?(\\d+\\.?\\d*)");
58#else
59 TQRegExp rx( "^(.+):\\s+[\\+\\-]?(\\d+\\.?\\d*)");
60#endif
61 while( it != stringList.end())
62 {
63 rx.search( *it );
64
65 if ( !rx.cap(0).isEmpty())
66 {
67 sensorMap[rx.cap(1)] = rx.cap(2);
68 }
69 it++;
70 }
71
72 TQString format;
73 TQString type;
74 SensorParams *sp;
75 Meter *meter;
76
77 TQObjectListIt lit( *objList );
78 while (lit != 0)
79 {
80 sp = (SensorParams*)(*lit);
81 meter = sp->getMeter();
82 format = sp->getParam("FORMAT");
83 type = sp->getParam("TYPE");
84
85 if (type.length() == 0)
86 type = "temp2";
87
88 if (format.length() == 0 )
89 {
90 format = "%v";
91 }
92
93#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
94 format.replace( TQRegExp("%v", false), sensorMap[sensorMapBSD[type]]);
95#else
96 format.replace( TQRegExp("%v", false), sensorMap[type]);
97#endif
98 meter->setValue(format);
99 ++lit;
100 }
101}
102
103void SensorSensor::update()
104{
105 ksp.clearArguments();
106#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
107 ksp << "mbmon -r -c 1" << extraParams;
108#else
109 ksp << "sensors" << extraParams;
110#endif
111 ksp.start( TDEProcess::NotifyOnExit,TDEProcIO::Stdout);
112}
113
114
115#include "sensorsensor.moc"
SensorParams
Hans Karlsson.
Definition: sensorparams.h:32

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.