PowerStatus: fixed how the info is retrieved.
* The state was usually 0 once there was more than one battery slot. * We now ignore missing batteries completely, instead of taking eventually bogus data into account. * Fixed how to determine fOnline, and fHasBattery, and when to ignore probes. * Made it more strict when to show the notification, ie. it's now only shown when actually discharging. * This fixes all spurious notifications for me.
This commit is contained in:
@@ -106,7 +106,7 @@ PowerStatusView::_Init()
|
|||||||
fShowTime = false;
|
fShowTime = false;
|
||||||
fShowStatusIcon = true;
|
fShowStatusIcon = true;
|
||||||
|
|
||||||
fPercent = -1;
|
fPercent = 100;
|
||||||
fOnline = true;
|
fOnline = true;
|
||||||
fTimeLeft = 0;
|
fTimeLeft = 0;
|
||||||
}
|
}
|
||||||
@@ -338,13 +338,12 @@ PowerStatusView::Update(bool force)
|
|||||||
bool wasOnline = fOnline;
|
bool wasOnline = fOnline;
|
||||||
bool hadBattery = fHasBattery;
|
bool hadBattery = fHasBattery;
|
||||||
|
|
||||||
_GetBatteryInfo(&fBatteryInfo, fBatteryID);
|
_GetBatteryInfo(fBatteryID, &fBatteryInfo);
|
||||||
|
fHasBattery = fBatteryInfo.full_capacity > 0;
|
||||||
fHasBattery = (fBatteryInfo.state & BATTERY_CRITICAL_STATE) == 0;
|
|
||||||
|
|
||||||
if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
|
if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
|
||||||
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
|
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
|
||||||
fOnline = (fBatteryInfo.state & BATTERY_CHARGING) != 0;
|
fOnline = (fBatteryInfo.state & BATTERY_DISCHARGING) == 0;
|
||||||
fTimeLeft = fBatteryInfo.time_left;
|
fTimeLeft = fBatteryInfo.time_left;
|
||||||
} else {
|
} else {
|
||||||
fPercent = 0;
|
fPercent = 0;
|
||||||
@@ -352,7 +351,7 @@ PowerStatusView::Update(bool force)
|
|||||||
fTimeLeft = -1;
|
fTimeLeft = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fOnline && (fPercent <= 0 || fPercent > 100)) {
|
if (fHasBattery && (fPercent <= 0 || fPercent > 100)) {
|
||||||
// Just ignore this probe -- it obviously returned invalid values
|
// Just ignore this probe -- it obviously returned invalid values
|
||||||
fPercent = previousPercent;
|
fPercent = previousPercent;
|
||||||
fTimeLeft = previousTimeLeft;
|
fTimeLeft = previousTimeLeft;
|
||||||
@@ -417,9 +416,8 @@ PowerStatusView::Update(bool force)
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((hadBattery && !fHasBattery)
|
if (!fOnline && fHasBattery && previousPercent > kLowBatteryPercentage
|
||||||
|| (previousPercent > kLowBatteryPercentage
|
&& fPercent <= kLowBatteryPercentage) {
|
||||||
&& fPercent <= kLowBatteryPercentage)) {
|
|
||||||
_NotifyLowBattery();
|
_NotifyLowBattery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,19 +460,26 @@ PowerStatusView::ToMessage(BMessage* archive) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID)
|
PowerStatusView::_GetBatteryInfo(int batteryID, battery_info* batteryInfo)
|
||||||
{
|
{
|
||||||
if (batteryID >= 0) {
|
if (batteryID >= 0) {
|
||||||
fDriverInterface->GetBatteryInfo(batteryID, batteryInfo);
|
fDriverInterface->GetBatteryInfo(batteryID, batteryInfo);
|
||||||
} else {
|
} else {
|
||||||
|
bool first = true;
|
||||||
|
memset(batteryInfo, 0, sizeof(battery_info));
|
||||||
|
|
||||||
for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
|
for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
|
||||||
battery_info info;
|
battery_info info;
|
||||||
fDriverInterface->GetBatteryInfo(i, &info);
|
fDriverInterface->GetBatteryInfo(i, &info);
|
||||||
|
|
||||||
if (i == 0)
|
if (info.full_capacity <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (first) {
|
||||||
*batteryInfo = info;
|
*batteryInfo = info;
|
||||||
else {
|
first = false;
|
||||||
batteryInfo->state &= info.state;
|
} else {
|
||||||
|
batteryInfo->state |= info.state;
|
||||||
batteryInfo->capacity += info.capacity;
|
batteryInfo->capacity += info.capacity;
|
||||||
batteryInfo->full_capacity += info.full_capacity;
|
batteryInfo->full_capacity += info.full_capacity;
|
||||||
batteryInfo->time_left += info.time_left;
|
batteryInfo->time_left += info.time_left;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2014, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -45,7 +45,7 @@ protected:
|
|||||||
status_t ToMessage(BMessage* message) const;
|
status_t ToMessage(BMessage* message) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _GetBatteryInfo(battery_info* info, int batteryID);
|
void _GetBatteryInfo(int batteryID, battery_info* info);
|
||||||
void _Init();
|
void _Init();
|
||||||
void _SetLabel(char* buffer, size_t bufferLength);
|
void _SetLabel(char* buffer, size_t bufferLength);
|
||||||
void _DrawBattery(BRect rect);
|
void _DrawBattery(BRect rect);
|
||||||
|
|||||||
Reference in New Issue
Block a user