Compare commits
No commits in common. "b57cbba805fd4e5c34c8638cb2eb385ec883903e" and "4e80ad46175cb6c01a75257841844cce066fbba4" have entirely different histories.
b57cbba805
...
4e80ad4617
1 changed files with 2 additions and 15 deletions
17
src/main.zig
17
src/main.zig
|
@ -13,7 +13,6 @@ pub fn main() !void {
|
||||||
defer std.process.argsFree(allocator, args);
|
defer std.process.argsFree(allocator, args);
|
||||||
|
|
||||||
var target: u8 = 15;
|
var target: u8 = 15;
|
||||||
var battery: []const u8 = "BAT0";
|
|
||||||
|
|
||||||
for (args, 0..) |arg, i| {
|
for (args, 0..) |arg, i| {
|
||||||
if (std.mem.eql(u8, arg, "--help")) {
|
if (std.mem.eql(u8, arg, "--help")) {
|
||||||
|
@ -22,8 +21,7 @@ pub fn main() !void {
|
||||||
\\Usage: bat-alert [options]
|
\\Usage: bat-alert [options]
|
||||||
\\
|
\\
|
||||||
\\Options:
|
\\Options:
|
||||||
\\ -t, --target NUM Target battery level (default: 15)
|
\\ -t, --target NUM Target battery level
|
||||||
\\ --battery NAME Battery name (default: BAT0)
|
|
||||||
\\
|
\\
|
||||||
, .{});
|
, .{});
|
||||||
std.process.exit(0);
|
std.process.exit(0);
|
||||||
|
@ -41,22 +39,12 @@ pub fn main() !void {
|
||||||
};
|
};
|
||||||
target = parsedTarget;
|
target = parsedTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std.mem.eql(u8, arg, "--battery")) {
|
|
||||||
if (i + 1 == args.len) {
|
|
||||||
std.log.err("--battery requires an argument", .{});
|
|
||||||
std.process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
battery = args[i + 1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var sent = false;
|
var sent = false;
|
||||||
const batteryPath = try std.fmt.allocPrint(allocator, "/sys/class/power_supply/{s}/capacity", .{battery});
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const capacityFile = try std.fs.openFileAbsolute(batteryPath, .{});
|
const capacityFile = try std.fs.openFileAbsolute("/sys/class/power_supply/BAT0/capacity", .{});
|
||||||
var capacityStr = std.ArrayList(u8).init(allocator);
|
var capacityStr = std.ArrayList(u8).init(allocator);
|
||||||
try capacityFile.reader().streamUntilDelimiter(capacityStr.writer(), '\n', null);
|
try capacityFile.reader().streamUntilDelimiter(capacityStr.writer(), '\n', null);
|
||||||
capacityFile.close();
|
capacityFile.close();
|
||||||
|
@ -78,7 +66,6 @@ pub fn main() !void {
|
||||||
} else {
|
} else {
|
||||||
sent = false;
|
sent = false;
|
||||||
}
|
}
|
||||||
capacityStr.deinit();
|
|
||||||
|
|
||||||
std.time.sleep(10 * 1e9);
|
std.time.sleep(10 * 1e9);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue