summaryrefslogtreecommitdiff
path: root/src/print_battery_info.c
AgeCommit message (Collapse)Author
2020-02-10use format_placeholder for batteryFelix Buehler
2019-11-16Introduce format_percentage for battery (#371)grmat
Allow custom output, backwards-compatible to integer_battery_capacity
2019-07-21Merge pull request #355 from jasperla/header_fixIngo Bürk
Fix headers meant for OpenBSD, but snuck in for FreeBSD
2019-07-12battery: include sys/sysctl.h on OpenBSDMichael Stapelberg
This is required so that CTL_HW and others are defined (ran into this on OpenBSD 6.5).
2019-07-08Fix headers meant for OpenBSD, but snuck in for FreeBSDJasper Lievisse Adriaanse
2019-07-08Extend battery handling on OpenBSD (#351)Jasper Lievisse Adriaanse
If acpibat watts value is not available, try current (for batteries that report in amps), then convert to watts. originally submitted by @jcs
2019-01-23Switch to autotools (#316)Michael Stapelberg
2018-09-03Add support for "POWER_SUPPLY_STATUS=Not charging" (fixes #304)David96
2018-07-13able to print percentageFelix Buehler
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-13Merge pull request #256 from oyvinht/masterIngo Bürk
Read multiple batteries on DragonFly BSD.
2018-06-20Prevent potential crash if glob() failsOlivier Gayot
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-20Fix potential memory leak on LinuxOlivier Gayot
The function slurp_all_batteries(), on Linux, allocates memory dynamically Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-03-27Read multiple batteries on DragonFly BSD.Øyvin Halfdan Thuv
Using ACPI to read individual battery information instead of just accumulations from sysctl.
2018-01-28Treat zero battery capacity as "not available" (#259)johcgt
`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.
2017-08-24Be more cautious about handling invalid battery measurements.kousu
2017-08-19Use local timezone for battery %emptytime (#236)Emeric Planet
2017-04-13Add battery capacity parsing (#216)Emeric Planet
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-02-07Suppress printing :00 seconds of remaining battery lifetime, as apm(4)'sJasper Lievisse Adriaanse
estimate only has a granularity of minutes. From tb@openbsd.org
2016-10-23Detect batteries using glob (#163)Stu Zhao
2016-08-28Implement aggregates for batteries.Tommie Gannert
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-22Match trailing equal sign in slurp_battery_info.Tommie Gannert
Should make it more resilient to future ambiguities in uevent.
2016-08-21Added missing ampere to watt conversion for last full capacity. (#158)tnnn
Signed-off-by: Tomasz Nitecki <tnnn@tnnn.pl>
2016-08-14Move time and ratio computations out of slurp_battery_info. (#151)tommie
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-14Move full_design and full_last into struct battery_info.Tommie Gannert
This is in preparation for moving the ratio computation code out of slurp_battery_info to support aggregating multiple batteries.
2016-08-14Also capture charge rate in NetBSD.Tommie Gannert
For time estimates when charging.
2016-08-14Fix warnings about using a char array index on NetBSD.Tommie Gannert
The isspace macro is just a table lookup.
2016-08-14Simplify string comparisons in slurp_battery_info for NetBSD.Tommie Gannert
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-14Remove warnings about unused variables in slurp_battery_info on OpenBSD.Tommie Gannert
2016-08-03Move OS-specific code to slurp_battery_info.Tommie Gannert
2016-08-03Introduce a struct battery_info to carry information from data retrieval to ↵Tommie Gannert
the output formatter.
2016-08-03Refactor common seconds_remaining code in print_battery_info.Tommie Gannert
2016-08-03Remove an END_COLOR in print_battery_info for OpenBSD.Tommie Gannert
This was probably a bug since it makes no sense to have here.
2016-08-03Move START_COLOR to after OS-specific code.Tommie Gannert
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-03Remove consumptionbuf from print_battery_info.Tommie Gannert
2016-08-03Remove emptytimebuf from print_battery_info.Tommie Gannert
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-03Remove remainingbuf from print_battery_info.Tommie Gannert
2016-08-01Remove percentagebuf from print_battery_info.Tommie Gannert
2016-08-01Remove statusbuf from print_battery_info.Tommie Gannert
2016-03-21Added status_unk to battery_infoeoin
2016-01-25This removes the 'remaining' time when the battery is full, since the ↵Clayton Craft
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.
2015-10-08Properly detect the battery charging status under FreeBSD.John Baldwin
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-04Added support for lemonbarBrendan Van Hook
2015-05-20Clamp the percentage at 100% when last_full_capacity is enabled.Michael Stapelberg
2015-05-05Changed battery info output to HH:MM for consistency accross all platformsNicholas Helke
2015-03-16clang-format-3.5 -i **/*.[ch], update modelineMichael Stapelberg
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.
2014-12-22Avoid use of uninitialized variable in print_battery_infoAlexander Monakov
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-10-07Created three individual Strings for each battery status (charging, ↵Cyril Andreatta
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-08-25Fix battery indicator on systems without POWER_SUPPLY_VOLTAGE_NOW.Klemen Košir
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-05-31Use the absolute values for (dis)charging ratesMichael Stapelberg
Apparently some notebooks report a negative current, whereas most don’t. fixes #1249
2014-04-30Implement battery functionality for NetBSD usersAlexander Vasarab
This patch takes a similar approach as the NetBSD CPU temperature code in that it uses proplib(3) to walk dictionaries supplied by envsys(4). In addition to providing the basic functionality, it: * Provides all existing format specifiers (%emptytime %consumption %status %percentage %remaining) * Respects all existing config options (hide_seconds, low_threshold, integer_battery_capacity, last_full_capacity) * Projects "time until full" when battery status is CS_CHARGING