bnr_xfs/
intermediate_event.rs

1use std::fmt;
2
3use crate::impl_xfs_enum;
4
5const INTERMEDIATE_CDR_OFFSET: u32 = 6140;
6const CDR_INPUT_REFUSED: u32 = 6209;
7const CDR_SUBCASHIN: u32 = INTERMEDIATE_CDR_OFFSET;
8const CDR_BCC_INSERTED: u32 = INTERMEDIATE_CDR_OFFSET + 1;
9const CDR_NOT_SUPPORTED: u32 = u32::MAX;
10
11/// Cash Module intermediate event.
12#[repr(u32)]
13#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
14pub enum IntermediateEvent {
15    /// Input refused.
16    InputRefused = CDR_INPUT_REFUSED,
17    /// A bill has been recognized during a cash in transaction, but the amount requested has not been reached yet.
18    #[default]
19    SubCashIn = CDR_SUBCASHIN,
20    /// A coupon with barcode has been inserted and recognized during a cash in transaction, the BNR then waits for a [`set_recognition_result()`](crate::DeviceHandle::set_recognition_result) call.
21    BccInserted = CDR_BCC_INSERTED,
22    /// Unsupported [IntermediateEvent] number.
23    NotSupported = CDR_NOT_SUPPORTED,
24}
25
26impl IntermediateEvent {
27    /// Creates a new [IntermediateEvent].
28    pub const fn new() -> Self {
29        Self::SubCashIn
30    }
31
32    /// Creates a new [IntermediateEvent] from the provided parameter.
33    pub const fn create(val: u32) -> Self {
34        match val {
35            CDR_INPUT_REFUSED => Self::InputRefused,
36            CDR_SUBCASHIN => Self::SubCashIn,
37            CDR_BCC_INSERTED => Self::BccInserted,
38            _ => Self::NotSupported,
39        }
40    }
41}
42
43impl From<&IntermediateEvent> for &'static str {
44    fn from(val: &IntermediateEvent) -> Self {
45        match val {
46            IntermediateEvent::InputRefused => "input refused",
47            IntermediateEvent::SubCashIn => "sub cash in",
48            IntermediateEvent::BccInserted => "BCC inserted",
49            IntermediateEvent::NotSupported => "not supported",
50        }
51    }
52}
53
54impl fmt::Display for IntermediateEvent {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        write!(f, r#""{}""#, <&str>::from(self))
57    }
58}
59
60impl_xfs_enum!(IntermediateEvent, "intermediateEvent");