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

superkaramba

sensorsensor.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Hans Karlsson                                   *
00003  *   karlsson.h@home.se                                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 #include "sensorsensor.h"
00011 #include <tqglobal.h>
00012 
00013 SensorSensor::SensorSensor(int interval, char tempUnit) : Sensor( interval )
00014 {
00015 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00016     sensorMapBSD["VCore 1"] = "VC0";
00017     sensorMapBSD["VCore 2"] = "VC1";
00018     sensorMapBSD["+3.3V"] = "V33";
00019     sensorMapBSD["+5V"] = "V50P";
00020     sensorMapBSD["+12V"] = "V12P";
00021     sensorMapBSD["-12V"] = "V12N";
00022     sensorMapBSD["-5V"] = "V50N";
00023     sensorMapBSD["fan1"] = "FAN0";
00024     sensorMapBSD["fan2"] = "FAN1";
00025     sensorMapBSD["fan3"] = "FAN2";
00026     sensorMapBSD["temp1"] = "TEMP0";
00027     sensorMapBSD["temp2"] = "TEMP1";
00028     sensorMapBSD["temp3"] = "TEMP2";
00029 #endif
00030     if(tempUnit == 'F')
00031       extraParams = " -f";
00032     connect(&ksp, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int )),
00033             this,TQT_SLOT(receivedStdout(TDEProcess *, char *, int )));
00034     connect(&ksp, TQT_SIGNAL(processExited(TDEProcess *)),
00035             this,TQT_SLOT(processExited( TDEProcess * )));
00036 
00037     // readValues();
00038 }
00039 
00040 
00041 SensorSensor::~SensorSensor()
00042 {
00043 }
00044 
00045 void SensorSensor::receivedStdout(TDEProcess *, char *buffer, int len )
00046 {
00047     buffer[len] = 0;
00048     sensorResult += TQString( TQCString(buffer) );
00049 }
00050 
00051 void SensorSensor::processExited(TDEProcess *)
00052 {
00053     TQStringList stringList = TQStringList::split('\n',sensorResult);
00054     sensorResult = "";
00055     TQStringList::Iterator it = stringList.begin();
00056 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00057     TQRegExp rx( "^(\\S+)\\s+:\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00058 #else
00059     TQRegExp rx( "^(.+):\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00060 #endif
00061     while( it != stringList.end())
00062     {
00063         rx.search( *it );
00064 
00065         if ( !rx.cap(0).isEmpty())
00066         {
00067             sensorMap[rx.cap(1)] = rx.cap(2);
00068         }
00069         it++;
00070     }
00071 
00072     TQString format;
00073     TQString type;
00074     SensorParams *sp;
00075     Meter *meter;
00076 
00077     TQObjectListIt lit( *objList );
00078     while (lit != 0)
00079     {
00080         sp = (SensorParams*)(*lit);
00081         meter = sp->getMeter();
00082         format = sp->getParam("FORMAT");
00083         type = sp->getParam("TYPE");
00084 
00085         if (type.length() == 0)
00086             type = "temp2";
00087 
00088         if (format.length() == 0 )
00089         {
00090             format = "%v";
00091         }
00092 
00093 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00094         format.replace( TQRegExp("%v", false), sensorMap[sensorMapBSD[type]]);
00095 #else
00096         format.replace( TQRegExp("%v", false), sensorMap[type]);
00097 #endif
00098         meter->setValue(format);
00099         ++lit;
00100     }
00101 }
00102 
00103 void SensorSensor::update()
00104 {
00105     ksp.clearArguments();
00106 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00107     ksp << "mbmon -r -c 1" << extraParams;
00108 #else
00109     ksp << "sensors" << extraParams;
00110 #endif
00111     ksp.start( TDEProcess::NotifyOnExit,KProcIO::Stdout);
00112 }
00113 
00114 
00115 #include "sensorsensor.moc"

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.6.3
This website is maintained by Timothy Pearson.