mirror of
https://github.com/aristocratos/btop.git
synced 2024-06-17 01:45:34 +12:00
add freebsd support for battery power
This commit is contained in:
parent
cd6c1b7294
commit
a81b514d6d
|
@ -200,7 +200,7 @@ namespace Cpu {
|
||||||
string cpuName;
|
string cpuName;
|
||||||
string cpuHz;
|
string cpuHz;
|
||||||
bool has_battery = true;
|
bool has_battery = true;
|
||||||
tuple<int, long, string> current_bat;
|
tuple<int, float, long, string> current_bat;
|
||||||
|
|
||||||
const array<string, 10> time_names = {"user", "nice", "system", "idle"};
|
const array<string, 10> time_names = {"user", "nice", "system", "idle"};
|
||||||
|
|
||||||
|
@ -366,10 +366,11 @@ namespace Cpu {
|
||||||
return core_map;
|
return core_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_battery() -> tuple<int, long, string> {
|
auto get_battery() -> tuple<int, float, long, string> {
|
||||||
if (not has_battery) return {0, 0, ""};
|
if (not has_battery) return {0, 0, 0, ""};
|
||||||
|
|
||||||
long seconds = -1;
|
long seconds = -1;
|
||||||
|
float watts = -1;
|
||||||
uint32_t percent = -1;
|
uint32_t percent = -1;
|
||||||
size_t size = sizeof(percent);
|
size_t size = sizeof(percent);
|
||||||
string status = "discharging";
|
string status = "discharging";
|
||||||
|
@ -381,6 +382,10 @@ namespace Cpu {
|
||||||
if (sysctlbyname("hw.acpi.battery.time", &seconds, &size, nullptr, 0) < 0) {
|
if (sysctlbyname("hw.acpi.battery.time", &seconds, &size, nullptr, 0) < 0) {
|
||||||
seconds = 0;
|
seconds = 0;
|
||||||
}
|
}
|
||||||
|
size = sizeof(watts);
|
||||||
|
if (sysctlbyname("hw.acpi.battery.rate", &watts, &size, nullptr, 0) < 0) {
|
||||||
|
watts = -1;
|
||||||
|
}
|
||||||
int state;
|
int state;
|
||||||
size = sizeof(state);
|
size = sizeof(state);
|
||||||
if (sysctlbyname("hw.acpi.battery.state", &state, &size, nullptr, 0) < 0) {
|
if (sysctlbyname("hw.acpi.battery.state", &state, &size, nullptr, 0) < 0) {
|
||||||
|
@ -395,7 +400,7 @@ namespace Cpu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {percent, seconds, status};
|
return {percent, watts, seconds, status};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto collect(bool no_update) -> cpu_info & {
|
auto collect(bool no_update) -> cpu_info & {
|
||||||
|
|
Loading…
Reference in a new issue