Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 47ea9d5

Browse files
authored
Merge pull request #20 from greg-elmi/master
Added support for CSN A2L with firmware 2.168
2 parents dab20b3 + e3db283 commit 47ea9d5

File tree

5 files changed

+129
-10
lines changed

5 files changed

+129
-10
lines changed

adafruit_thermal_printer/__init__.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ def get_printer_class(version):
2929
assert version is not None
3030
assert version >= 0.0
3131
# pylint: disable=import-outside-toplevel
32-
if version < 2.64:
33-
import adafruit_thermal_printer.thermal_printer_legacy as thermal_printer
34-
elif version < 2.68:
32+
33+
# I reversed order of checking the version
34+
35+
# TODO the legacy printer should be a base class for all newer printer. It'll make it easier
36+
# to upgrade the library with newer firmware
37+
if version >= 2.168:
38+
import adafruit_thermal_printer.thermal_printer_2168 as thermal_printer
39+
elif version >= 2.68:
40+
import adafruit_thermal_printer.thermal_printer as thermal_printer
41+
elif version >= 2.64:
3542
import adafruit_thermal_printer.thermal_printer_264 as thermal_printer
3643
else:
37-
import adafruit_thermal_printer.thermal_printer as thermal_printer
44+
import adafruit_thermal_printer.thermal_printer_legacy as thermal_printer
45+
3846
# pylint: enable=import-outside-toplevel
3947
return thermal_printer.ThermalPrinter

adafruit_thermal_printer/thermal_printer.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
# else it will be very easy to break or introduce subtle incompatibilities with
103103
# older firmware printers.
104104
class ThermalPrinter:
105-
"""Thermal printer for printers with firmware version 2.68 or higher."""
105+
"""Thermal printer for printers with firmware version from 2.68 and below 2.168"""
106106

107107
# Barcode types. These vary based on the firmware version so are made
108108
# as class-level variables that users can reference (i.e.
@@ -180,6 +180,7 @@ def __init__(
180180
self._char_height = 24
181181
self._line_spacing = 6
182182
self._barcode_height = 50
183+
self.up_down_mode = True
183184
# pylint: disable=line-too-long
184185
# Byte delay calculated based on assumption of 19200 baud.
185186
# From Arduino library code, see formula here:
@@ -387,6 +388,9 @@ def set_defaults(self):
387388
self.underline = None
388389
self.inverse = False
389390
self.upside_down = False
391+
# this should work in 2.68 according to user manual v 4.0
392+
# but it does't work with 2.168 hence i implemented the below
393+
self.up_down_mode = True
390394
self.double_height = False
391395
self.double_width = False
392396
self.strike = False
@@ -487,7 +491,19 @@ def _set_inverse(self, inverse):
487491
)
488492
# pylint: enable=line-too-long
489493

490-
upside_down = _PrintModeBit(_UPDOWN_MASK)
494+
def _set_up_down_mode(self, up_down_mode):
495+
if up_down_mode:
496+
self.send_command("\x1B{\x01")
497+
498+
else:
499+
self.send_command("\x1B{\x00")
500+
501+
up_down_mode = property(
502+
None, _set_up_down_mode, None, "Turns on/off upside-down printing mode"
503+
)
504+
# The above Should work in 2.68 so its here and not in 2.168 module
505+
506+
upside_down = _PrintModeBit(_UPDOWN_MASK) # Don't work in 2.168 hence the above
491507

492508
double_height = _PrintModeBit(_DOUBLE_HEIGHT_MASK)
493509

@@ -522,8 +538,7 @@ def offline(self):
522538
self.send_command("\x1B=\x00") # ESC + '=' + 0
523539

524540
def online(self):
525-
"""Put the printer into an online state after previously put offline.
526-
"""
541+
"""Put the printer into an online state after previously put offline."""
527542
self.send_command("\x1B=\x01") # ESC + '=' + 1
528543

529544
def has_paper(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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()

adafruit_thermal_printer/thermal_printer_264.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
versions and care must be taken to select the appropriate module inside this
2929
package for your firmware printer:
3030
31-
* thermal_printer = The latest printers with firmware version 2.68+
31+
* thermal_printer_2168 = Printers with firmware version 2.168+.
32+
* thermal_printer = The latest printers with firmware version 2.68 up to 2.168
3233
* thermal_printer_264 = Printers with firmware version 2.64 up to 2.68.
3334
* thermal_printer_legacy = Printers with firmware version before 2.64.
3435

adafruit_thermal_printer/thermal_printer_legacy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
versions and care must be taken to select the appropriate module inside this
2929
package for your firmware printer:
3030
31-
* thermal_printer = The latest printers with firmware version 2.68+
31+
* thermal_printer_2168 = Printers with firmware version 2.168+.
32+
* thermal_printer = The latest printers with firmware version 2.68 up to 2.168
3233
* thermal_printer_264 = Printers with firmware version 2.64 up to 2.68.
3334
* thermal_printer_legacy = Printers with firmware version before 2.64.
3435

0 commit comments

Comments
 (0)