waveshare_barcodescanner/lib.rs
1use std::fmt::Display;
2
3pub mod crc;
4pub mod interface;
5
6// indicates, that the checksum was not calculated (checksum will not be validated)
7pub const IGNORED_CHECKSUM: u16 = 0xabcd;
8
9/// target light mode to indicate scanning
10pub enum TargetLightMode {
11 /// target light is disabled
12 AlwaysOff,
13 /// target light is always on (also when not scanning)
14 AlwaysOn,
15 /// target light is on during scanning
16 Standard,
17}
18
19/// light mode for object detection in dark environments
20pub enum IlluminationMode {
21 /// white LED is disabled (scanning in dark environments might be difficult)
22 AlwaysOff,
23 /// white LED is always on (also when not scanning)
24 AlwaysOn,
25 /// white LED is on during scanning
26 Standard,
27}
28
29/// scanner mode operation
30pub enum OperationMode {
31 /// push button to scan
32 Manual,
33 /// send command to scan
34 Command,
35 /// continuous scanning
36 Continuous,
37 /// detect ambient brightness change and start scanning
38 Sensing,
39}
40
41/// scan area for bar codes
42pub enum ScanArea {
43 /// the entire area of view of the camera is used to detect barcodes
44 All,
45 /// the center area (default 20%) of the camera is used to detect barcodes
46 Center,
47}
48
49/// type of barcodes to enable/disable (device dependent)
50pub enum Barcodes {
51 /// enable all supported barcodes
52 EnableAll,
53 /// disable all barcodes
54 DisableAll,
55 /// enable all default barcodes
56 Default,
57}
58
59/// scanned barcode
60pub enum Barcode {
61 /// Interleaved 2of5, single line of digits
62 Interleaved2of5(String),
63 /// International Article Number - EAN13, single line of digits
64 EAN13(String),
65 /// Code 128, single line of alphanumeric characters
66 Code128(String),
67 /// Code 39, single line of alphanumeric characters
68 Code39(String),
69 /// QR code, multiple lines of alphanumeric characters
70 QR(Vec<String>),
71 /// mini QR code, multiple lines of alphanumeric characters
72 MicroQR(Vec<String>),
73 /// Dot Matrix code, multiple lines of alphanumeric characters
74 DotMatrix(Vec<String>),
75}
76
77impl Display for Barcode {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 match self {
80 Barcode::Interleaved2of5(data) => write!(f, "interleaved2of5: {}", data),
81 Barcode::EAN13(data) => write!(f, "EAN13: {}", data),
82 Barcode::Code39(data) => write!(f, "Code39: {}", data),
83 Barcode::Code128(data) => write!(f, "Code128: {}", data),
84 Barcode::QR(data) => write!(
85 f,
86 "QR: {}",
87 data.iter()
88 .enumerate()
89 .map(|(i, line)| format!("{}: {}", i, line))
90 .collect::<Vec<String>>()
91 .join("\n")
92 ),
93 Barcode::MicroQR(data) => write!(
94 f,
95 "Micro QR: {}",
96 data.iter()
97 .enumerate()
98 .map(|(i, line)| format!("{}: {}", i, line))
99 .collect::<Vec<String>>()
100 .join("\n")
101 ),
102 Barcode::DotMatrix(data) => write!(
103 f,
104 "Dot Matrix: {}",
105 data.iter()
106 .enumerate()
107 .map(|(i, line)| format!("{}: {}", i, line))
108 .collect::<Vec<String>>()
109 .join("\n")
110 ),
111 }
112 }
113}