Battery status / warning

I would like to get a warning if the battery drained to, let’s say 15%. As long hibernation or sleep are missing, this would remember me to put in the charger in time.

There already is a battery warning. Two, in fact: one telling you battery is running low, and one when the battery is about to quit. Both a regular notifications, with the disadvantage of them disappearing after the set delay automatically. So they are easy to miss.
See also ticket #16324.

1 Like

If an alert sound is defined, would it work for notifications?

Thanks for the info. Seems I need a bit more help.
I have not seen any notification in respect to the battery up to now. I got notification for the connection status wireless and wired.
When I open the preferences for notification those are actived. When I switch to the application tab the list is emty. I see no option how to app PowerStatus or to set any parameters.
Any idea?

Currently it apparently isn’t implemented. I set a sound for the Info notification in the Sounds prefs, and hear nothing when taping in Terminal:

notify --type info "Hello ralf!"

^^ Do you see a notification when doing that, @ralf?
I suppose there’s the possibility that your battery charge isn’t recognized correctly or something…

Yepp, I get a notification by typing
notify --type info "Hello ralf!"

No idea… if it were only the battery notification missing, I’d guess it were some misreporting of the driver. But since you don’t get network up/down notifications either… How about download finished notifications from Web+?

Anyway, maybe the /var/log/syslog has some info. If it does, consider attaching it to a new ticket at the bugtracker.

Anyway, the battery is recognized and the charge ist indicated in percentage an estimated time. I also got the information about the battery displayed.
The syslog give me by “more /var/log/syslog | grep batt”:
KERN: publish device: node 0xffffffff8214dc88, path power/acpi_battery/0, module drivers/power/acpi_battery/device_v1.
During writing this lines I have my eyes on the open PowerStatus applet. I see the color of the bar changing from green to orange, but no notification. Down to 15%, bar getting red, but no notivation.

Sorry, not sure what’s going on. I tried myself and do get the notification when going below 15%.

This is the code in question, PowerStatusView::Update() that gets called every 2 seconds:

	if (!fOnline && fHasBattery && previousPercent > kLowBatteryPercentage
			&& fPercent <= kLowBatteryPercentage) {
		_NotifyLowBattery();
	}

That looks OK. kLowBatteryPercentage = 15%.

Aside from your issue, that you don’t see any notifications, I wonder when/how the “critical” notification is shown. Called from the _NotifyLowBattery(); there’s this code:

	if (fHasBattery) {
		notification.SetTitle(B_TRANSLATE("Battery low"));
		notification.SetContent(B_TRANSLATE(
			"The battery level is getting low, please plug in the device."));
	} else {
		notification.SetTitle(B_TRANSLATE("Battery critical"));
		notification.SetContent(B_TRANSLATE(
			"The battery level is critical, please plug in the device "
			"immediately."));
	}

I see the first at 15%, but never see the second, critical one. What’s exactly fHasBattery?
Maybe, when the battery is just about to be drained, ACPI reports “no battery” and fHasBattery becomes false?

Unfortunately, my battery is old and so far gone, that I hear the BIOS beeping when PowerStatus shows 8%. Then I have to scramble to plug in the power supply or the computer shuts straight off… :slight_smile:
Then, after a minute of charging, PowerStatus starts counting up from 1%.

Let me understand the code. && means all expressions have to be true that the result gets true.
!fOnline – true, as we have not plugged in the power supply
fHasBattery – true
previousPercent > kLowBatteryPercentage – true, % are dropping, but why this check?
fPercent <= kLowBatteryPercentage – true, i can read 15% in the PowerStatus
Looks all well to me. It is possible that one check fails due to faulty ACPI table? Anyway the PowerStatus is working well and give good values.
Btw, I get notifications by plugging in and out the Ethernet cable. Do you have some more events I can trigger to force a notification?

Because we want to trigger the notification only once, when the previousPercent was higher than 15% AND if it’s now fPercent lower or equal 15%.

