[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenonbeta/kbatterymonitor/linux-acpi
From:       Chris Howells <howells () kde ! org>
Date:       2004-10-31 23:11:46
Message-ID: 20041031231146.21FF616B9D () office ! kde ! org
[Download RAW message or body]

CVS commit by howells: 

% works


  M +25 -7     linux_acpi.cpp   1.6


--- kdenonbeta/kbatterymonitor/linux-acpi/linux_acpi.cpp  #1.5:1.6
@@ -27,4 +27,6 @@
 #include <qregexp.h>
 
+#include <cmath> // for round()
+
 #include "../kbatterymonitor/monitor.h"
 
@@ -225,20 +227,36 @@ bool LinuxACPI::parseCharging(QStringLis
 int LinuxACPI::batteryTime()
 {
-        //kdDebug() << "VALUES*****" << mRemainingCapacity << " * " << mPresentRate \
                << " * " << endl;
-        if (mCharging)
+        if (!mCharging && (mPresentRate > 0))
         {
-                kdDebug() << "Using the charging equation: remaining " << \
                mRemainingCapacity << " present rate " << mPresentRate << endl;
-                return (int)(mRemainingCapacity / ((float)mPresentRate * 60));
+                //kdDebug() << "Using the charging equation: remaining " << \
mRemainingCapacity << " present rate " << mPresentRate << endl; +                long \
foo = mPresentRate * 60; +                float blah = (float)mRemainingCapacity / \
foo; +                kdDebug() << "blah " << foo << " " << blah << endl;
+                return ((float)mRemainingCapacity / (mPresentRate * 60));
+        }
+        else if (mCharging && (mPresentRate > 0))
+        {
+                //kdDebug() << "Using the non charging equation: remaining " << \
mRemainingCapacity << " present rate " << mPresentRate << endl; +                \
return (float)(mPresentRate - mRemainingCapacity) / (mPresentRate * 60);  }
         else
         {
-                kdDebug() << "Using the non charging equation: remaining " << \
                mRemainingCapacity << " present rate " << mPresentRate << endl;
-                return (int)((mPresentRate - mRemainingCapacity) / \
((float)(mPresentRate) * 60)); +                return -1; // we are just on AC so \
nothing to estimate  }
+                
 }
 
 int LinuxACPI::batteryPercent()
 {
-        return (mPresentRate / ((float)mLastFullCapacity) * 100);
+        if ((mPresentRate > 0) && !mCharging) // if the rate is > 0 we should be \
charging or discharging +        {
+                //kdDebug() << "Remaining capacity" << mRemainingCapacity << endl;
+                //kdDebug() << "last full capacity" << mLastFullCapacity << endl;
+                return ((float)mRemainingCapacity / mLastFullCapacity * 100);
+        }
+        else
+        {
+                return 100;
+        }
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic