PowerStatus: fix a possible division error.
* also fix some types misuses.
This commit is contained in:
@@ -43,8 +43,8 @@ RateBuffer::AddRate(int32 rate)
|
||||
int32
|
||||
RateBuffer::GetMeanRate()
|
||||
{
|
||||
int mean = 0;
|
||||
for (int i = 0; i < fCurrentSize; i++) {
|
||||
int32 mean = 0;
|
||||
for (int8 i = 0; i < fCurrentSize; i++) {
|
||||
mean += fRateBuffer[i];
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ Battery::GetBatteryInfoCached(battery_info* info)
|
||||
info->capacity = fCachedAcpiInfo.capacity;
|
||||
info->full_capacity = fExtendedBatteryInfo.last_full_charge;
|
||||
fRateBuffer.AddRate(fCachedAcpiInfo.current_rate);
|
||||
if (fCachedAcpiInfo.current_rate > 0)
|
||||
if (fCachedAcpiInfo.current_rate > 0 && fRateBuffer.GetMeanRate() != 0)
|
||||
info->time_left = 3600 * fCachedAcpiInfo.capacity
|
||||
/ fRateBuffer.GetMeanRate();
|
||||
else
|
||||
@@ -254,5 +254,3 @@ ACPIDriverInterface::_FindDrivers(const char* dirpath)
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@ void
|
||||
PowerStatusView::Update(bool force)
|
||||
{
|
||||
int32 previousPercent = fPercent;
|
||||
bool previousTimeLeft = fTimeLeft;
|
||||
time_t previousTimeLeft = fTimeLeft;
|
||||
bool wasOnline = fOnline;
|
||||
|
||||
_GetBatteryInfo(&fBatteryInfo, fBatteryID);
|
||||
@@ -350,7 +350,7 @@ PowerStatusView::Update(bool force)
|
||||
} else {
|
||||
fPercent = 0;
|
||||
fOnline = false;
|
||||
fTimeLeft = false;
|
||||
fTimeLeft = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -375,7 +375,7 @@ PowerStatusView::Update(bool force)
|
||||
if (fHasBattery) {
|
||||
size_t length = snprintf(text, sizeof(text), "%s%" B_PRId32
|
||||
"%%%s", open, fPercent, close);
|
||||
if (fTimeLeft) {
|
||||
if (fTimeLeft >= 0) {
|
||||
length += snprintf(text + length, sizeof(text) - length,
|
||||
"\n%" B_PRId32 ":%02" B_PRId32, fTimeLeft / 3600,
|
||||
(fTimeLeft / 60) % 60);
|
||||
@@ -751,4 +751,3 @@ instantiate_deskbar_item(void)
|
||||
{
|
||||
return new PowerStatusReplicant(BRect(0, 0, 15, 15), B_FOLLOW_NONE, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user