Fix temperature for new power kernels
authorDaniel Klaffenbach <danielklaffenbach@gmail.com>
Thu, 5 May 2011 19:20:14 +0000 (21:20 +0200)
committerDaniel Klaffenbach <danielklaffenbach@gmail.com>
Thu, 5 May 2011 19:20:14 +0000 (21:20 +0200)
New power kernels (> v46) report the temperature in the format 386 (for
38.6 °C). We need to divide the value from the kernel by 10 in order to
display the correct temperature again.

Note: this breaks temperature reporting for older power kernels.

Thanks to misiak for pointing this out and providing a fix.

src/mainwindow.cpp

index 1ae60ae..60df0ce 100644 (file)
@@ -283,11 +283,15 @@ QString MainWindow::getCPUTemp()
 {
 #if defined(Q_WS_MAEMO_5)
     QFile file( "/sys/class/power_supply/bq27200-0/temp" );
+    //! The string containing the value of the temperature
+    QString tstring;
 
     //check if we can read a more accurate temperature (only for power kernel)
-    if (file.exists())
-        return QString( readSysFile( "class/power_supply/bq27200-0/temp" ) + " " + QString::fromUtf8("\302\260") + "C" );
-    else {
+    if (file.exists()) {
+        //this only works on kernel-power > 46
+        tstring = readSysFile( "class/power_supply/bq27200-0/temp" );
+        return tstring.left(tstring.length()-1) + " " + QString::fromUtf8("\302\260") + "C";
+    } else {
         /*
           We actually only need to read the raw temperature, but it appears that by also reading temp1_input
           the raw temperature (temp1_input_raw) is being updated more frequently.
@@ -295,7 +299,7 @@ QString MainWindow::getCPUTemp()
         readSysFile( "devices/platform/omap34xx_temp/temp1_input" );
 
         //read the current system temperature
-        QString tstring = readSysFile( "devices/platform/omap34xx_temp/temp1_input_raw" );
+        tstring = readSysFile( "devices/platform/omap34xx_temp/temp1_input_raw" );
         if (tstring == "0")
             return tr( "Unknown" );