Commit Graph

86 Commits

Author SHA1 Message Date
Michael Nolan e19539e5f6
Add support for batteries outputting Time to empty on linux (#378)
* Add support for batteries outputting Time to empty on linux

The battery in the pinebook pro does not output the remaining charge
in Wh or mAh, so i3 cannot calculate the time remaining. However, it
does directly output the number of minutes remaining on in
POWER_SUPPLY_TIME_TO_EMPTY. This adds support for reading this field
and converting it to seconds_remaining.

* Add testcase for POWER_SUPPLY_TIME_TO_EMTY_NOW
2020-06-15 09:09:06 +02:00
Felix Buehler b5a804d1af use format_placeholder for battery 2020-02-10 21:05:18 +01:00
grmat abfe05c8bd Introduce format_percentage for battery (#371)
Allow custom output, backwards-compatible to integer_battery_capacity
2019-11-16 16:26:26 +01:00
Ingo Bürk 86a4ff0333
Merge pull request #355 from jasperla/header_fix
Fix headers meant for OpenBSD, but snuck in for FreeBSD
2019-07-21 15:28:40 +02:00
Michael Stapelberg 02a47cd196 battery: include sys/sysctl.h on OpenBSD
This is required so that CTL_HW and others are defined (ran into this on OpenBSD
6.5).
2019-07-12 14:44:03 +02:00
Jasper Lievisse Adriaanse 70b954b122 Fix headers meant for OpenBSD, but snuck in for FreeBSD 2019-07-08 20:14:59 +02:00
Jasper Lievisse Adriaanse 3a51673c05 Extend battery handling on OpenBSD (#351)
If acpibat watts value is not available, try current (for batteries
that report in amps), then convert to watts.

originally submitted by @jcs
2019-07-08 17:53:25 +02:00
Michael Stapelberg a57cdc84e2
Switch to autotools (#316) 2019-01-23 08:56:40 +01:00
David96 6a5e5b8ac4 Add support for "POWER_SUPPLY_STATUS=Not charging" (fixes #304) 2018-09-03 20:50:36 +02:00
Felix Buehler 52e9f6f63b able to print percentage
its now possible to have percentage before and after a variable. except
for the date. But percentage with dates does not make much sense to me, so
i skipped it.
2018-07-13 15:03:31 +02:00
Ingo Bürk 9aafc38370
Merge pull request #256 from oyvinht/master
Read multiple batteries on DragonFly BSD.
2018-07-13 12:31:04 +02:00
Olivier Gayot c221b4d331 Prevent potential crash if glob() fails
Calling globfree(NULL) is undefined behaviour. In Linux (glibc), it
results in a segmentation fault.

It is also undefined behaviour to call globfree(&pglob) if a previous
call to glob(&pglob) returned an error.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot 445b1925e3 Fix potential memory leak on Linux
The function slurp_all_batteries(), on Linux, allocates memory
dynamically

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Øyvin Halfdan Thuv 3e1213123f Read multiple batteries on DragonFly BSD.
Using ACPI to read individual battery information instead of just
accumulations from sysctl.
2018-03-27 11:52:08 +02:00
johcgt d5c69a9d60 Treat zero battery capacity as "not available" (#259)
`print_battery_info` computes `batt_info.percentage_remaining` by
dividing batt_info.remaining by `full`. If `full` is `0` then the
battery remaining will be reported as "inf".

Before this, it tries to set `full` to either the design capacity or to
the last known good charge. It determines if these values are available
by checking whether their fields in `batt_info` are non-negative. As it
initialized `batt_info` with values of `-1`, a non-negative value
implies that something has provided a value.

`slurp_all_batteries` and `add_battery_info` however initialize these
fields to zero, so if these functions are called then
`batt_info.full_design` will always be used.

This means that on systems that don't provide a value for design
capacity the percentage remaining will be reported as "inf", unless the
user has set `last_full_capacity` to `true` in their `i3status.conf`.

This patch changes `print_battery_info` to expect values for the battery
capacity to be strictly greater than zero. This seems reasonable as a
battery with a capacity of zero isn't useful.

An alternative solution would be to change `slurp_all_batteries` and
`add_battery_info` to initialize `batt_info` with `-1`, as
`print_battery_info` does. This is less appealing as `add_battery_info`
is accumulating the values, so using `-1` would introduce off-by-one
errors without additional code to avoid them.
2018-01-28 15:37:51 +01:00
kousu 62d0905c7f Be more cautious about handling invalid battery measurements. 2017-08-24 19:00:08 -04:00
Emeric Planet ca9bee8b88 Use local timezone for battery %emptytime (#236) 2017-08-19 14:56:30 +02:00
Emeric Planet c7dea74751 Add battery capacity parsing (#216)
The Linux power supply class defines three entries to provide battery status.
One of them wasn't used: POWER_SUPPLY_CAPACITY.

https://www.kernel.org/doc/Documentation/power/power_supply_class.txt
2017-04-13 21:46:21 +02:00
Jasper Lievisse Adriaanse 9166765803 Suppress printing :00 seconds of remaining battery lifetime, as apm(4)'s
estimate only has a granularity of minutes.

From tb@openbsd.org
2017-02-07 19:25:03 +01:00
Stu Zhao 707ceffc8b Detect batteries using glob (#163) 2016-10-23 21:20:31 +02:00
Tommie Gannert dc072f9f53 Implement aggregates for batteries.
Using title number all, this enables aggregates. Note that FreeBSD and
OpenBSD previously only reported aggregates, so this is bringing Linux
and NetBSD that functionality.

Changes the default battery reporting to the aggregate since most
users probably don't care about individual batteries. For single-battery
systems there should be no change.

Fixes one obvious memory leak in NetBSD.
2016-08-28 14:29:08 +01:00
Tommie Gannert ac8998ef03 Match trailing equal sign in slurp_battery_info.
Should make it more resilient to future ambiguities in uevent.
2016-08-22 21:18:31 +01:00
tnnn a2fd4bd074 Added missing ampere to watt conversion for last full capacity. (#158)
Signed-off-by: Tomasz Nitecki <tnnn@tnnn.pl>
2016-08-21 13:11:19 -07:00
tommie 7ce0044a03 Move time and ratio computations out of slurp_battery_info. (#151)
This allows OSes that support reporting multiple batteries to simply
sum into full_design,full_last,remaining and let print_battery_info
make computations.
2016-08-14 23:52:20 -07:00
Tommie Gannert d74bc90bfe Move full_design and full_last into struct battery_info.
This is in preparation for moving the ratio computation code out of
slurp_battery_info to support aggregating multiple batteries.
2016-08-14 20:44:54 +01:00
Tommie Gannert 9970af67e5 Also capture charge rate in NetBSD.
For time estimates when charging.
2016-08-14 20:44:54 +01:00
Tommie Gannert eb0b6412af Fix warnings about using a char array index on NetBSD.
The isspace macro is just a table lookup.
2016-08-14 12:37:38 +01:00
Tommie Gannert a937693cef Simplify string comparisons in slurp_battery_info for NetBSD.
Doing strlen(a) == strlen(b) && strncmp(a, b, N) seems to have no
benefits compared to just strcmp(a, b). The NetBSD cstring properties
come from the kernel, not the user.

The test for units did a prefix match, but that looked like a bug, the
unit is "Watt hour" in my Virtual box.
2016-08-14 12:20:43 +01:00
Tommie Gannert 185d70ecbb Remove warnings about unused variables in slurp_battery_info on OpenBSD. 2016-08-14 11:52:27 +01:00
Tommie Gannert 77f097dcca Move OS-specific code to slurp_battery_info. 2016-08-03 23:27:04 +01:00
Tommie Gannert a537d1503a Introduce a struct battery_info to carry information from data retrieval to the output formatter. 2016-08-03 23:27:04 +01:00
Tommie Gannert 0b16860145 Refactor common seconds_remaining code in print_battery_info. 2016-08-03 23:09:16 +01:00
Tommie Gannert 52f0dd6a36 Remove an END_COLOR in print_battery_info for OpenBSD.
This was probably a bug since it makes no sense to have here.
2016-08-03 23:09:15 +01:00
Tommie Gannert 6d3e9991de Move START_COLOR to after OS-specific code.
This uses the more direct tests of whether percentage_remaining and
seconds_remaining are available or not (rather than looking at
present_rate).
2016-08-03 23:09:02 +01:00
Tommie Gannert 47ec48b85d Remove consumptionbuf from print_battery_info. 2016-08-03 20:13:10 +01:00
Tommie Gannert b890d2e416 Remove emptytimebuf from print_battery_info.
This changes the behavior for NetBSD: previously this time was not
shown while charging. On Linux it was treated as "full time". This
change makes all OSes behave the same.

OpenBSD and FreeBSD did not support emptytime previously.
2016-08-03 20:13:10 +01:00
Tommie Gannert 63724e2fa5 Remove remainingbuf from print_battery_info. 2016-08-03 08:24:24 +01:00
Tommie Gannert 0390dbf2e0 Remove percentagebuf from print_battery_info. 2016-08-01 00:34:31 +01:00
Tommie Gannert 88a0c6923c Remove statusbuf from print_battery_info. 2016-08-01 00:24:40 +01:00
eoin d59589bf9e Added status_unk to battery_info 2016-03-21 22:41:22 +00:00
Clayton Craft 430b053326 This removes the 'remaining' time when the battery is full, since the remaining time is always 00:00:00. When the battery is discharging, the remaining time will show up again if the user has set their format correctly. 2016-01-25 00:38:13 -08:00
John Baldwin 5e33d9fe74 Properly detect the battery charging status under FreeBSD.
The hw.acpi.battery.state sysctl returns a bitmask of flags as
defined in <dev/acpica/acpiio.h>.  Use constants from this header
to examine the state and check for the charging flag to determine
if the battery is charging.
2015-10-08 13:15:38 -07:00
Brendan Van Hook a13b2e7288 Added support for lemonbar 2015-10-04 14:52:32 -04:00
Michael Stapelberg d1aa135d28 Clamp the percentage at 100% when last_full_capacity is enabled. 2015-05-20 19:17:23 +02:00
Nicholas Helke d7f0d64c40 Changed battery info output to HH:MM for consistency accross all platforms 2015-05-05 10:51:57 +01:00
Michael Stapelberg d74e904bf4 clang-format-3.5 -i **/*.[ch], update modeline
From here on, we’ll use clang-format to automatically format the source.

This has worked well in i3, so we are introducing it for i3status.
2015-03-16 10:01:07 +01:00
Alexander Monakov 05273b03fd Avoid use of uninitialized variable in print_battery_info
The boolean flag 'watt_as_unit' may be used without being initialized if the
configured battery path does not contain expected statistics (for example if
it is misconfigured and points to AC adapter info or simply an unrelated file).

Even though it does not cause ill effects, it causes a warning (true positive)
when running i3status under Valgrind.  Initialize the variable to make code
well-defined.
2014-12-22 09:19:40 +01:00
Cyril Andreatta 8e22f3839d Created three individual Strings for each battery status (charging, dicharching, full)
Replaced hard coded status strings (CHR, BAT, FULL) in
print_battery_info.c with user defined strings. The new strings are
'status_chr', 'status_bat' and 'status_full' and can be set in i3status.conf.
e.g.
status_chr = " CHR"

If any of the new status strings is omitted the standard strings (CHR,
BAT, FULL) are used.
2014-10-07 18:52:01 +02:00
Klemen Košir fcd95c2408 Fix battery indicator on systems without POWER_SUPPLY_VOLTAGE_NOW.
In my case, the voltage variable would stay initialized as -1,
which caused the calculation of battery charge percentage to be
incorrect (I would get the message that there is no battery present
or even -0% charge).

I have no idea how this would affect other systems, since I don't
have a chance to test this.
2014-08-25 19:36:02 +02:00
Michael Stapelberg 2158128ea0 Use the absolute values for (dis)charging rates
Apparently some notebooks report a negative current, whereas most don’t.

fixes #1249
2014-05-31 14:01:18 +02:00