Linux: Batteries.

Linux also provides battery vendor and model. As with FreeBSD
set the label for battery name "properly".
This commit is contained in:
Alastair Poole 2019-09-08 01:13:43 +01:00
parent f086b0d2d5
commit 3d51dfe687
1 changed files with 35 additions and 0 deletions

View File

@ -943,9 +943,44 @@ _battery_state_get(power_t *power)
free(buf);
}
char *model, *vendor;
snprintf(path, sizeof(path), "/sys/class/power_supply/%s/manufacturer", power->battery_names[i]);
vendor = file_contents(path);
snprintf(path, sizeof(path), "/sys/class/power_supply/%s/model_name", power->battery_names[i]);
model = file_contents(path);
if (vendor && vendor[0] && model && model[0])
{
char name[256];
int len;
len = strlen(vendor);
if (vendor[len - 1] == '\n' || vendor[len - 1] == '\r')
{
vendor[len - 1] = '\0';
}
len = strlen(model);
if (model[len - 1] == '\n' || model[len - 1] == '\r')
{
model[len - 1] = '\0';
}
free(power->battery_names[i]);
snprintf(name, sizeof(name), "%s (%s)", vendor, model);
power->battery_names[i] = strdup(name);
}
power->batteries[i]->charge_full = charge_full;
power->batteries[i]->charge_current = charge_current;
if (model)
free(model);
if (vendor)
free(vendor);
free(naming);
if (i == MAX_BATTERIES)