PowerStatus: Implemented sound cues for low battery and charging
* Added two beep events ("Low battery" and "Battery charged") to Sounds * "Battery charged" is activated when the battery is fully charged to 100 percent * "Low battery" is activated when the battery is less than 15 percent or has less than 30 minutes of usage time left, whichever comes first Change-Id: If95f812be7a0aa15d668a42fdcfaccd2995d2b4f Reviewed-on: https://review.haiku-os.org/c/haiku/+/6481 Reviewed-by: Niels Sascha Reedijk <niels.reedijk@gmail.com>
This commit is contained in:
parent
1676a41ec5
commit
0f293bd7b6
@ -21,6 +21,7 @@
|
|||||||
#include <AboutWindow.h>
|
#include <AboutWindow.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <Beep.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Deskbar.h>
|
#include <Deskbar.h>
|
||||||
@ -61,6 +62,9 @@ const uint32 kMsgToggleExtInfo = 'texi';
|
|||||||
|
|
||||||
const double kLowBatteryPercentage = 0.15;
|
const double kLowBatteryPercentage = 0.15;
|
||||||
const double kNoteBatteryPercentage = 0.3;
|
const double kNoteBatteryPercentage = 0.3;
|
||||||
|
const double kFullBatteryPercentage = 1.0;
|
||||||
|
|
||||||
|
const time_t kLowBatteryTimeLeft = 30 * 60;
|
||||||
|
|
||||||
|
|
||||||
PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
|
PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
|
||||||
@ -116,6 +120,11 @@ PowerStatusView::_Init()
|
|||||||
fPercent = 1.0;
|
fPercent = 1.0;
|
||||||
fOnline = true;
|
fOnline = true;
|
||||||
fTimeLeft = 0;
|
fTimeLeft = 0;
|
||||||
|
|
||||||
|
fHasNotifiedLowBattery = false;
|
||||||
|
|
||||||
|
add_system_beep_event("Low battery");
|
||||||
|
add_system_beep_event("Battery charged");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -298,6 +307,7 @@ PowerStatusView::Draw(BRect updateRect)
|
|||||||
DrawTo(this, Bounds());
|
DrawTo(this, Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PowerStatusView::DrawTo(BView* view, BRect rect)
|
PowerStatusView::DrawTo(BView* view, BRect rect)
|
||||||
{
|
{
|
||||||
@ -491,9 +501,23 @@ PowerStatusView::Update(bool force, bool notify)
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fOnline && fHasBattery && previousPercent > kLowBatteryPercentage
|
if (fPercent > kLowBatteryPercentage && fTimeLeft > kLowBatteryTimeLeft)
|
||||||
&& fPercent <= kLowBatteryPercentage && notify) {
|
fHasNotifiedLowBattery = false;
|
||||||
|
|
||||||
|
bool justTurnedLowBattery = (previousPercent > kLowBatteryPercentage
|
||||||
|
&& fPercent <= kLowBatteryPercentage)
|
||||||
|
|| (fTimeLeft <= kLowBatteryTimeLeft
|
||||||
|
&& previousTimeLeft > kLowBatteryTimeLeft);
|
||||||
|
|
||||||
|
if (!fOnline && notify && fHasBattery
|
||||||
|
&& !fHasNotifiedLowBattery && justTurnedLowBattery) {
|
||||||
_NotifyLowBattery();
|
_NotifyLowBattery();
|
||||||
|
fHasNotifiedLowBattery = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fOnline && fPercent >= kFullBatteryPercentage
|
||||||
|
&& previousPercent < kFullBatteryPercentage) {
|
||||||
|
system_beep("Battery charged");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,6 +609,8 @@ PowerStatusView::_NotifyLowBattery()
|
|||||||
BNotification notification(
|
BNotification notification(
|
||||||
fHasBattery ? B_INFORMATION_NOTIFICATION : B_ERROR_NOTIFICATION);
|
fHasBattery ? B_INFORMATION_NOTIFICATION : B_ERROR_NOTIFICATION);
|
||||||
|
|
||||||
|
system_beep("Low battery");
|
||||||
|
|
||||||
if (fHasBattery) {
|
if (fHasBattery) {
|
||||||
notification.SetTitle(B_TRANSLATE("Battery low"));
|
notification.SetTitle(B_TRANSLATE("Battery low"));
|
||||||
notification.SetContent(B_TRANSLATE(
|
notification.SetContent(B_TRANSLATE(
|
||||||
|
@ -68,6 +68,8 @@ protected:
|
|||||||
time_t fTimeLeft;
|
time_t fTimeLeft;
|
||||||
bool fOnline;
|
bool fOnline;
|
||||||
bool fHasBattery;
|
bool fHasBattery;
|
||||||
|
|
||||||
|
bool fHasNotifiedLowBattery;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user