escpos_rust/printer/
printer_model.rs

1use super::{PrinterProfile};
2use crate::{PrinterConnectionData, command::Font};
3
4/// Printers known to this library
5///
6/// Probably needs updates. If you know one that is not in the list, send them to the author through email to be considered in future updates.
7pub enum PrinterModel {
8    /// ZKTeco mini printer
9    ZKTeco,
10    /// Epson most used printer
11    TMT20
12}
13
14impl PrinterModel {
15    /// Get the vendor, product id and endpoint of the current model
16    pub fn vp_id(&self) -> (u16, u16, Option<u8>) {
17        match self {
18            PrinterModel::ZKTeco => (0x6868, 0x0200, Some(0x02)),
19            PrinterModel::TMT20 => (0x04b8, 0x0e15, Some(0x01))
20        }
21    }
22
23    /// Obtain the details to connect to a printer model through usb
24    pub fn usb_profile(&self) -> PrinterProfile {
25        let (vendor_id, product_id, endpoint) = self.vp_id();
26        match self {
27            PrinterModel::ZKTeco => {
28                PrinterProfile {
29                    printer_connection_data: PrinterConnectionData::Usb {
30                        vendor_id,
31                        product_id,
32                        endpoint,
33                        timeout: std::time::Duration::from_secs(2)
34                    },
35                    columns_per_font: vec![(Font::FontA, 32), (Font::FontB, 42)].into_iter().collect(),
36                    width: 384
37                }
38            },
39            PrinterModel::TMT20 => {
40                PrinterProfile {
41                    printer_connection_data: PrinterConnectionData::Usb {
42                        vendor_id,
43                        product_id,
44                        endpoint,
45                        timeout: std::time::Duration::from_secs(2)
46                    },
47                    columns_per_font: vec![(Font::FontA, 48)].into_iter().collect(),
48                    width: 576
49                }
50            }
51        }
52    }
53}