mirror of
https://github.com/aristocratos/btop.git
synced 2024-05-18 11:22:46 +12:00
add power draw calculation for battery
This commit is contained in:
parent
b09f352c09
commit
419a7d4ca3
|
@ -755,6 +755,7 @@ namespace Cpu {
|
|||
|
||||
int percent = -1;
|
||||
long seconds = -1;
|
||||
float watts = -1;
|
||||
|
||||
//? Try to get battery percentage
|
||||
if (percent < 0) {
|
||||
|
@ -820,6 +821,25 @@ namespace Cpu {
|
|||
}
|
||||
}
|
||||
|
||||
//? Get power draw
|
||||
if (b.use_power) {
|
||||
if (not b.power_now.empty()) {
|
||||
try {
|
||||
watts = (float)stoll(readfile(b.energy_now, "-1")) / 1000000.0;
|
||||
}
|
||||
catch (const std::invalid_argument&) { }
|
||||
catch (const std::out_of_range&) { }
|
||||
}
|
||||
else if (not b.voltage_now.empty() and not b.current_now.empty()) {
|
||||
try {
|
||||
watts = (float)stoll(readfile(b.current_now, "-1")) / 1000000.0 * stoll(readfile(b.voltage_now, "1")) / 1000000.0;
|
||||
}
|
||||
catch (const std::invalid_argument&) { }
|
||||
catch (const std::out_of_range&) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {percent, seconds, status};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue