• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

superkaramba

lmsensor.cpp

Go to the documentation of this file.
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 
00011 #include "lmsensor.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, SIGNAL(receivedStdout(K3Process *, char *, int)),
00033             this, SLOT(receivedStdout(K3Process *, char *, int)));
00034     connect(&ksp, SIGNAL(processExited(K3Process *)),
00035             this, SLOT(processExited(K3Process *)));
00036 
00037     // readValues();
00038 }
00039 
00040 
00041 SensorSensor::~SensorSensor()
00042 {}
00043 
00044 void SensorSensor::receivedStdout(K3Process *, char *buffer, int len)
00045 {
00046     buffer[len] = 0;
00047     sensorResult += QString(buffer);
00048 }
00049 
00050 void SensorSensor::processExited(K3Process *)
00051 {
00052     QStringList stringList = sensorResult.split('\n');
00053     sensorResult = "";
00054     QStringList::Iterator it = stringList.begin();
00055 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00056     QRegExp rx("^(\\S+)\\s+:\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00057 #else
00058     QRegExp rx("^(.+):\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00059 #endif
00060     while (it != stringList.end()) {
00061         rx.indexIn(*it);
00062 
00063         if (!rx.cap(0).isEmpty()) {
00064             sensorMap[rx.cap(1)] = rx.cap(2);
00065         }
00066         it++;
00067     }
00068 
00069     QString format;
00070     QString type;
00071     SensorParams *sp;
00072     Meter *meter;
00073 
00074     QObject *lobject;
00075     foreach(lobject, *objList) {
00076         sp = (SensorParams*)(lobject);
00077         meter = sp->getMeter();
00078         format = sp->getParam("FORMAT");
00079         type = sp->getParam("TYPE");
00080 
00081         if (type.length() == 0)
00082             type = "temp2";
00083 
00084         if (format.length() == 0) {
00085             format = "%v";
00086         }
00087 
00088 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00089         format.replace(QRegExp("%v", Qt::CaseInsensitive),
00090                        sensorMap[sensorMapBSD[type]]);
00091 #else
00092         format.replace(QRegExp("%v", Qt::CaseInsensitive),
00093                        sensorMap[type]);
00094 #endif
00095         meter->setValue(format);
00096     }
00097 }
00098 
00099 void SensorSensor::update()
00100 {
00101     ksp.clearArguments();
00102 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00103     ksp << "mbmon -r -c 1" << extraParams;
00104 #else
00105     ksp << "sensors" << extraParams;
00106 #endif
00107     ksp.start(K3Process::NotifyOnExit, K3ProcIO::Stdout);
00108 }
00109 
00110 
00111 #include "lmsensor.moc"

superkaramba

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal