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" name = "winf-photobooth-app"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"dotenvy", "dotenvy",
"opencv", "opencv",
"slint", "slint",

View File

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

View File

@@ -23,8 +23,10 @@
//! unless the printer is known to understand them. They are sent with every //! 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). //! 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 //! 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 //! 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 //! 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. //! `Treitlstrasse` is spelled out rather than risking a mangled sharp s.
//! //!
@@ -43,6 +45,7 @@ use std::{
time::Duration, time::Duration,
}; };
use chrono::Local;
use opencv::{ use opencv::{
core::{self, Mat, Size}, core::{self, Mat, Size},
imgproc, imgproc,
@@ -69,6 +72,8 @@ const EVENT_TITLE: &str = "WINFNACHTEN";
const EVENT_PLACE: &str = "WINF Treitlstrasse 3"; const EVENT_PLACE: &str = "WINF Treitlstrasse 3";
const KEEPSAKE_DE: &str = "Ich war dabei!"; const KEEPSAKE_DE: &str = "Ich war dabei!";
const KEEPSAKE_EN: &str = "I was there!"; 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) /// Pause between writes, leaving the head time to drain a band (8 mm of paper)
/// before the next one arrives. /// before the next one arrives.
const PACE: Duration = Duration::from_millis(100); const PACE: Duration = Duration::from_millis(100);
@@ -204,7 +209,8 @@ impl Printer {
} }
let bitmap = let bitmap =
render(frame, self.dots, self.gamma).map_err(|error| format!("render: {error}"))?; 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. /// 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: /// 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 /// 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. /// 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(); let mut job = Vec::new();
for _ in 0..copies { for _ in 0..copies {
job.push(header(head)); job.push(header(head));
@@ -349,7 +355,7 @@ fn encode(bitmap: &Bitmap, head: &Head, copies: usize) -> Vec<Vec<u8>> {
write.extend(band); write.extend(band);
job.push(write); job.push(write);
} }
job.push(footer(head)); job.push(footer(head, stamp));
} }
job job
} }
@@ -376,13 +382,15 @@ fn header(head: &Head) -> Vec<u8> {
write write
} }
fn footer(head: &Head) -> Vec<u8> { fn footer(head: &Head, stamp: &str) -> Vec<u8> {
let mut write = centered(head); let mut write = centered(head);
write.extend([0x1B, b'd', 1]); write.extend([0x1B, b'd', 1]);
write.extend(LARGE); write.extend(LARGE);
write.extend(format!("{KEEPSAKE_DE}\n").as_bytes()); write.extend(format!("{KEEPSAKE_DE}\n").as_bytes());
write.extend(SMALL); write.extend(SMALL);
write.extend(format!("{KEEPSAKE_EN}\n").as_bytes()); 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([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.extend([0x1D, b'V', 66, 3]); // GS V 66 n: feed and partial cut
write write
@@ -392,6 +400,8 @@ fn footer(head: &Head) -> Vec<u8> {
mod tests { mod tests {
use super::*; use super::*;
const STAMP: &str = "14.11.2026, 15:42";
#[test] #[test]
fn parses_device_and_network_targets() { fn parses_device_and_network_targets() {
assert_eq!(Target::parse(" "), None); assert_eq!(Target::parse(" "), None);
@@ -451,7 +461,7 @@ mod tests {
width_bytes: 1, width_bytes: 1,
data: vec![0; BAND_ROWS + 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] { for band in &job[1..3] {
assert_eq!( assert_eq!(
&band[..12], &band[..12],
@@ -491,7 +501,7 @@ mod tests {
width_bytes: 2, width_bytes: 2,
data: vec![0xAA; 2 * (BAND_ROWS + 1)], 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. // Per copy: the caption, a full band, the leftover row, then the footer.
assert_eq!(job.len(), 2 * 4); assert_eq!(job.len(), 2 * 4);
for copy in job.chunks(4) { for copy in job.chunks(4) {
@@ -515,16 +525,20 @@ mod tests {
width_bytes: 1, width_bytes: 1,
data: vec![0; 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 let text: Vec<String> = job
.iter() .iter()
.map(|write| String::from_utf8_lossy(write).into_owned()) .map(|write| String::from_utf8_lossy(write).into_owned())
.collect(); .collect();
assert!(text[0].contains(EVENT_TITLE) && text[0].contains(EVENT_PLACE)); 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(KEEPSAKE_DE) && text[2].contains(KEEPSAKE_EN));
assert!(text[2].contains(STAMP));
// The captions are ASCII, so no code page has to be selected. // The captions are ASCII, so no code page has to be selected.
assert!(header(&Head::default()).iter().all(u8::is_ascii)); 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 let cuts = job
.iter() .iter()
.filter(|write| write.ends_with(&[0x1D, b'V', 66, 3])) .filter(|write| write.ends_with(&[0x1D, b'V', 66, 3]))
@@ -535,3 +549,4 @@ mod tests {