From 69ec05bb07cd8ea13fca6574ac9882acb2618daf Mon Sep 17 00:00:00 2001 From: datalore Date: Mon, 2 Jun 2025 19:56:37 +0200 Subject: [PATCH] Added charging status --- src/batteryinfo.zig | 4 ++++ src/main.zig | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/batteryinfo.zig b/src/batteryinfo.zig index b2315b5..94d0806 100644 --- a/src/batteryinfo.zig +++ b/src/batteryinfo.zig @@ -6,6 +6,7 @@ pub const BatteryInfo = struct { Manufacturer: []u8, Model: []u8, Technology: []u8, + Status: []u8, CellSeriesCount: u32 = 0, Capacity: u32 = 0, CapacityDesign: u32 = 0, @@ -21,6 +22,7 @@ pub const BatteryInfo = struct { self._allocator.free(self.Manufacturer); self._allocator.free(self.Model); self._allocator.free(self.Technology); + self._allocator.free(self.Status); } }; @@ -41,11 +43,13 @@ pub fn GetBatteryInfoAlloc(allocator: std.mem.Allocator, dir: std.fs.Dir) !Batte const manufacturer = try _readInfo(allocator, dir, "manufacturer"); const model = try _readInfo(allocator, dir, "model_name"); const technology = try _readInfo(allocator, dir, "technology"); + const status = try _readInfo(allocator, dir, "status"); var info = BatteryInfo{ .Manufacturer = manufacturer, .Model = model, .Technology = technology, + .Status = status, ._allocator = allocator, }; diff --git a/src/main.zig b/src/main.zig index 62a0564..22bdafb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -23,7 +23,7 @@ pub fn main() !void { fn printBattery(battery: batinfo.BatteryInfo) !void { const stdout = std.io.getStdOut().writer(); - try stdout.print("Battery {s} {s}\n", .{battery.Manufacturer, battery.Model}); + try stdout.print("Battery {s} {s} ({s})\n", .{battery.Manufacturer, battery.Model, battery.Status}); try stdout.print("\tTechnology: {s}\n", .{battery.Technology}); try stdout.print("\tCell series count: {}s (guessed)\n\n", .{battery.CellSeriesCount}); try stdout.print("\tCapacity: {}%\n", .{battery.Capacity});