Maybe someone more versed in ACPI has a better insight (@korli or @tqh ?), but it looks to me like if you get reasonable percentages, this code should work, as it just compares to that data…

Notifications in general don’t seem to be your issue, as you report working LAN un/plug notifications and the “notify” command works. Other notifications are Web+ download finished, new mail from the mail_daemon, and changing settings in the notifications prefs, for example.

OK, let us keep this issue down. May be it is very depending on the hardware of my old laptop or something else.

This is my third day with HAIKU and I like to get some advice.

  1. Can I get some links where I can read howto deal with the code? Means what is the preferred IDE? Is there some manual? I like to download some code from git compile it locally with debugging and look how it preceeds.
  2. My genuine reason to install HAIKU was upcycling of my old Laptop. I had to recognized that I am not able to programm a digispark (ATtiny) with Arduino on my hackmac running Mojave. Therefore I was forced to bring back this old hardware back to life, which was running Win7. I am close to my sixth decade and watched the stuff from Redmond from the early beginning. I never liked it, period. From that I like to get contact to the guys maintaining the Arduino App in HAIKU. It would be really great to bring in support for other boards and features as in the actual version.

Have you examined SimulIDE in HaikuDepot yet? Fritzing is also interesting.

There’s Paladin for an IDE. But you can just as well just get an editor like Koder and compile from Terminal. Most projects in the HaikuArchives github come with an easy to use Makefile.

Thanks, I will go first with the terminal. Following the documentation (ReadMe.Compiling.md) I cloned the repo and could build PowerStatus by jam -qa PowerStatus. A first step only, but anyway. I had to dive into the source directory of PowerStatus. At first I expected that this would run from the root dir of the src tree also.
Back to my issue with the notification. I think to know what’s gonig wrong. The charging status is wrong. The lightning icon is show whether the power supply is plugged in or not. Well, should have recognized before, sorry. Following, there will never be thrown a notification.

Congrats on building Haiku! :slight_smile:

BTW, if you want to build debug versions of components, you need to specify those in your build/jam/UserBuildConfig (see the UserBuildConfig.ReadMe there for more info). In short, this line would do that for PowerStatus:

SetConfigVar DEBUG : HAIKU_TOP src apps powerstatus : 1 : global ;

You can, e.g. start the generated binary with the Debugger to set breakpoints etc.

Ah, so there appears to be a reporting issue by the ACPI driver (I assume) after all. Do file a bug report for that including you syslog. Maybe there’s something in there the pros recognize…

For giggles, you could remove the fOnline condition in the PowerStatus code, to see if that ‘fixes’ it for you. :slight_smile:

By giving "cat /dev/power/acpi_battery/0 " in the terminal I got the correct state. From that I changed the code in PowerStatusView.cpp like that:
void
PowerStatusView::Update(bool force)
{
int32 previousPercent = fPercent;
time_t previousTimeLeft = fTimeLeft;
bool wasOnline = fOnline;
bool hadBattery = fHasBattery;
_GetBatteryInfo(fBatteryID, &fBatteryInfo);
fHasBattery = fBatteryInfo.full_capacity > 0;

if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
	fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;

//
// original code:
// fOnline = (fBatteryInfo.state & BATTERY_DISCHARGING) == 0;
// ACPI: Battery state = 0 - > power supply unplugged
// ACPI: Battery state = 1 - > discharging
// ACPI: Battery state = 2 - > charging
// battery state 1 is a bit missleading. It indicates when battery is fully
// charged (100%) and power supply is plugged in (online)
fOnline = (fBatteryInfo.state ) != 0;
fTimeLeft = fBatteryInfo.time_left;
} else {
fPercent = 0;
fOnline = false;
fTimeLeft = -1;
}

This fixes the behavior in the app regarding the icon and the notification. For the icon in the deskbar I have to look later. Question is, whether this is just an issue on my machine or does it affect also others?

2 Likes

Probably worth submitting a patch, yes. I think @tqh knows the most about this code.