feat: print the capture date and time under the keepsake line

This commit is contained in:
bankosegger
2026-11-14 15:38:36 +01:00
parent 181a0512bd
commit f406b36c5f
3 changed files with 27 additions and 10 deletions

1
Cargo.lock generated
View File

@@ -5450,6 +5450,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
name = "winf-photobooth-app"
version = "0.1.0"
dependencies = [
"chrono",
"dotenvy",
"opencv",
"slint",

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
chrono = { version = "0.4.45", default-features = false, features = ["clock", "std"] }
dotenvy = "0.15.7"
opencv = "0.101.1"
slint = {

View File

@@ -23,8 +23,10 @@
//! unless the printer is known to understand them. They are sent with every
//! band and are not stored by the printer (no memory switch writes).
//!
//! Each photo is captioned with the event name and place above it and a
//! keepsake line below, in German with the English directly underneath. The
//! Each photo is captioned with the event name and place above it, and a
//! keepsake line plus the capture date and time below it, in German with the
//! English directly underneath. The timestamp is the system clock in local
//! time, so the booth's clock has to be right for it to mean anything. The
//! captions are ASCII only: the printer's code page is not configured here, so
//! `Treitlstrasse` is spelled out rather than risking a mangled sharp s.
//!
@@ -43,6 +45,7 @@ use std::{
time::Duration,
};
use chrono::Local;
use opencv::{
core::{self, Mat, Size},
imgproc,
@@ -69,6 +72,8 @@ const EVENT_TITLE: &str = "WINFNACHTEN";
const EVENT_PLACE: &str = "WINF Treitlstrasse 3";
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";
/// 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);
@@ -204,7 +209,8 @@ impl Printer {
}
let bitmap =
render(frame, self.dots, self.gamma).map_err(|error| format!("render: {error}"))?;
self.send(&encode(&bitmap, &self.head, copies))
let stamp = Local::now().format(STAMP_FORMAT).to_string();
self.send(&encode(&bitmap, &self.head, copies, &stamp))
}
/// Sends the job one write at a time, pacing them to the print head.
@@ -335,7 +341,7 @@ fn dither(gray: &[u8], width: usize, rows: usize) -> Vec<u8> {
/// tested Birch 0CP-Q3 only keeps sync when `GS v 0` follows `ESC @` directly:
/// given several bands in one initialized stream it abandons the image and
/// prints the remaining dot data as text, about two metres of it per photo.
fn encode(bitmap: &Bitmap, head: &Head, copies: usize) -> Vec<Vec<u8>> {
fn encode(bitmap: &Bitmap, head: &Head, copies: usize, stamp: &str) -> Vec<Vec<u8>> {
let mut job = Vec::new();
for _ in 0..copies {
job.push(header(head));
@@ -349,7 +355,7 @@ fn encode(bitmap: &Bitmap, head: &Head, copies: usize) -> Vec<Vec<u8>> {
write.extend(band);
job.push(write);
}
job.push(footer(head));
job.push(footer(head, stamp));
}
job
}
@@ -376,13 +382,15 @@ fn header(head: &Head) -> Vec<u8> {
write
}
fn footer(head: &Head) -> Vec<u8> {
fn footer(head: &Head, stamp: &str) -> Vec<u8> {
let mut write = centered(head);
write.extend([0x1B, b'd', 1]);
write.extend(LARGE);
write.extend(format!("{KEEPSAKE_DE}\n").as_bytes());
write.extend(SMALL);
write.extend(format!("{KEEPSAKE_EN}\n").as_bytes());
write.extend([0x1B, b'd', 1]);
write.extend(format!("{stamp}\n").as_bytes());
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
@@ -392,6 +400,8 @@ fn footer(head: &Head) -> Vec<u8> {
mod tests {
use super::*;
const STAMP: &str = "14.11.2026, 15:42";
#[test]
fn parses_device_and_network_targets() {
assert_eq!(Target::parse(" "), None);
@@ -451,7 +461,7 @@ mod tests {
width_bytes: 1,
data: vec![0; BAND_ROWS + 1],
};
let job = encode(&bitmap, &Head::from_values(Some("85"), Some("quality")), 1);
let job = encode(&bitmap, &Head::from_values(Some("85"), Some("quality")), 1, STAMP);
for band in &job[1..3] {
assert_eq!(
&band[..12],
@@ -491,7 +501,7 @@ mod tests {
width_bytes: 2,
data: vec![0xAA; 2 * (BAND_ROWS + 1)],
};
let job = encode(&bitmap, &Head::default(), 2);
let job = encode(&bitmap, &Head::default(), 2, STAMP);
// Per copy: the caption, a full band, the leftover row, then the footer.
assert_eq!(job.len(), 2 * 4);
for copy in job.chunks(4) {
@@ -515,16 +525,20 @@ mod tests {
width_bytes: 1,
data: vec![0; 1],
};
let job = encode(&bitmap, &Head::default(), 2);
let job = encode(&bitmap, &Head::default(), 2, STAMP);
let text: Vec<String> = job
.iter()
.map(|write| String::from_utf8_lossy(write).into_owned())
.collect();
assert!(text[0].contains(EVENT_TITLE) && text[0].contains(EVENT_PLACE));
assert!(text[2].contains(KEEPSAKE_DE) && text[2].contains(KEEPSAKE_EN));
assert!(text[2].contains(STAMP));
// The captions are ASCII, so no code page has to be selected.
assert!(header(&Head::default()).iter().all(u8::is_ascii));
assert!(footer(&Head::default()).iter().all(u8::is_ascii));
assert!(footer(&Head::default(), STAMP).iter().all(u8::is_ascii));
// The real stamp is ASCII too.
let now = Local::now().format(STAMP_FORMAT).to_string();
assert!(now.is_ascii() && now.len() == STAMP.len(), "{now}");
let cuts = job
.iter()
.filter(|write| write.ends_with(&[0x1D, b'V', 66, 3]))
@@ -535,3 +549,4 @@ mod tests {