|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (c) 2020 Tony DiCola, Grzegorz Nowicki |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | + |
| 23 | +""" |
| 24 | +`adafruit_thermal_printer.thermal_printer_2168.ThermalPrinter` |
| 25 | +============================================================== |
| 26 | +
|
| 27 | +Thermal printer control module built to work with small serial thermal |
| 28 | +receipt printers. Note that these printers have many different firmware |
| 29 | +versions and care must be taken to select the appropriate module inside this |
| 30 | +package for your firmware printer: |
| 31 | +
|
| 32 | +* thermal_printer_2168 = Printers with firmware version 2.168+. |
| 33 | +* thermal_printer = The latest printers with firmware version 2.68 up to 2.168 |
| 34 | +* thermal_printer_264 = Printers with firmware version 2.64 up to 2.68. |
| 35 | +* thermal_printer_legacy = Printers with firmware version before 2.64. |
| 36 | +
|
| 37 | +* Author(s): Tony DiCola, Grzegorz Nowicki |
| 38 | +""" |
| 39 | + |
| 40 | + |
| 41 | +import adafruit_thermal_printer.thermal_printer as thermal_printer |
| 42 | + |
| 43 | + |
| 44 | +# pylint: disable=too-many-arguments |
| 45 | +class ThermalPrinter(thermal_printer.ThermalPrinter): |
| 46 | + """Thermal printer for printers with firmware version from 2.168""" |
| 47 | + |
| 48 | + # Barcode types. These vary based on the firmware version so are made |
| 49 | + # as class-level variables that users can reference (i.e. |
| 50 | + # ThermalPrinter.UPC_A, etc) and write code that is independent of the |
| 51 | + # printer firmware version. |
| 52 | + UPC_A = 65 |
| 53 | + UPC_E = 66 |
| 54 | + EAN13 = 67 |
| 55 | + EAN8 = 68 |
| 56 | + CODE39 = 69 |
| 57 | + ITF = 70 |
| 58 | + CODABAR = 71 |
| 59 | + CODE93 = 72 |
| 60 | + CODE128 = 73 |
| 61 | + |
| 62 | + def __init__( |
| 63 | + self, |
| 64 | + uart, |
| 65 | + byte_delay_s=0.00057346, |
| 66 | + dot_feed_s=0.0021, |
| 67 | + dot_print_s=0.03, |
| 68 | + auto_warm_up=True, |
| 69 | + ): |
| 70 | + """Thermal printer class. Requires a serial UART connection with at |
| 71 | + least the TX pin connected. Take care connecting RX as the printer |
| 72 | + will output a 5V signal which can damage boards! If RX is unconnected |
| 73 | + the only loss in functionality is the has_paper function, all other |
| 74 | + printer functions will continue to work. The byte_delay_s, dot_feed_s, |
| 75 | + and dot_print_s values are delays which are used to prevent overloading |
| 76 | + the printer with data. Use the default delays unless you fully |
| 77 | + understand the workings of the printer and how delays, baud rate, |
| 78 | + number of dots, heat time, etc. relate to each other. |
| 79 | + """ |
| 80 | + super().__init__( |
| 81 | + uart, |
| 82 | + byte_delay_s=byte_delay_s, |
| 83 | + dot_feed_s=dot_feed_s, |
| 84 | + dot_print_s=dot_print_s, |
| 85 | + auto_warm_up=auto_warm_up, |
| 86 | + ) |
| 87 | + |
| 88 | + def warm_up(self, heat_time=120): |
| 89 | + """Apparently there are no parameters for setting darkness in 2.168 |
| 90 | + (at least commands from 2.68 dont work), So it is little |
| 91 | + compatibility method to reuse older code. |
| 92 | + """ |
| 93 | + self._set_timeout(0.5) # Half second delay for printer to initialize. |
| 94 | + self.reset() |
0 commit comments