From kde-commits Sun Oct 31 23:11:46 2004 From: Chris Howells Date: Sun, 31 Oct 2004 23:11:46 +0000 To: kde-commits Subject: kdenonbeta/kbatterymonitor/linux-acpi Message-Id: <20041031231146.21FF616B9D () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=109926431620506 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 +#include // 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; + } }