Compare commits
No commits in common. "6d4156322682919c86d922131c2f658e0b67da65" and "25e410c0b592a432402b8a8e9c50a493be8e0b6f" have entirely different histories.
6d41563226
...
25e410c0b5
34
src/main.zig
34
src/main.zig
|
@ -38,7 +38,6 @@ fn usage(args: [][]u8) !void {
|
|||
const Options = struct {
|
||||
background_filename: [:0]u8,
|
||||
device_file: [:0]u8,
|
||||
flip: bool,
|
||||
};
|
||||
pub fn main() !void {
|
||||
defer deinit();
|
||||
|
@ -84,15 +83,12 @@ pub fn main() !void {
|
|||
line_inx += 1;
|
||||
}
|
||||
}
|
||||
const opts = try processArgs(args, &lines);
|
||||
const opts = try processArgs(alloc, args, &lines);
|
||||
defer alloc.destroy(opts);
|
||||
if (opts.background_filename.len > 0) try stdout.print("Converting {s}\n", .{opts.background_filename});
|
||||
var pixels: [display.WIDTH * display.HEIGHT]u8 = undefined;
|
||||
try convertImage(opts.background_filename, &pixels, noTextForLine);
|
||||
try addTextToImage(alloc, &pixels, &lines);
|
||||
if (opts.flip) {
|
||||
try stdout.print("Flipping\n", .{});
|
||||
flipImage(&pixels);
|
||||
}
|
||||
try bw.flush();
|
||||
|
||||
// We should take the linux device file here, then inspect for ttyUSB vs
|
||||
|
@ -118,31 +114,24 @@ fn deinit() void {
|
|||
font_arena = null;
|
||||
}
|
||||
|
||||
fn processArgs(args: [][:0]u8, line_array: *[display.LINES]*const [:0]u8) !Options {
|
||||
fn processArgs(allocator: std.mem.Allocator, args: [][:0]u8, line_array: *[display.LINES]*const [:0]u8) !*Options {
|
||||
if (args.len < 2) try usage(args);
|
||||
const prefix = "/dev/ttyUSB";
|
||||
var opts = Options{
|
||||
.device_file = args[1],
|
||||
.flip = false,
|
||||
.background_filename = @constCast(""),
|
||||
};
|
||||
var opts = try allocator.create(Options);
|
||||
opts.device_file = args[1];
|
||||
if (!std.mem.eql(u8, opts.device_file, "-") and !std.mem.startsWith(u8, opts.device_file, prefix)) try usage(args);
|
||||
|
||||
opts.background_filename = @constCast("");
|
||||
var is_filename = false;
|
||||
var line_number: ?usize = null;
|
||||
for (args[1..], 1..) |arg, i| {
|
||||
if (std.mem.eql(u8, "-flip", arg)) {
|
||||
opts.flip = true;
|
||||
continue;
|
||||
}
|
||||
if (std.mem.eql(u8, "-bg", arg)) {
|
||||
is_filename = true;
|
||||
continue;
|
||||
}
|
||||
if (is_filename) {
|
||||
is_filename = false;
|
||||
opts.background_filename = args[i]; // arg capture changes value...
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if ((arg[0] == '-' and arg.len > 1) and areDigits(arg[1..])) {
|
||||
line_number = try std.fmt.parseInt(usize, arg[1..], 10);
|
||||
|
@ -171,15 +160,6 @@ fn areDigits(bytes: []u8) bool {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
fn flipImage(pixels: *[display.WIDTH * display.HEIGHT]u8) void {
|
||||
for (pixels[0..(display.WIDTH * display.HEIGHT / 2)], 0..) |_, i| {
|
||||
const dest_pixel = pixels[pixels.len - 1 - i];
|
||||
const src_pixel = pixels[i];
|
||||
|
||||
pixels[pixels.len - 1 - i] = src_pixel;
|
||||
pixels[i] = dest_pixel;
|
||||
}
|
||||
}
|
||||
|
||||
fn addTextToImage(allocator: std.mem.Allocator, pixels: *[display.WIDTH * display.HEIGHT]u8, data: []*[]u8) !void {
|
||||
var maybe_font_data = try getFontData(allocator, DEFAULT_FONT);
|
||||
|
|
Loading…
Reference in New Issue
Block a user