feat: load printer configuration from .env

Configure the 80 mm thermal printer (576 dots) via a committed .env file,
loaded at startup with dotenvy. Real environment variables take precedence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bankosegger
2026-11-11 15:00:03 +01:00
parent eae81bb052
commit a2b83744db
5 changed files with 27 additions and 1 deletions

10
.env Normal file
View File

@@ -0,0 +1,10 @@
# Photobooth configuration, loaded from the directory the app is started from.
# Variables already set in the environment (e.g. by systemd) take precedence.
# Thermal printer (ESC/POS). Remove or leave empty to disable printing.
# A device path for USB/serial printers, or tcp://host[:port] for network
# printers (port defaults to 9100).
PHOTOBOOTH_PRINTER=/dev/usb/lp0
# Printable width in dots: 576 for 80 mm paper (384 for 58 mm).
PHOTOBOOTH_PRINTER_DOTS=576

7
Cargo.lock generated
View File

@@ -991,6 +991,12 @@ dependencies = [
"litrs",
]
[[package]]
name = "dotenvy"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "downcast-rs"
version = "1.2.1"
@@ -5444,6 +5450,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
name = "winf-photobooth-app"
version = "0.1.0"
dependencies = [
"dotenvy",
"opencv",
"slint",
"slint-build",

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
dotenvy = "0.15.7"
opencv = "0.101.1"
slint = {
version = "1.18.1",

View File

@@ -35,6 +35,13 @@ struct PreviewFrame {
}
fn main() -> Result<(), Box<dyn Error>> {
// Load `.env` before any thread starts, since it sets process variables.
// Values already present in the real environment take precedence.
match dotenvy::dotenv() {
Ok(path) => eprintln!("[config INFO] Loaded {}", path.display()),
Err(error) if error.not_found() => {}
Err(error) => eprintln!("[config ERROR] Could not load .env: {error}"),
}
// One OpenCV inference thread per worker leaves CPU time for the camera/UI
// on the dual-core kiosk instead of each model spawning two busy threads.
core::set_num_threads(1)?;

View File

@@ -1,6 +1,7 @@
//! ESC/POS thermal printing for captured photos.
//!
//! Configuration (environment variables, read once at startup):
//! Configuration (environment variables or the committed `.env`; read once at
//! startup):
//! - `PHOTOBOOTH_PRINTER`: where to send print data. Either a device path such as
//! `/dev/usb/lp0` (USB printer class) or a raw network printer as
//! `tcp://host[:port]` (port defaults to 9100). Printing is disabled when unset.