feat: add more quotes to the printed slips

Move the quotes into their own module and add 67 English-only ones: good
times, Winfnachten, winf.at, studying at TU Wien, getting involved and
receipt jokes. A quote is now a list of printed lines instead of a fixed
German/English pair, and the middle dot is sent as its PC437 byte.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bankosegger
2026-11-15 22:01:26 +01:00
parent d06077a257
commit 39e055eb0e
3 changed files with 136 additions and 44 deletions

View File

@@ -52,6 +52,8 @@ use opencv::{
prelude::*,
};
use crate::quotes::QUOTES;
const DEFAULT_PRINTER: &str = "/dev/usb/lp0";
const DEFAULT_DOTS: usize = 576;
const DEFAULT_GAMMA: f32 = 2.0;
@@ -74,42 +76,6 @@ const KEEPSAKE_DE: &str = "Ich war dabei!";
const KEEPSAKE_EN: &str = "I was there!";
/// Capture time, written the German way and the same in both languages.
const STAMP_FORMAT: &str = "%d.%m.%Y, %H:%M";
/// One is printed per slip. Each line is short enough for a single 80 mm line;
/// on 58 mm paper the longer ones wrap.
const QUOTES: [[&str; 2]; 8] = [
[
"Analysis bestanden. Wunder gibt es doch.",
"Passed Analysis. Miracles do happen.",
],
[
"Im Freihaus gibt es Kaffee und Hoffnung.",
"The Freihaus serves coffee and hope.",
],
[
"TISS sagt nein. Mein Herz sagt auch nein.",
"TISS says no. So does my heart.",
],
[
"WINF: zwei Fächer, eine Deadline.",
"WINF: two subjects, one deadline.",
],
[
"Karlsplatz: der schönste Umweg zur Uni.",
"Karlsplatz: the prettiest detour to class.",
],
[
"Prüfungswoche: Schlafen ist optional.",
"Exam week: sleeping is optional.",
],
[
"Die Bibliothek kennt alle meine Ausreden.",
"The library has heard all my excuses.",
],
[
"Mathe ist einfach, sagt die Mathematik.",
"Maths is easy, says maths.",
],
];
/// Pause between writes, leaving the head time to drain a band (8 mm of paper)
/// before the next one arrives.
const PACE: Duration = Duration::from_millis(100);
@@ -402,9 +368,10 @@ fn encode(
job
}
/// The German letters in the captions as single PC437 bytes, the code page the
/// booth's printer starts in. Anything else non-ASCII would need a wider table
/// or `ESC t`, so a test keeps the printed text within this set.
/// The German letters and the middle dot in the captions as single PC437 bytes,
/// the code page the booth's printer starts in. Anything else non-ASCII would
/// need a wider table or `ESC t`, so a test keeps the printed text within this
/// set.
fn code_page(character: char) -> Option<u8> {
Some(match character {
'ä' => 0x84,
@@ -414,6 +381,7 @@ fn code_page(character: char) -> Option<u8> {
'Ö' => 0x99,
'Ü' => 0x9A,
'ß' => 0xE1,
'·' => 0xFA,
ascii if ascii.is_ascii() => ascii as u8,
_ => return None,
})
@@ -456,7 +424,7 @@ fn first_quote() -> usize {
% QUOTES.len()
}
fn footer(head: &Head, stamp: &str, quote: &[&str; 2]) -> Vec<u8> {
fn footer(head: &Head, stamp: &str, quote: &[&str]) -> Vec<u8> {
let mut write = centered(head);
write.extend([0x1B, b'd', 1]);
write.extend(LARGE);
@@ -466,8 +434,9 @@ fn footer(head: &Head, stamp: &str, quote: &[&str; 2]) -> Vec<u8> {
write.extend([0x1B, b'd', 1]);
text_line(&mut write, stamp);
write.extend([0x1B, b'd', 1]);
text_line(&mut write, quote[0]);
text_line(&mut write, quote[1]);
for line in quote {
text_line(&mut write, line);
}
write.extend([0x1B, b'd', FEED_LINES]); // ESC d n: feed n lines
write.extend([0x1D, b'V', 66, 3]); // GS V 66 n: feed and partial cut
write
@@ -483,7 +452,7 @@ mod tests {
fn printed_lines() -> impl Iterator<Item = &'static str> {
[EVENT_TITLE, EVENT_PLACE, KEEPSAKE_DE, KEEPSAKE_EN, STAMP]
.into_iter()
.chain(QUOTES.iter().flatten().copied())
.chain(QUOTES.iter().flat_map(|quote| quote.iter().copied()))
}
fn contains_line(write: &[u8], line: &str) -> bool {
@@ -523,7 +492,7 @@ mod tests {
let picked: std::collections::BTreeSet<usize> =
(0..1000).map(|_| first_quote()).collect();
assert!(picked.last().is_some_and(|last| *last < QUOTES.len()));
// Not all eight on a coarse clock, but a slip must not be predictable.
// Not all of them on a coarse clock, but a slip must not be predictable.
assert!(picked.len() > 1, "{picked:?}");
}