be able to read upside-down barcodes

This commit is contained in:
2025-05-31 11:19:07 -04:00
parent b734760dd3
commit ca60281d7c
2 changed files with 23 additions and 1 deletions
+23 -1
View File
@@ -188,7 +188,29 @@ fn generateChecksum(data: [13]u8) u16 {
return checksum;
}
fn decode(bars: [65]BarType) Error!BarcodeResult {
fn flipBarcode(bars: [65]BarType) [65]BarType {
var flipped: [65]BarType = undefined;
var i: u8 = 65;
for (bars) |bar| {
i -= 1;
flipped[i] = switch (bar) {
.ascending => .descending,
.descending => .ascending,
else => bar,
};
}
return flipped;
}
pub fn decode(bars: [65]BarType) Error!BarcodeResult {
return tryDecode(bars) catch tryDecode(flipBarcode(bars));
}
fn tryDecode(bars: [65]BarType) Error!BarcodeResult {
var characters = [_]u13{0} ** 10;
for (bars, 0..) |bar, i| {