From 93e884d740662739e9f71dd14ca94f8e460788b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20R=C3=BCth?= Date: Mon, 13 May 2024 20:50:12 +0200 Subject: [PATCH] Card scanning check is optional As reported in #8, it seems that card scanning is not available on all scanners. This change makes it optional and simply returns no card scanning when the feature seems to not be available. --- es2button/src/listener.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/es2button/src/listener.rs b/es2button/src/listener.rs index 0e2b50f..7a9b466 100644 --- a/es2button/src/listener.rs +++ b/es2button/src/listener.rs @@ -74,9 +74,20 @@ impl<'a> Listener<'a> { self.scanner .get_bool_value_for_key(es2command::ESKEY_DOCUMENT_LOADED) } + fn is_card_scanning(&self) -> Result { - self.scanner + match self + .scanner .get_bool_value_for_key(es2command::ESKEY_CARD_SCANNING) + { + // Not all scanners support card scanning, in this case, + // we get a InvalidParameter, we just report this as no card scanning + Err(ESError::InvalidParameter) => { + trace!("Got InvalidParameter for \"cardScanning\" lookup, assuming no card scanning available"); + Ok(false) + } + x => x, + } } fn handle_button_press(&self, button: u8) -> Result<(), anyhow::Error> {