From 5800d86543ad98303f2db9412dafeed2fc0cf8fc Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:43:21 -0700 Subject: [PATCH] fix(pdi-scanner): use a smaller USB buffer in development (#5551) Closes #5541 --- libs/pdi-scanner/build.rs | 13 +++++++++++++ libs/pdi-scanner/src/rust/scanner.rs | 7 +++++++ 2 files changed, 20 insertions(+) create mode 100644 libs/pdi-scanner/build.rs diff --git a/libs/pdi-scanner/build.rs b/libs/pdi-scanner/build.rs new file mode 100644 index 0000000000..82485b39be --- /dev/null +++ b/libs/pdi-scanner/build.rs @@ -0,0 +1,13 @@ +fn main() { + println!("cargo::rustc-check-cfg=cfg(production)"); + println!("cargo:rerun-if-env-changed=NODE_ENV"); + + let is_production = match std::env::var("NODE_ENV") { + Ok(env) => env == "production", + Err(_) => false, + }; + + if is_production { + println!("cargo:rustc-cfg=production"); + } +} diff --git a/libs/pdi-scanner/src/rust/scanner.rs b/libs/pdi-scanner/src/rust/scanner.rs index e5cc5221c4..5b8d4755c5 100644 --- a/libs/pdi-scanner/src/rust/scanner.rs +++ b/libs/pdi-scanner/src/rust/scanner.rs @@ -82,8 +82,15 @@ impl Scanner { /// bit trying to catch the paper, we might need a bit more. So for any /// reasonable paper size, 4 MB should be plenty and doesn't really put /// a dent in available memory. + #[cfg(production)] const BUFFER_SIZE: usize = 4_194_304; + /// For development, we want a smaller buffer because, for reasons we + /// don't understand, communicating with the scanner times out with a + /// larger buffer. + #[cfg(not(production))] + const BUFFER_SIZE: usize = 16_384; + let (host_to_scanner_tx, host_to_scanner_rx) = mpsc::channel::<(usize, packets::Outgoing)>(); let (host_to_scanner_ack_tx, host_to_scanner_ack_rx) = mpsc::channel::();