feat: add kernel ACPI support for querying battery percentage, add battery indicator to desktop, move log state to 0:/state directory
This commit is contained in:
1 parent
0a18b2cf2d
commit
e641500b40
34 files changed
+2461
-100
No files matched your search
@@ -95,6 +95,63 @@ static void print_snapshot(const montauk::abi::PowerInfo& info) {
|
||||
print("\n");
|
||||
}
|
||||
|
||||
// Battery is reported independently of the CPU power features: a laptop under
|
||||
// emulation has neither, but a real one may well expose a battery and no HWP.
|
||||
static void print_battery() {
|
||||
montauk::abi::BatteryInfo b{};
|
||||
if (montauk::battery_info(&b) != 0) {
|
||||
print("Battery: none (no ACPI battery device)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!b.present) {
|
||||
print("Battery: slot present, no pack installed");
|
||||
if (b.hasAcAdapter) print(b.acOnline ? " (on AC)" : " (no AC)");
|
||||
print("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print("Battery: ");
|
||||
put_u64(b.percent);
|
||||
print("%");
|
||||
|
||||
if (b.charging) print(", charging");
|
||||
else if (b.acOnline) print(", on AC, not charging");
|
||||
else print(", discharging");
|
||||
if (b.critical) print(", CRITICAL");
|
||||
print("\n");
|
||||
|
||||
if (b.fullCapacity > 0) {
|
||||
print(" Capacity: ");
|
||||
put_u64(b.remainingCapacity);
|
||||
print(" of ");
|
||||
put_u64(b.fullCapacity);
|
||||
print(b.powerUnitMilliAmps ? " mAh (design " : " mWh (design ");
|
||||
put_u64(b.designCapacity);
|
||||
print(")\n");
|
||||
}
|
||||
|
||||
if (b.presentRate > 0) {
|
||||
print(" Rate: ");
|
||||
put_u64(b.presentRate);
|
||||
print(b.powerUnitMilliAmps ? " mA\n" : " mW\n");
|
||||
}
|
||||
|
||||
if (b.minutesRemaining >= 0) {
|
||||
print(" Time left: ");
|
||||
put_u64((uint64_t)(b.minutesRemaining / 60));
|
||||
print("h ");
|
||||
put_u64((uint64_t)(b.minutesRemaining % 60));
|
||||
print("m\n");
|
||||
}
|
||||
|
||||
if (b.voltageMv > 0) {
|
||||
print(" Voltage: ");
|
||||
put_u64(b.voltageMv);
|
||||
print(" mV\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void print_watch_line(const montauk::abi::PowerInfo& info, uint64_t t) {
|
||||
put_u64(t);
|
||||
print("s ");
|
||||
@@ -124,13 +181,16 @@ extern "C" void _start() {
|
||||
montauk::abi::PowerInfo info{};
|
||||
if (!read_info(info)) {
|
||||
print("power: no CPU power management available\n");
|
||||
print("(non-Intel CPU or running under emulation)\n");
|
||||
print("(non-Intel CPU or running under emulation)\n\n");
|
||||
print_battery();
|
||||
montauk::exit(1);
|
||||
}
|
||||
|
||||
bool watch = rest[0] == 'w';
|
||||
if (!watch) {
|
||||
print_snapshot(info);
|
||||
print("\n");
|
||||
print_battery();
|
||||
montauk::exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user