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