Ticket #1027: updated_temp_sensor.patch

File updated_temp_sensor.patch, 5.8 KB (added by anonymous, 18 years ago)
  • configure

     
    17921792  fi
    17931793fi
    17941794
     1795#########################################
     1796# lmsensor probe
     1797
     1798cat > $TMPC << EOF
     1799#include <sensors/sensors.h>
     1800int main( void ) { return; };
     1801EOF
     1802
     1803lmsensors=no
     1804if $cc $CFLAGS $LDFLAGS -o $TMPE $TMPC -lsensors > /dev/null 2>&1; then
     1805  lmsensors=yes
     1806fi
     1807
    17951808##########################################
    17961809# SDL probe
    17971810
     
    24422455  echo "FREETYPE_CFLAGS=`freetype-config --cflags`" >> $MYTH_CONFIG_MAK
    24432456  echo "FREETYPE_LIBS=`freetype-config --libs`" >> $MYTH_CONFIG_MAK
    24442457fi
     2458if test "$lmsensors" = "yes" ; then
     2459  CCONFIG="$CCONFIG using_lmsensors"
     2460  echo "#define CONFIG_LMSENSORS 1" >> $TMPH
     2461fi
    24452462if test "$sunmlib" = "yes" ; then
    24462463  echo "HAVE_MLIB=yes" >> $MYTH_CONFIG_MAK
    24472464  echo "#define HAVE_MLIB 1" >> $TMPH
  • programs/mythbackend/mythbackend.pro

     
    2424using_dvb:DEFINES += USING_DVB
    2525
    2626using_valgrind:DEFINES += USING_VALGRIND
     27
     28using_lmsensors:LIBS += -lsensors
  • programs/mythbackend/mainserver.cpp

     
    4545#include "jobqueue.h"
    4646#include "autoexpire.h"
    4747#include "previewgenerator.h"
     48#ifdef CONFIG_LMSENSORS
     49    #define LMSENSOR_DEFAULT_CONFIG_FILE "/etc/sensors.conf"
     50    #include <sensors/sensors.h>
     51    #include <sensors/chips.h>
     52#endif
    4853
    4954/** Milliseconds to wait for an existing thread from
    5055 *  process request thread pool.
     
    39033908    QDomElement mInfo   = pDoc->createElement("MachineInfo");
    39043909    QDomElement storage = pDoc->createElement("Storage"    );
    39053910    QDomElement load    = pDoc->createElement("Load"       );
     3911    QDomElement thermal = pDoc->createElement("Thermal"    );
    39063912    QDomElement guide   = pDoc->createElement("Guide"      );
    39073913
    39083914    root.appendChild (mInfo  );
     
    39843990        load.setAttribute("avg3", rgdAverages[2]);
    39853991    }
    39863992
     3993    //temperature -----------------
     3994    // Try ACPI first, then lmsensor 2nd
     3995    QDir dir("/proc/acpi/thermal_zone");
     3996    bool found_acpi = false;
     3997    if (dir.exists())
     3998    {
     3999        QString acpiTempDir;
     4000        QStringList lst = dir.entryList();
     4001        QRegExp rxp = QRegExp ("TH?M?", TRUE, FALSE);
     4002        QString line, temp;
     4003        for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
     4004        {
     4005            if ( (*it).contains(rxp))
     4006            {
     4007                acpiTempDir = dir.absFilePath(*it);
     4008            }
     4009        }
     4010       
     4011        QFile acpiTempFile(acpiTempDir.append("/temperature"));
     4012        if (acpiTempFile.open(IO_ReadOnly))
     4013        {
     4014            QTextStream stream (&acpiTempFile);
     4015            line = stream.readLine();
     4016            rxp = QRegExp ("(\\d+)", TRUE, FALSE);
     4017            if (rxp.search(line) != -1 )
     4018            {
     4019                temp = rxp.cap(1);
     4020                temp += " &#8451;"; // print degress Celsius
     4021                mInfo.appendChild(thermal);
     4022                thermal.setAttribute("temperature", temp);
     4023                found_acpi = true;
     4024            }
     4025        }
     4026        acpiTempFile.close();
     4027    }
     4028#ifdef CONFIG_LMSENSORS
     4029    if (!found_acpi)
     4030    {
     4031        int chip_nr, a, b;
     4032        char *label;
     4033        double value;
     4034        const sensors_chip_name *chip;
     4035        const sensors_feature_data *data;
     4036        const char* lmsensorConfigName = LMSENSOR_DEFAULT_CONFIG_FILE;
     4037        a = b = 0;
     4038        FILE *lmsensorConfigFile = fopen(lmsensorConfigName, "r");
     4039        sensors_init(lmsensorConfigFile);
     4040        fclose(lmsensorConfigFile);
     4041        for (chip_nr = 0 ; (chip = sensors_get_detected_chips(&chip_nr)) ; )
     4042        {
     4043            while ((data = sensors_get_all_features(*chip, &a, &b)))
     4044            {
     4045                if ((!sensors_get_label(*chip, data->number, &label)) &&
     4046                    (!sensors_get_feature(*chip, data->number, &value)))
     4047                {
     4048                    // Find label matching "CPU Temp" or "Temp/CPU" or something close to that
     4049                    QRegExp rxp = QRegExp ("(CPU.+Temp)|(Temp.+CPU)", FALSE, FALSE);
     4050                    if (rxp.search(QString(label)) != -1  && value > 0)
     4051                    {
     4052                        VERBOSE(VB_IMPORTANT,
     4053                                QString("Temp debug. Remove before committing: lmsensor temp label %1 value %2")
     4054                                .arg(label).arg(value));
     4055                        QString temp = QString("%1").arg(value);
     4056                        temp += " &#8451;";
     4057                        mInfo.appendChild(thermal);
     4058                        thermal.setAttribute("temperature", temp);
     4059                    }
     4060                }
     4061            }
     4062        }
     4063    }
     4064#endif
    39874065    // Guide Data ---------------------
    39884066
    39894067    QDateTime GuideDataThrough;
  • programs/mythbackend/httpstatus.cpp

     
    733733        }
    734734    }
    735735
     736   // ACPI temperature ------------------
     737
     738    node = info.namedItem( "Thermal" );
     739
     740    if (!node.isNull())
     741    {
     742        QDomElement e = node.toElement();
     743
     744        if (!e.isNull())
     745        {
     746            std::string temperature = e.attribute( "temperature" , "0" );
     747
     748            os << "      Current CPU temperature: "
     749               << temperature
     750               << ".<br />\r\n";
     751        }
     752    }
     753       
    736754    // Guide Info ---------------------
    737755
    738756    node = info.namedItem( "Guide" );