Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement get_battery_power_draw() for FreeBSD. #1252

Merged
merged 1 commit into from Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/freebsd.cc
Expand Up @@ -460,6 +460,27 @@ int get_battery_perct(const char *) {
return batcapacity;
}

void get_battery_power_draw(char *buffer, unsigned int n, const char *bat) {
int rate = 0;
double ret = 0;

/*
* hw.acpi.battery.rate returns battery discharge rate in mW,
* or -1 (according to docs, but also 0 in practice) when not discharging.
*
* ref. acpi_battery(4)
*/
if (GETSYSCTL("hw.acpi.battery.rate", rate)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.rate\"\n");
}

if (rate > 0) {
ret = (double)rate/(double)1000;
}

snprintf(buffer, n, "%.1f", ret);
}

double get_battery_perct_bar(struct text_object *obj) {
int batperct = get_battery_perct(obj->data.s);
return batperct;
Expand Down