diff options
author | Jakob P. Liljenberg <admin@qvantnet.com> | 2024-02-11 17:54:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-11 17:54:00 +0100 |
commit | 65f3ade9b6446ef73eaffec6fbce20118748c50b (patch) | |
tree | a542d5cbddbb5bc21ecc8950ca2ce74e8097c7f8 /src/freebsd | |
parent | ab0bef204a248609ac05948e531108a8032b8e63 (diff) | |
parent | e8137674b0604b3f5171ac58bd8895e46469c2a6 (diff) |
Merge branch 'main' into unix-duplicates
Diffstat (limited to 'src/freebsd')
-rw-r--r-- | src/freebsd/btop_collect.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index d64a878..decd542 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -195,7 +195,7 @@ namespace Cpu { string cpuName; string cpuHz; 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"}; @@ -361,10 +361,11 @@ namespace Cpu { return core_map; } - auto get_battery() -> tuple<int, long, string> { - if (not has_battery) return {0, 0, ""}; + auto get_battery() -> tuple<int, float, long, string> { + if (not has_battery) return {0, 0, 0, ""}; long seconds = -1; + float watts = -1; uint32_t percent = -1; size_t size = sizeof(percent); string status = "discharging"; @@ -376,6 +377,10 @@ namespace Cpu { if (sysctlbyname("hw.acpi.battery.time", &seconds, &size, nullptr, 0) < 0) { seconds = 0; } + size = sizeof(watts); + if (sysctlbyname("hw.acpi.battery.rate", &watts, &size, nullptr, 0) < 0) { + watts = -1; + } int state; size = sizeof(state); if (sysctlbyname("hw.acpi.battery.state", &state, &size, nullptr, 0) < 0) { @@ -390,7 +395,7 @@ namespace Cpu { } } - return {percent, seconds, status}; + return {percent, watts, seconds, status}; } auto collect(bool no_update) -> cpu_info & { |