device_envoy_core/rfid.rs
1//! A device abstraction support module for RFID readers.
2//!
3//! See [`Rfid`] for the trait-based API, and use platform crates
4//! (`device_envoy-rp` or `device_envoy-esp`) for hardware-specific constructors/examples.
5
6/// Events received from an RFID reader.
7#[derive(Debug, Clone, Copy, Eq, PartialEq)]
8#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9pub enum RfidEvent {
10 /// A card was detected with a 10-byte UID value.
11 CardDetected {
12 /// UID bytes, padded with zeros if the physical UID is shorter than 10 bytes.
13 uid: [u8; 10],
14 },
15}
16
17/// Platform-agnostic RFID reader contract.
18///
19/// Platform crates implement this for concrete `Rfid` types so shared logic can
20/// await card-tap events without depending on platform-specific modules.
21///
22/// # Example
23///
24/// ```rust,no_run
25/// use device_envoy_core::rfid::{Rfid, RfidEvent};
26///
27/// async fn log_card_taps(rfid: &impl Rfid) -> ! {
28/// loop {
29/// let RfidEvent::CardDetected { uid } = rfid.wait_for_tap().await;
30/// let _ = uid;
31/// }
32/// }
33///
34/// # struct DemoRfid;
35/// # impl Rfid for DemoRfid {
36/// # async fn wait_for_tap(&self) -> RfidEvent {
37/// # RfidEvent::CardDetected { uid: [0; 10] }
38/// # }
39/// # }
40/// # fn main() {
41/// # let rfid = DemoRfid;
42/// # let _future = log_card_taps(&rfid);
43/// # }
44/// ```
45#[allow(async_fn_in_trait)]
46pub trait Rfid {
47 /// Wait for the next RFID event.
48 ///
49 /// See the [Rfid trait documentation](Self) for usage examples.
50 async fn wait_for_tap(&self) -> RfidEvent;
51}