├── .github ├── PULL_REQUEST_TEMPLATE │ └── adafruit_circuitpython_pr.md └── workflows │ ├── build.yml │ ├── failure-help-text.yml │ ├── release_gh.yml │ └── release_pypi.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .pylintrc ├── .readthedocs.yaml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── LICENSES ├── CC-BY-4.0.txt ├── MIT.txt └── Unlicense.txt ├── README.rst ├── README.rst.license ├── adafruit_thermal_printer ├── __init__.py ├── thermal_printer.py ├── thermal_printer_2168.py ├── thermal_printer_264.py └── thermal_printer_legacy.py ├── docs ├── _static │ ├── favicon.ico │ └── favicon.ico.license ├── api.rst ├── api.rst.license ├── conf.py ├── examples.rst ├── examples.rst.license ├── index.rst ├── index.rst.license └── requirements.txt ├── examples └── thermal_printer_simpletest.py ├── optional_requirements.txt ├── pyproject.toml └── requirements.txt /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Diego Elio Pettenò 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/python/black 7 | rev: 23.3.0 8 | hooks: 9 | - id: black 10 | - repo: https://github.com/fsfe/reuse-tool 11 | rev: v1.1.2 12 | hooks: 13 | - id: reuse 14 | - repo: https://github.com/pre-commit/pre-commit-hooks 15 | rev: v4.4.0 16 | hooks: 17 | - id: check-yaml 18 | - id: end-of-file-fixer 19 | - id: trailing-whitespace 20 | - repo: https://github.com/pycqa/pylint 21 | rev: v2.17.4 22 | hooks: 23 | - id: pylint 24 | name: pylint (library code) 25 | types: [python] 26 | args: 27 | - --disable=consider-using-f-string,duplicate-code 28 | exclude: "^(docs/|examples/|tests/|setup.py$)" 29 | - id: pylint 30 | name: pylint (example code) 31 | description: Run pylint rules on "examples/*.py" files 32 | types: [python] 33 | files: "^examples/" 34 | args: 35 | - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code 36 | - id: pylint 37 | name: pylint (test code) 38 | description: Run pylint rules on "tests/*.py" files 39 | types: [python] 40 | files: "^tests/" 41 | args: 42 | - --disable=missing-docstring,consider-using-f-string,duplicate-code 43 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | [MASTER] 6 | 7 | # A comma-separated list of package or module names from where C extensions may 8 | # be loaded. Extensions are loading into the active Python interpreter and may 9 | # run arbitrary code 10 | extension-pkg-whitelist= 11 | 12 | # Add files or directories to the ignore-list. They should be base names, not 13 | # paths. 14 | ignore=CVS 15 | 16 | # Add files or directories matching the regex patterns to the ignore-list. The 17 | # regex matches against base names, not paths. 18 | ignore-patterns= 19 | 20 | # Python code to execute, usually for sys.path manipulation such as 21 | # pygtk.require(). 22 | #init-hook= 23 | 24 | # Use multiple processes to speed up Pylint. 25 | jobs=1 26 | 27 | # List of plugins (as comma separated values of python modules names) to load, 28 | # usually to register additional checkers. 29 | load-plugins=pylint.extensions.no_self_use 30 | 31 | # Pickle collected data for later comparisons. 32 | persistent=yes 33 | 34 | # Specify a configuration file. 35 | #rcfile= 36 | 37 | # Allow loading of arbitrary C extensions. Extensions are imported into the 38 | # active Python interpreter and may run arbitrary code. 39 | unsafe-load-any-extension=no 40 | 41 | 42 | [MESSAGES CONTROL] 43 | 44 | # Only show warnings with the listed confidence levels. Leave empty to show 45 | # all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED 46 | confidence= 47 | 48 | # Disable the message, report, category or checker with the given id(s). You 49 | # can either give multiple identifiers separated by comma (,) or put this 50 | # option multiple times (only on the command line, not in the configuration 51 | # file where it should appear only once).You can also use "--disable=all" to 52 | # disable everything first and then reenable specific checks. For example, if 53 | # you want to run only the similarities checker, you can use "--disable=all 54 | # --enable=similarities". If you want to run only the classes checker, but have 55 | # no Warning level messages displayed, use"--disable=all --enable=classes 56 | # --disable=W" 57 | # disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call 58 | disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding 59 | 60 | # Enable the message, report, category or checker with the given id(s). You can 61 | # either give multiple identifier separated by comma (,) or put this option 62 | # multiple time (only on the command line, not in the configuration file where 63 | # it should appear only once). See also the "--disable" option for examples. 64 | enable= 65 | 66 | 67 | [REPORTS] 68 | 69 | # Python expression which should return a note less than 10 (10 is the highest 70 | # note). You have access to the variables errors warning, statement which 71 | # respectively contain the number of errors / warnings messages and the total 72 | # number of statements analyzed. This is used by the global evaluation report 73 | # (RP0004). 74 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 75 | 76 | # Template used to display messages. This is a python new-style format string 77 | # used to format the message information. See doc for all details 78 | #msg-template= 79 | 80 | # Set the output format. Available formats are text, parseable, colorized, json 81 | # and msvs (visual studio).You can also give a reporter class, eg 82 | # mypackage.mymodule.MyReporterClass. 83 | output-format=text 84 | 85 | # Tells whether to display a full report or only the messages 86 | reports=no 87 | 88 | # Activate the evaluation score. 89 | score=yes 90 | 91 | 92 | [REFACTORING] 93 | 94 | # Maximum number of nested blocks for function / method body 95 | max-nested-blocks=5 96 | 97 | 98 | [LOGGING] 99 | 100 | # Logging modules to check that the string format arguments are in logging 101 | # function parameter format 102 | logging-modules=logging 103 | 104 | 105 | [SPELLING] 106 | 107 | # Spelling dictionary name. Available dictionaries: none. To make it working 108 | # install python-enchant package. 109 | spelling-dict= 110 | 111 | # List of comma separated words that should not be checked. 112 | spelling-ignore-words= 113 | 114 | # A path to a file that contains private dictionary; one word per line. 115 | spelling-private-dict-file= 116 | 117 | # Tells whether to store unknown words to indicated private dictionary in 118 | # --spelling-private-dict-file option instead of raising a message. 119 | spelling-store-unknown-words=no 120 | 121 | 122 | [MISCELLANEOUS] 123 | 124 | # List of note tags to take in consideration, separated by a comma. 125 | # notes=FIXME,XXX,TODO 126 | notes=FIXME,XXX 127 | 128 | 129 | [TYPECHECK] 130 | 131 | # List of decorators that produce context managers, such as 132 | # contextlib.contextmanager. Add to this list to register other decorators that 133 | # produce valid context managers. 134 | contextmanager-decorators=contextlib.contextmanager 135 | 136 | # List of members which are set dynamically and missed by pylint inference 137 | # system, and so shouldn't trigger E1101 when accessed. Python regular 138 | # expressions are accepted. 139 | generated-members= 140 | 141 | # Tells whether missing members accessed in mixin class should be ignored. A 142 | # mixin class is detected if its name ends with "mixin" (case insensitive). 143 | ignore-mixin-members=yes 144 | 145 | # This flag controls whether pylint should warn about no-member and similar 146 | # checks whenever an opaque object is returned when inferring. The inference 147 | # can return multiple potential results while evaluating a Python object, but 148 | # some branches might not be evaluated, which results in partial inference. In 149 | # that case, it might be useful to still emit no-member and other checks for 150 | # the rest of the inferred objects. 151 | ignore-on-opaque-inference=yes 152 | 153 | # List of class names for which member attributes should not be checked (useful 154 | # for classes with dynamically set attributes). This supports the use of 155 | # qualified names. 156 | ignored-classes=optparse.Values,thread._local,_thread._local 157 | 158 | # List of module names for which member attributes should not be checked 159 | # (useful for modules/projects where namespaces are manipulated during runtime 160 | # and thus existing member attributes cannot be deduced by static analysis. It 161 | # supports qualified module names, as well as Unix pattern matching. 162 | ignored-modules=board 163 | 164 | # Show a hint with possible names when a member name was not found. The aspect 165 | # of finding the hint is based on edit distance. 166 | missing-member-hint=yes 167 | 168 | # The minimum edit distance a name should have in order to be considered a 169 | # similar match for a missing member name. 170 | missing-member-hint-distance=1 171 | 172 | # The total number of similar names that should be taken in consideration when 173 | # showing a hint for a missing member. 174 | missing-member-max-choices=1 175 | 176 | 177 | [VARIABLES] 178 | 179 | # List of additional names supposed to be defined in builtins. Remember that 180 | # you should avoid to define new builtins when possible. 181 | additional-builtins= 182 | 183 | # Tells whether unused global variables should be treated as a violation. 184 | allow-global-unused-variables=yes 185 | 186 | # List of strings which can identify a callback function by name. A callback 187 | # name must start or end with one of those strings. 188 | callbacks=cb_,_cb 189 | 190 | # A regular expression matching the name of dummy variables (i.e. expectedly 191 | # not used). 192 | dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ 193 | 194 | # Argument names that match this expression will be ignored. Default to name 195 | # with leading underscore 196 | ignored-argument-names=_.*|^ignored_|^unused_ 197 | 198 | # Tells whether we should check for unused import in __init__ files. 199 | init-import=no 200 | 201 | # List of qualified module names which can have objects that can redefine 202 | # builtins. 203 | redefining-builtins-modules=six.moves,future.builtins 204 | 205 | 206 | [FORMAT] 207 | 208 | # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. 209 | # expected-line-ending-format= 210 | expected-line-ending-format=LF 211 | 212 | # Regexp for a line that is allowed to be longer than the limit. 213 | ignore-long-lines=^\s*(# )??$ 214 | 215 | # Number of spaces of indent required inside a hanging or continued line. 216 | indent-after-paren=4 217 | 218 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 219 | # tab). 220 | indent-string=' ' 221 | 222 | # Maximum number of characters on a single line. 223 | max-line-length=100 224 | 225 | # Maximum number of lines in a module 226 | max-module-lines=1000 227 | 228 | # Allow the body of a class to be on the same line as the declaration if body 229 | # contains single statement. 230 | single-line-class-stmt=no 231 | 232 | # Allow the body of an if to be on the same line as the test if there is no 233 | # else. 234 | single-line-if-stmt=no 235 | 236 | 237 | [SIMILARITIES] 238 | 239 | # Ignore comments when computing similarities. 240 | ignore-comments=yes 241 | 242 | # Ignore docstrings when computing similarities. 243 | ignore-docstrings=yes 244 | 245 | # Ignore imports when computing similarities. 246 | ignore-imports=yes 247 | 248 | # Minimum lines number of a similarity. 249 | min-similarity-lines=12 250 | 251 | 252 | [BASIC] 253 | 254 | # Regular expression matching correct argument names 255 | argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 256 | 257 | # Regular expression matching correct attribute names 258 | attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 259 | 260 | # Bad variable names which should always be refused, separated by a comma 261 | bad-names=foo,bar,baz,toto,tutu,tata 262 | 263 | # Regular expression matching correct class attribute names 264 | class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 265 | 266 | # Regular expression matching correct class names 267 | # class-rgx=[A-Z_][a-zA-Z0-9]+$ 268 | class-rgx=[A-Z_][a-zA-Z0-9_]+$ 269 | 270 | # Regular expression matching correct constant names 271 | const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 272 | 273 | # Minimum line length for functions/classes that require docstrings, shorter 274 | # ones are exempt. 275 | docstring-min-length=-1 276 | 277 | # Regular expression matching correct function names 278 | function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 279 | 280 | # Good variable names which should always be accepted, separated by a comma 281 | # good-names=i,j,k,ex,Run,_ 282 | good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ 283 | 284 | # Include a hint for the correct naming format with invalid-name 285 | include-naming-hint=no 286 | 287 | # Regular expression matching correct inline iteration names 288 | inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ 289 | 290 | # Regular expression matching correct method names 291 | method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 292 | 293 | # Regular expression matching correct module names 294 | module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 295 | 296 | # Colon-delimited sets of names that determine each other's naming style when 297 | # the name regexes allow several styles. 298 | name-group= 299 | 300 | # Regular expression which should only match function or class names that do 301 | # not require a docstring. 302 | no-docstring-rgx=^_ 303 | 304 | # List of decorators that produce properties, such as abc.abstractproperty. Add 305 | # to this list to register other decorators that produce valid properties. 306 | property-classes=abc.abstractproperty 307 | 308 | # Regular expression matching correct variable names 309 | variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 310 | 311 | 312 | [IMPORTS] 313 | 314 | # Allow wildcard imports from modules that define __all__. 315 | allow-wildcard-with-all=no 316 | 317 | # Analyse import fallback blocks. This can be used to support both Python 2 and 318 | # 3 compatible code, which means that the block might have code that exists 319 | # only in one or another interpreter, leading to false positives when analysed. 320 | analyse-fallback-blocks=no 321 | 322 | # Deprecated modules which should not be used, separated by a comma 323 | deprecated-modules=optparse,tkinter.tix 324 | 325 | # Create a graph of external dependencies in the given file (report RP0402 must 326 | # not be disabled) 327 | ext-import-graph= 328 | 329 | # Create a graph of every (i.e. internal and external) dependencies in the 330 | # given file (report RP0402 must not be disabled) 331 | import-graph= 332 | 333 | # Create a graph of internal dependencies in the given file (report RP0402 must 334 | # not be disabled) 335 | int-import-graph= 336 | 337 | # Force import order to recognize a module as part of the standard 338 | # compatibility libraries. 339 | known-standard-library= 340 | 341 | # Force import order to recognize a module as part of a third party library. 342 | known-third-party=enchant 343 | 344 | 345 | [CLASSES] 346 | 347 | # List of method names used to declare (i.e. assign) instance attributes. 348 | defining-attr-methods=__init__,__new__,setUp 349 | 350 | # List of member names, which should be excluded from the protected access 351 | # warning. 352 | exclude-protected=_asdict,_fields,_replace,_source,_make 353 | 354 | # List of valid names for the first argument in a class method. 355 | valid-classmethod-first-arg=cls 356 | 357 | # List of valid names for the first argument in a metaclass class method. 358 | valid-metaclass-classmethod-first-arg=mcs 359 | 360 | 361 | [DESIGN] 362 | 363 | # Maximum number of arguments for function / method 364 | max-args=5 365 | 366 | # Maximum number of attributes for a class (see R0902). 367 | # max-attributes=7 368 | max-attributes=11 369 | 370 | # Maximum number of boolean expressions in a if statement 371 | max-bool-expr=5 372 | 373 | # Maximum number of branch for function / method body 374 | max-branches=12 375 | 376 | # Maximum number of locals for function / method body 377 | max-locals=15 378 | 379 | # Maximum number of parents for a class (see R0901). 380 | max-parents=7 381 | 382 | # Maximum number of public methods for a class (see R0904). 383 | max-public-methods=20 384 | 385 | # Maximum number of return / yield for function / method body 386 | max-returns=6 387 | 388 | # Maximum number of statements in function / method body 389 | max-statements=50 390 | 391 | # Minimum number of public methods for a class (see R0903). 392 | min-public-methods=1 393 | 394 | 395 | [EXCEPTIONS] 396 | 397 | # Exceptions that will emit a warning when being caught. Defaults to 398 | # "Exception" 399 | overgeneral-exceptions=Exception 400 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | build: 12 | os: ubuntu-20.04 13 | tools: 14 | python: "3" 15 | 16 | python: 17 | install: 18 | - requirements: docs/requirements.txt 19 | - requirements: requirements.txt 20 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Tony DiCola for Adafruit Industries 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International Creative Commons Corporation 2 | ("Creative Commons") is not a law firm and does not provide legal services 3 | or legal advice. Distribution of Creative Commons public licenses does not 4 | create a lawyer-client or other relationship. Creative Commons makes its licenses 5 | and related information available on an "as-is" basis. Creative Commons gives 6 | no warranties regarding its licenses, any material licensed under their terms 7 | and conditions, or any related information. Creative Commons disclaims all 8 | liability for damages resulting from their use to the fullest extent possible. 9 | 10 | Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions 13 | that creators and other rights holders may use to share original works of 14 | authorship and other material subject to copyright and certain other rights 15 | specified in the public license below. The following considerations are for 16 | informational purposes only, are not exhaustive, and do not form part of our 17 | licenses. 18 | 19 | Considerations for licensors: Our public licenses are intended for use by 20 | those authorized to give the public permission to use material in ways otherwise 21 | restricted by copyright and certain other rights. Our licenses are irrevocable. 22 | Licensors should read and understand the terms and conditions of the license 23 | they choose before applying it. Licensors should also secure all rights necessary 24 | before applying our licenses so that the public can reuse the material as 25 | expected. Licensors should clearly mark any material not subject to the license. 26 | This includes other CC-licensed material, or material used under an exception 27 | or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors 28 | 29 | Considerations for the public: By using one of our public licenses, a licensor 30 | grants the public permission to use the licensed material under specified 31 | terms and conditions. If the licensor's permission is not necessary for any 32 | reason–for example, because of any applicable exception or limitation to copyright–then 33 | that use is not regulated by the license. Our licenses grant only permissions 34 | under copyright and certain other rights that a licensor has authority to 35 | grant. Use of the licensed material may still be restricted for other reasons, 36 | including because others have copyright or other rights in the material. A 37 | licensor may make special requests, such as asking that all changes be marked 38 | or described. Although not required by our licenses, you are encouraged to 39 | respect those requests where reasonable. More considerations for the public 40 | : wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution 41 | 4.0 International Public License 42 | 43 | By exercising the Licensed Rights (defined below), You accept and agree to 44 | be bound by the terms and conditions of this Creative Commons Attribution 45 | 4.0 International Public License ("Public License"). To the extent this Public 46 | License may be interpreted as a contract, You are granted the Licensed Rights 47 | in consideration of Your acceptance of these terms and conditions, and the 48 | Licensor grants You such rights in consideration of benefits the Licensor 49 | receives from making the Licensed Material available under these terms and 50 | conditions. 51 | 52 | Section 1 – Definitions. 53 | 54 | a. Adapted Material means material subject to Copyright and Similar Rights 55 | that is derived from or based upon the Licensed Material and in which the 56 | Licensed Material is translated, altered, arranged, transformed, or otherwise 57 | modified in a manner requiring permission under the Copyright and Similar 58 | Rights held by the Licensor. For purposes of this Public License, where the 59 | Licensed Material is a musical work, performance, or sound recording, Adapted 60 | Material is always produced where the Licensed Material is synched in timed 61 | relation with a moving image. 62 | 63 | b. Adapter's License means the license You apply to Your Copyright and Similar 64 | Rights in Your contributions to Adapted Material in accordance with the terms 65 | and conditions of this Public License. 66 | 67 | c. Copyright and Similar Rights means copyright and/or similar rights closely 68 | related to copyright including, without limitation, performance, broadcast, 69 | sound recording, and Sui Generis Database Rights, without regard to how the 70 | rights are labeled or categorized. For purposes of this Public License, the 71 | rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 72 | 73 | d. Effective Technological Measures means those measures that, in the absence 74 | of proper authority, may not be circumvented under laws fulfilling obligations 75 | under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, 76 | and/or similar international agreements. 77 | 78 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other 79 | exception or limitation to Copyright and Similar Rights that applies to Your 80 | use of the Licensed Material. 81 | 82 | f. Licensed Material means the artistic or literary work, database, or other 83 | material to which the Licensor applied this Public License. 84 | 85 | g. Licensed Rights means the rights granted to You subject to the terms and 86 | conditions of this Public License, which are limited to all Copyright and 87 | Similar Rights that apply to Your use of the Licensed Material and that the 88 | Licensor has authority to license. 89 | 90 | h. Licensor means the individual(s) or entity(ies) granting rights under this 91 | Public License. 92 | 93 | i. Share means to provide material to the public by any means or process that 94 | requires permission under the Licensed Rights, such as reproduction, public 95 | display, public performance, distribution, dissemination, communication, or 96 | importation, and to make material available to the public including in ways 97 | that members of the public may access the material from a place and at a time 98 | individually chosen by them. 99 | 100 | j. Sui Generis Database Rights means rights other than copyright resulting 101 | from Directive 96/9/EC of the European Parliament and of the Council of 11 102 | March 1996 on the legal protection of databases, as amended and/or succeeded, 103 | as well as other essentially equivalent rights anywhere in the world. 104 | 105 | k. You means the individual or entity exercising the Licensed Rights under 106 | this Public License. Your has a corresponding meaning. 107 | 108 | Section 2 – Scope. 109 | 110 | a. License grant. 111 | 112 | 1. Subject to the terms and conditions of this Public License, the Licensor 113 | hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, 114 | irrevocable license to exercise the Licensed Rights in the Licensed Material 115 | to: 116 | 117 | A. reproduce and Share the Licensed Material, in whole or in part; and 118 | 119 | B. produce, reproduce, and Share Adapted Material. 120 | 121 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions 122 | and Limitations apply to Your use, this Public License does not apply, and 123 | You do not need to comply with its terms and conditions. 124 | 125 | 3. Term. The term of this Public License is specified in Section 6(a). 126 | 127 | 4. Media and formats; technical modifications allowed. The Licensor authorizes 128 | You to exercise the Licensed Rights in all media and formats whether now known 129 | or hereafter created, and to make technical modifications necessary to do 130 | so. The Licensor waives and/or agrees not to assert any right or authority 131 | to forbid You from making technical modifications necessary to exercise the 132 | Licensed Rights, including technical modifications necessary to circumvent 133 | Effective Technological Measures. For purposes of this Public License, simply 134 | making modifications authorized by this Section 2(a)(4) never produces Adapted 135 | Material. 136 | 137 | 5. Downstream recipients. 138 | 139 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed 140 | Material automatically receives an offer from the Licensor to exercise the 141 | Licensed Rights under the terms and conditions of this Public License. 142 | 143 | B. No downstream restrictions. You may not offer or impose any additional 144 | or different terms or conditions on, or apply any Effective Technological 145 | Measures to, the Licensed Material if doing so restricts exercise of the Licensed 146 | Rights by any recipient of the Licensed Material. 147 | 148 | 6. No endorsement. Nothing in this Public License constitutes or may be construed 149 | as permission to assert or imply that You are, or that Your use of the Licensed 150 | Material is, connected with, or sponsored, endorsed, or granted official status 151 | by, the Licensor or others designated to receive attribution as provided in 152 | Section 3(a)(1)(A)(i). 153 | 154 | b. Other rights. 155 | 156 | 1. Moral rights, such as the right of integrity, are not licensed under this 157 | Public License, nor are publicity, privacy, and/or other similar personality 158 | rights; however, to the extent possible, the Licensor waives and/or agrees 159 | not to assert any such rights held by the Licensor to the limited extent necessary 160 | to allow You to exercise the Licensed Rights, but not otherwise. 161 | 162 | 2. Patent and trademark rights are not licensed under this Public License. 163 | 164 | 3. To the extent possible, the Licensor waives any right to collect royalties 165 | from You for the exercise of the Licensed Rights, whether directly or through 166 | a collecting society under any voluntary or waivable statutory or compulsory 167 | licensing scheme. In all other cases the Licensor expressly reserves any right 168 | to collect such royalties. 169 | 170 | Section 3 – License Conditions. 171 | 172 | Your exercise of the Licensed Rights is expressly made subject to the following 173 | conditions. 174 | 175 | a. Attribution. 176 | 177 | 1. If You Share the Licensed Material (including in modified form), You must: 178 | 179 | A. retain the following if it is supplied by the Licensor with the Licensed 180 | Material: 181 | 182 | i. identification of the creator(s) of the Licensed Material and any others 183 | designated to receive attribution, in any reasonable manner requested by the 184 | Licensor (including by pseudonym if designated); 185 | 186 | ii. a copyright notice; 187 | 188 | iii. a notice that refers to this Public License; 189 | 190 | iv. a notice that refers to the disclaimer of warranties; 191 | 192 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 193 | 194 | B. indicate if You modified the Licensed Material and retain an indication 195 | of any previous modifications; and 196 | 197 | C. indicate the Licensed Material is licensed under this Public License, and 198 | include the text of, or the URI or hyperlink to, this Public License. 199 | 200 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner 201 | based on the medium, means, and context in which You Share the Licensed Material. 202 | For example, it may be reasonable to satisfy the conditions by providing a 203 | URI or hyperlink to a resource that includes the required information. 204 | 205 | 3. If requested by the Licensor, You must remove any of the information required 206 | by Section 3(a)(1)(A) to the extent reasonably practicable. 207 | 208 | 4. If You Share Adapted Material You produce, the Adapter's License You apply 209 | must not prevent recipients of the Adapted Material from complying with this 210 | Public License. 211 | 212 | Section 4 – Sui Generis Database Rights. 213 | 214 | Where the Licensed Rights include Sui Generis Database Rights that apply to 215 | Your use of the Licensed Material: 216 | 217 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, 218 | reuse, reproduce, and Share all or a substantial portion of the contents of 219 | the database; 220 | 221 | b. if You include all or a substantial portion of the database contents in 222 | a database in which You have Sui Generis Database Rights, then the database 223 | in which You have Sui Generis Database Rights (but not its individual contents) 224 | is Adapted Material; and 225 | 226 | c. You must comply with the conditions in Section 3(a) if You Share all or 227 | a substantial portion of the contents of the database. 228 | 229 | For the avoidance of doubt, this Section 4 supplements and does not replace 230 | Your obligations under this Public License where the Licensed Rights include 231 | other Copyright and Similar Rights. 232 | 233 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 234 | 235 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, 236 | the Licensor offers the Licensed Material as-is and as-available, and makes 237 | no representations or warranties of any kind concerning the Licensed Material, 238 | whether express, implied, statutory, or other. This includes, without limitation, 239 | warranties of title, merchantability, fitness for a particular purpose, non-infringement, 240 | absence of latent or other defects, accuracy, or the presence or absence of 241 | errors, whether or not known or discoverable. Where disclaimers of warranties 242 | are not allowed in full or in part, this disclaimer may not apply to You. 243 | 244 | b. To the extent possible, in no event will the Licensor be liable to You 245 | on any legal theory (including, without limitation, negligence) or otherwise 246 | for any direct, special, indirect, incidental, consequential, punitive, exemplary, 247 | or other losses, costs, expenses, or damages arising out of this Public License 248 | or use of the Licensed Material, even if the Licensor has been advised of 249 | the possibility of such losses, costs, expenses, or damages. Where a limitation 250 | of liability is not allowed in full or in part, this limitation may not apply 251 | to You. 252 | 253 | c. The disclaimer of warranties and limitation of liability provided above 254 | shall be interpreted in a manner that, to the extent possible, most closely 255 | approximates an absolute disclaimer and waiver of all liability. 256 | 257 | Section 6 – Term and Termination. 258 | 259 | a. This Public License applies for the term of the Copyright and Similar Rights 260 | licensed here. However, if You fail to comply with this Public License, then 261 | Your rights under this Public License terminate automatically. 262 | 263 | b. Where Your right to use the Licensed Material has terminated under Section 264 | 6(a), it reinstates: 265 | 266 | 1. automatically as of the date the violation is cured, provided it is cured 267 | within 30 days of Your discovery of the violation; or 268 | 269 | 2. upon express reinstatement by the Licensor. 270 | 271 | c. For the avoidance of doubt, this Section 6(b) does not affect any right 272 | the Licensor may have to seek remedies for Your violations of this Public 273 | License. 274 | 275 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material 276 | under separate terms or conditions or stop distributing the Licensed Material 277 | at any time; however, doing so will not terminate this Public License. 278 | 279 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 280 | 281 | Section 7 – Other Terms and Conditions. 282 | 283 | a. The Licensor shall not be bound by any additional or different terms or 284 | conditions communicated by You unless expressly agreed. 285 | 286 | b. Any arrangements, understandings, or agreements regarding the Licensed 287 | Material not stated herein are separate from and independent of the terms 288 | and conditions of this Public License. 289 | 290 | Section 8 – Interpretation. 291 | 292 | a. For the avoidance of doubt, this Public License does not, and shall not 293 | be interpreted to, reduce, limit, restrict, or impose conditions on any use 294 | of the Licensed Material that could lawfully be made without permission under 295 | this Public License. 296 | 297 | b. To the extent possible, if any provision of this Public License is deemed 298 | unenforceable, it shall be automatically reformed to the minimum extent necessary 299 | to make it enforceable. If the provision cannot be reformed, it shall be severed 300 | from this Public License without affecting the enforceability of the remaining 301 | terms and conditions. 302 | 303 | c. No term or condition of this Public License will be waived and no failure 304 | to comply consented to unless expressly agreed to by the Licensor. 305 | 306 | d. Nothing in this Public License constitutes or may be interpreted as a limitation 307 | upon, or waiver of, any privileges and immunities that apply to the Licensor 308 | or You, including from the legal processes of any jurisdiction or authority. 309 | 310 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative 311 | Commons may elect to apply one of its public licenses to material it publishes 312 | and in those instances will be considered the "Licensor." The text of the 313 | Creative Commons public licenses is dedicated to the public domain under the 314 | CC0 Public Domain Dedication. Except for the limited purpose of indicating 315 | that material is shared under a Creative Commons public license or as otherwise 316 | permitted by the Creative Commons policies published at creativecommons.org/policies, 317 | Creative Commons does not authorize the use of the trademark "Creative Commons" 318 | or any other trademark or logo of Creative Commons without its prior written 319 | consent including, without limitation, in connection with any unauthorized 320 | modifications to any of its public licenses or any other arrangements, understandings, 321 | or agreements concerning use of licensed material. For the avoidance of doubt, 322 | this paragraph does not form part of the public licenses. 323 | 324 | Creative Commons may be contacted at creativecommons.org. 325 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and successors. We intend this dedication to 11 | be an overt act of relinquishment in perpetuity of all present and future 12 | rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 19 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, 20 | please refer to 21 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | This library is archived and no longer supported 2 | ============================================= 3 | 4 | Introduction 5 | ============ 6 | 7 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-thermal-printer/badge/?version=latest 8 | :target: https://docs.circuitpython.org/projects/thermal_printer/en/latest/ 9 | :alt: Documentation Status 10 | 11 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 12 | :target: https://adafru.it/discord 13 | :alt: Discord 14 | 15 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer/workflows/Build%20CI/badge.svg 16 | :target: https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer/actions/ 17 | :alt: Build Status 18 | 19 | .. image:: https://img.shields.io/badge/code%20style-black-000000.svg 20 | :target: https://github.com/psf/black 21 | :alt: Code Style: Black 22 | 23 | CircuitPython module for control of various small serial thermal printers. 24 | 25 | Dependencies 26 | ============= 27 | This driver depends on: 28 | 29 | * `Adafruit CircuitPython `_ 30 | 31 | Please ensure all dependencies are available on the CircuitPython filesystem. 32 | This is easily achieved by downloading 33 | `the Adafruit library and driver bundle `_. 34 | 35 | Installing from PyPI 36 | ==================== 37 | 38 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 39 | PyPI `_. To install for current user: 40 | 41 | .. code-block:: shell 42 | 43 | pip3 install adafruit-circuitpython-thermal_printer 44 | 45 | To install system-wide (this may be required in some cases): 46 | 47 | .. code-block:: shell 48 | 49 | sudo pip3 install adafruit-circuitpython-thermal_printer 50 | 51 | To install in a virtual environment in your current project: 52 | 53 | .. code-block:: shell 54 | 55 | mkdir project-name && cd project-name 56 | python3 -m venv .venv 57 | source .venv/bin/activate 58 | pip3 install adafruit-circuitpython-thermal_printer 59 | 60 | Usage Example 61 | ============= 62 | 63 | See examples/thermal_printer_simpletest.py for a demo of basic printer usage. 64 | 65 | Documentation 66 | ============= 67 | 68 | API documentation for this library can be found on `Read the Docs `_. 69 | 70 | For information on building library documentation, please check out `this guide `_. 71 | 72 | Contributing 73 | ============ 74 | 75 | Contributions are welcome! Please read our `Code of Conduct 76 | `_ 77 | before contributing to help this project stay welcoming. 78 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_thermal_printer/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_thermal_printer.thermal_printer_legacy.__init__` 7 | ================================================================= 8 | 9 | Init function for the thermal printer library. 10 | 11 | * Author(s): Tony DiCola 12 | """ 13 | 14 | from adafruit_thermal_printer.thermal_printer import ( 15 | JUSTIFY_LEFT, 16 | JUSTIFY_CENTER, 17 | JUSTIFY_RIGHT, 18 | SIZE_SMALL, 19 | SIZE_MEDIUM, 20 | SIZE_LARGE, 21 | UNDERLINE_THIN, 22 | UNDERLINE_THICK, 23 | ) 24 | 25 | 26 | def get_printer_class(version): 27 | """Retrieve the class to construct for an instance of the specified 28 | thermal printer version. Pass in the printer firmware version as a numeric 29 | value like 2.68, 2.64, etc. You can get this value by holding the button 30 | on the printer as it powers on and a test page is printed--look at the 31 | bottom of the test page for the version number. 32 | """ 33 | assert version is not None 34 | assert version >= 0.0 35 | # pylint: disable=import-outside-toplevel 36 | 37 | # I reversed order of checking the version 38 | 39 | # TODO the legacy printer should be a base class for all newer printer. It'll make it easier 40 | # to upgrade the library with newer firmware 41 | if version >= 2.168: 42 | import adafruit_thermal_printer.thermal_printer_2168 as thermal_printer 43 | elif version >= 2.68: 44 | from adafruit_thermal_printer import thermal_printer 45 | elif version >= 2.64: 46 | import adafruit_thermal_printer.thermal_printer_264 as thermal_printer 47 | else: 48 | import adafruit_thermal_printer.thermal_printer_legacy as thermal_printer 49 | 50 | # pylint: enable=import-outside-toplevel 51 | return thermal_printer.ThermalPrinter 52 | -------------------------------------------------------------------------------- /adafruit_thermal_printer/thermal_printer.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_thermal_printer.thermal_printer` - Thermal Printer Driver 7 | ===================================================================== 8 | 9 | Thermal printer control module built to work with small serial thermal 10 | receipt printers. Note that these printers have many different firmware 11 | versions and care must be taken to select the appropriate module inside this 12 | package for your firmware printer: 13 | 14 | * thermal_printer = The latest printers with firmware version 2.68+ 15 | * thermal_printer_264 = Printers with firmware version 2.64 up to 2.68. 16 | * thermal_printer_legacy = Printers with firmware version before 2.64. 17 | 18 | * Author(s): Tony DiCola 19 | 20 | Implementation Notes 21 | -------------------- 22 | 23 | **Hardware:** 24 | 25 | * Mini `Thermal Receipt Printer 26 | `_ (Product ID: 597) 27 | 28 | **Software and Dependencies:** 29 | 30 | * Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: 31 | https://github.com/adafruit/circuitpython/releases 32 | 33 | """ 34 | import time 35 | 36 | from micropython import const 37 | 38 | try: 39 | from typing import Optional, Type 40 | from typing_extensions import Literal 41 | from circuitpython_typing import ReadableBuffer 42 | from busio import UART 43 | except ImportError: 44 | pass 45 | 46 | __version__ = "0.0.0+auto.0" 47 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer.git" 48 | 49 | 50 | # Internally used constants. 51 | _UPDOWN_MASK = const(1 << 2) 52 | _BOLD_MASK = const(1 << 3) 53 | _DOUBLE_HEIGHT_MASK = const(1 << 4) 54 | _DOUBLE_WIDTH_MASK = const(1 << 5) 55 | _STRIKE_MASK = const(1 << 6) 56 | 57 | # External constants: 58 | JUSTIFY_LEFT = const(0) 59 | JUSTIFY_CENTER = const(1) 60 | JUSTIFY_RIGHT = const(2) 61 | SIZE_SMALL = const(0) 62 | SIZE_MEDIUM = const(1) 63 | SIZE_LARGE = const(2) 64 | UNDERLINE_THIN = const(0) 65 | UNDERLINE_THICK = const(1) 66 | 67 | 68 | # Disable too many instance members warning. This is not something pylint can 69 | # reasonably infer--the complexity of instance variables is required for proper 70 | # printer function. Disable this warning. 71 | # pylint: disable=too-many-instance-attributes 72 | 73 | # Disable too many public members warning. Again this is not something pylint 74 | # can reasonably decide. Thermal printers require lots of control functions. 75 | # Disable this warning. 76 | # pylint: disable=too-many-public-methods 77 | 78 | 79 | # Thermal printer class for printers with firmware version 2.68 and higher. 80 | # Do not modify this class without fully understanding its coupling to the 81 | # legacy and 2.64+ version printer which inherit from it. These legacy printer 82 | # classes override specific functions which have different requirements of 83 | # behavior between different versions of printer firmware. Firmware printers 84 | # vary _greatly_ in their command set--there is not a clean abstraction. The 85 | # assumption here is that this class is the master with logic for the most 86 | # recent (2.68+) firmware printers. Older firmware versions inherit and 87 | # override behavior where necessary. It is highly, HIGHLY recommended you 88 | # carefully study the Arduino thermal printer library code and fully 89 | # understand all the firmware differences (notice where the library changes 90 | # behavior with the firmware version define): 91 | # https://github.com/adafruit/Adafruit-Thermal-Printer-Library 92 | # Bottom line: don't touch this code without understanding the big picture or 93 | # else it will be very easy to break or introduce subtle incompatibilities with 94 | # older firmware printers. 95 | class ThermalPrinter: 96 | """Thermal printer for printers with firmware version from 2.68 and below 2.168""" 97 | 98 | # Barcode types. These vary based on the firmware version so are made 99 | # as class-level variables that users can reference (i.e. 100 | # ThermalPrinter.UPC_A, etc) and write code that is independent of the 101 | # printer firmware version. 102 | UPC_A = 65 103 | UPC_E = 66 104 | EAN13 = 67 105 | EAN8 = 68 106 | CODE39 = 69 107 | ITF = 70 108 | CODABAR = 71 109 | CODE93 = 72 110 | CODE128 = 73 111 | 112 | class _PrintModeBit: 113 | # Internal descriptor class to simplify printer mode change properties. 114 | # This is tightly coupled to the ThermalPrinter implementation--do not 115 | # change it without fully understanding these dependencies on the 116 | # internal _set_print_mode and other methods! 117 | 118 | # pylint doesn't have the context to realize this internal class is 119 | # explicitly tightly coupled to the parent class implementation. 120 | # Therefore disable its warnings about protected access--this access 121 | # is required and by design. 122 | # pylint: disable=protected-access 123 | 124 | # Another odd pylint case, it seems to not realize this is a descriptor 125 | # which by design only implements get, set, init. As a result workaround 126 | # this pylint issue by disabling the warning. 127 | # pylint: disable=too-few-public-methods 128 | def __init__(self, mask: int) -> None: 129 | self._mask = mask 130 | 131 | def __get__( 132 | self, 133 | obj: Optional["ThermalPrinter"], 134 | objtype: Type["ThermalPrinter"], 135 | ) -> bool: 136 | return obj._print_mode & self._mask > 0 137 | 138 | def __set__(self, obj: "ThermalPrinter", val: int) -> None: 139 | if val: 140 | obj._set_print_mode(self._mask) 141 | else: 142 | obj._unset_print_mode(self._mask) 143 | 144 | # pylint: enable=protected-access 145 | # pylint: enable=too-few-public-methods 146 | 147 | def __init__( 148 | self, 149 | uart: UART, 150 | *, 151 | byte_delay_s: float = 0.00057346, 152 | dot_feed_s: float = 0.0021, 153 | dot_print_s: float = 0.03, 154 | auto_warm_up: bool = True, 155 | ) -> None: 156 | """Thermal printer class. Requires a serial UART connection with at 157 | least the TX pin connected. Take care connecting RX as the printer 158 | will output a 5V signal which can damage boards! If RX is unconnected 159 | the only loss in functionality is the has_paper function, all other 160 | printer functions will continue to work. The byte_delay_s, dot_feed_s, 161 | and dot_print_s values are delays which are used to prevent overloading 162 | the printer with data. Use the default delays unless you fully 163 | understand the workings of the printer and how delays, baud rate, 164 | number of dots, heat time, etc. relate to each other. Can set 165 | auto_warm_up to a boolean value (default True) to automatically call 166 | the warm_up function which will initialize the printer (but can take a 167 | significant amount of time, on the order 0.5-5 seconds, be warned!). 168 | """ 169 | self.max_chunk_height = 255 170 | self._resume = 0 171 | self._uart = uart 172 | self._print_mode = 0 173 | self._column = 0 174 | self._max_column = 32 175 | self._char_height = 24 176 | self._line_spacing = 6 177 | self._barcode_height = 50 178 | self.up_down_mode = True 179 | # pylint: disable=line-too-long 180 | # Byte delay calculated based on assumption of 19200 baud. 181 | # From Arduino library code, see formula here: 182 | # https://github.com/adafruit/Adafruit-Thermal-Printer-Library/blob/master/Adafruit_Thermal.cpp#L50-L53 183 | # pylint: enable=line-too-long 184 | self._byte_delay_s = byte_delay_s 185 | self._dot_feed_s = dot_feed_s 186 | self._dot_print_s = dot_print_s 187 | self.reset() 188 | if auto_warm_up: 189 | self.warm_up() 190 | 191 | def _set_timeout(self, period_s: float) -> None: 192 | # Set a timeout before future commands can be sent. 193 | self._resume = time.monotonic() + period_s 194 | 195 | def _wait_timeout(self) -> None: 196 | # Ensure the timeout that was previously set has passed (will busy wait). 197 | while time.monotonic() < self._resume: 198 | pass 199 | 200 | def _write_char(self, char: str, *, encoding: str = "utf-8") -> None: 201 | # Write a single character to the printer. 202 | if char == "\r": 203 | return # Strip carriage returns by skipping them. 204 | self._wait_timeout() 205 | self._uart.write(bytes(char, encoding)) 206 | delay = self._byte_delay_s 207 | # Add extra delay for newlines or moving past the last column. 208 | if char == "\n" or self._column == self._max_column: 209 | if self._column == 0: 210 | # Feed line delay 211 | delay += (self._char_height + self._line_spacing) * self._dot_feed_s 212 | else: 213 | # Text line delay 214 | delay += (self._char_height * self._dot_print_s) + ( 215 | self._line_spacing * self._dot_feed_s 216 | ) 217 | self._column = 0 218 | else: 219 | self._column += 1 220 | self._set_timeout(delay) 221 | 222 | def _write_print_mode(self) -> None: 223 | # Write the printer mode to the printer. 224 | self.send_command( 225 | f"\x1B!{chr(self._print_mode)}" 226 | ) # ESC + '!' + print mode byte 227 | # Adjust character height and column count based on print mode. 228 | self._char_height = 48 if self._print_mode & _DOUBLE_HEIGHT_MASK else 24 229 | self._max_column = 16 if self._print_mode & _DOUBLE_WIDTH_MASK else 32 230 | 231 | def _set_print_mode(self, mask: int) -> None: 232 | # Enable the specified bits of the print mode. 233 | self._print_mode |= mask & 0xFF 234 | self._write_print_mode() 235 | 236 | def _unset_print_mode(self, mask: int) -> None: 237 | # Disable the specified bits of the print mode. 238 | self._print_mode &= ~(mask & 0xFF) 239 | self._write_print_mode() 240 | 241 | def send_command(self, command: str) -> None: 242 | """Send a command string to the printer.""" 243 | self._uart.write(bytes(command, "ascii")) 244 | 245 | # Do initialization in warm_up instead of the initializer because this 246 | # initialization takes a long time (5 seconds) and shouldn't happen during 247 | # object creation (users need explicit control of when to start it). 248 | def warm_up(self, heat_time: int = 120) -> None: 249 | """Initialize the printer. Can specify an optional heat_time keyword 250 | to override the default heating timing of 1.2 ms. See the datasheet 251 | for details on the heating time value (duration in 10uS increments). 252 | Note that calling this function will take about half a second for the 253 | printer to intialize and warm up. 254 | """ 255 | assert 0 <= heat_time <= 255 256 | self._set_timeout(0.5) # Half second delay for printer to initialize. 257 | self.reset() 258 | # ESC 7 n1 n2 n3 Setting Control Parameter Command 259 | # n1 = "max heating dots" 0-255 -- max number of thermal print head 260 | # elements that will fire simultaneously. Units = 8 dots (minus 1). 261 | # Printer default is 7 (64 dots, or 1/6 of 384-dot width), this code 262 | # sets it to 11 (96 dots, or 1/4 of width). 263 | # n2 = "heating time" 3-255 -- duration that heating dots are fired. 264 | # Units = 10 us. Printer default is 80 (800 us), this code sets it 265 | # to value passed (default 120, or 1.2 ms -- a little longer than 266 | # the default because we've increased the max heating dots). 267 | # n3 = "heating interval" 0-255 -- recovery time between groups of 268 | # heating dots on line; possibly a function of power supply. 269 | # Units = 10 us. Printer default is 2 (20 us), this code sets it 270 | # to 40 (throttled back due to 2A supply). 271 | # More heating dots = more peak current, but faster printing speed. 272 | # More heating time = darker print, but slower printing speed and 273 | # possibly paper 'stiction'. More heating interval = clearer print, 274 | # but slower printing speed. 275 | # Send ESC + '7' (print settings) + heating dots, heat time, heat interval. 276 | self.send_command(f"\x1B7\x0B{chr(heat_time)}\x28") 277 | # Print density description from manual: 278 | # DC2 # n Set printing density 279 | # D4..D0 of n is used to set the printing density. Density is 280 | # 50% + 5% * n(D4-D0) printing density. 281 | # D7..D5 of n is used to set the printing break time. Break time 282 | # is n(D7-D5)*250us. 283 | print_density = 10 # 100% (? can go higher, text is darker but fuzzy) 284 | print_break_time = 2 # 500 uS 285 | dc2_value = (print_break_time << 5) | print_density 286 | self.send_command(f"\x12#{chr(dc2_value)}") # DC2 + '#' + value 287 | 288 | def reset(self) -> None: 289 | """Reset the printer.""" 290 | # Issue a reset command to the printer. (ESC + @) 291 | self.send_command("\x1B@") 292 | # Reset internal state: 293 | self._column = 0 294 | self._max_column = 32 295 | self._char_height = 24 296 | self._line_spacing = 6 297 | self._barcode_height = 50 298 | # Configure tab stops on recent printers. 299 | # ESC + 'D' + tab stop value list ending with null to terminate. 300 | self.send_command("\x1BD\x04\x08\x10\x14\x18\x1C\x00") 301 | 302 | def print( 303 | self, text: str, end: Optional[str] = "\n", *, encoding: str = "utf-8" 304 | ) -> None: 305 | """Print a line of text. Optionally specify the end keyword to 306 | override the new line printed after the text (set to None to disable 307 | the new line entirely). Optionally specify the encoding. Some 308 | printers only accept the more restrictive encodings "cp437" and 309 | "ascii". 310 | Note: Encodings other than "utf-8" are not accepted by 311 | microcontrollers. 312 | """ 313 | for char in text: 314 | self._write_char(char, encoding=encoding) 315 | if end is not None: 316 | self._write_char(end, encoding=encoding) 317 | 318 | def print_barcode(self, text: str, barcode_type: int) -> None: 319 | """Print a barcode with the specified text/number (the meaning 320 | varies based on the type of barcode) and type. Type is a value from 321 | the datasheet or class-level variables like UPC_A, etc. for 322 | convenience. Note the type value changes depending on the firmware 323 | version so use class-level values where possible! 324 | """ 325 | assert 0 <= barcode_type <= 255 326 | assert 0 <= len(text) <= 255 327 | self.feed(1) # Recent firmware can't print barcode w/o feed first??? 328 | self.send_command("\x1DH\x02") # Print label below barcode 329 | self.send_command("\x1Dw\x03") # Barcode width 3 (0.375/1.0mm thin/thick) 330 | self.send_command(f"\x1Dk{chr(barcode_type)}") # Barcode type 331 | # Write length and then string (note this only works with 2.64+). 332 | self.send_command(chr(len(text))) 333 | self.send_command(text) 334 | self._set_timeout((self._barcode_height + 40) * self._dot_print_s) 335 | self._column = 0 336 | 337 | def _print_bitmap(self, width: int, height: int, data: ReadableBuffer) -> None: 338 | """Print a bitmap image of the specified width, height and data bytes. 339 | Data bytes must be in 1-bit per pixel format, i.e. each byte represents 340 | 8 pixels of image data along a row of the image. You will want to 341 | pre-process your images with a script, you CANNOT send .jpg/.bmp/etc. 342 | image formats. See this Processing sketch for preprocessing: 343 | https://github.com/adafruit/Adafruit-Thermal-Printer-Library/blob/master/processing/bitmapImageConvert/bitmapImageConvert.pde 344 | 345 | .. note:: This is currently not working because it appears the bytes are 346 | sent too slowly and the printer gets confused with not enough data being 347 | sent to it in the expected time. 348 | """ 349 | assert len(data) >= (width // 8) * height 350 | row_bytes = (width + 7) // 8 # Round up to next byte boundary. 351 | row_bytes_clipped = min(row_bytes, 48) # 384 pixels max width. 352 | chunk_height_limit = 256 // row_bytes_clipped 353 | # Clip chunk height within the 1 to max range. 354 | chunk_height_limit = max(1, min(self.max_chunk_height, chunk_height_limit)) 355 | i = 0 356 | for row_start in range(0, height, chunk_height_limit): 357 | # Issue up to chunkHeightLimit rows at a time. 358 | chunk_height = min(height - row_start, chunk_height_limit) 359 | self.send_command(f"\x12*{chr(chunk_height)}{chr(row_bytes_clipped)}") 360 | for _ in range(chunk_height): 361 | for _ in range(row_bytes_clipped): 362 | # Drop down to low level UART access to avoid newline and 363 | # other bitmap values being misinterpreted. 364 | self._wait_timeout() 365 | self._uart.write(chr(data[i])) 366 | i += 1 367 | i += row_bytes - row_bytes_clipped 368 | self._set_timeout(chunk_height * self._dot_print_s) 369 | self._column = 0 370 | 371 | def test_page(self) -> None: 372 | """Print a test page.""" 373 | self.send_command("\x12T") # DC2 + 'T' for test page 374 | # Delay for 26 lines w/text (ea. 24 dots high) + 375 | # 26 text lines (feed 6 dots) + blank line 376 | self._set_timeout( 377 | self._dot_print_s * 24 * 26 + self._dot_feed_s * (6 * 26 + 30) 378 | ) 379 | 380 | def set_defaults(self) -> None: 381 | """Set default printing and text options. This is useful to reset back 382 | to a good state after printing different size, weight, etc. text. 383 | """ 384 | self.online() 385 | self.justify = JUSTIFY_LEFT 386 | self.size = SIZE_SMALL 387 | self.underline = None 388 | self.inverse = False 389 | self.upside_down = False 390 | # this should work in 2.68 according to user manual v 4.0 391 | # but it does't work with 2.168 hence i implemented the below 392 | self.up_down_mode = True 393 | self.double_height = False 394 | self.double_width = False 395 | self.strike = False 396 | self.bold = False 397 | self._set_line_height(30) 398 | self._set_barcode_height(50) 399 | self._set_charset() 400 | self._set_code_page() 401 | 402 | def _set_justify(self, val: Literal[0, 1, 2]) -> None: 403 | assert 0 <= val <= 2 404 | if val == JUSTIFY_LEFT: 405 | self.send_command("\x1Ba\x00") # ESC + 'a' + 0 406 | elif val == JUSTIFY_CENTER: 407 | self.send_command("\x1Ba\x01") # ESC + 'a' + 1 408 | elif val == JUSTIFY_RIGHT: 409 | self.send_command("\x1Ba\x02") # ESC + 'a' + 2 410 | 411 | # pylint: disable=line-too-long 412 | # Write-only property, can't assume we can read state from the printer 413 | # since there is no command for it and hooking up RX is discouraged 414 | # (5V will damage many boards). 415 | justify = property( 416 | None, 417 | _set_justify, 418 | None, 419 | "Set the justification of text, must be a value of JUSTIFY_LEFT, JUSTIFY_CENTER, or JUSTIFY_RIGHT.", 420 | ) 421 | # pylint: enable=line-too-long 422 | 423 | def _set_size(self, val: Literal[0, 1, 2]) -> None: 424 | assert 0 <= val <= 2 425 | if val == SIZE_SMALL: 426 | self._char_height = 24 427 | self._max_column = 32 428 | self.send_command("\x1D!\x00") # ASCII GS + '!' + 0x00 429 | elif val == SIZE_MEDIUM: 430 | self._char_height = 48 431 | self._max_column = 32 432 | self.send_command("\x1D!\x01") # ASCII GS + '!' + 0x01 433 | elif val == SIZE_LARGE: 434 | self._char_height = 48 435 | self._max_column = 16 436 | self.send_command("\x1D!\x11") # ASCII GS + '!' + 0x11 437 | self._column = 0 438 | 439 | # pylint: disable=line-too-long 440 | # Write-only property, can't assume we can read state from the printer 441 | # since there is no command for it and hooking up RX is discouraged 442 | # (5V will damage many boards). 443 | size = property( 444 | None, 445 | _set_size, 446 | None, 447 | "Set the size of text, must be a value of SIZE_SMALL, SIZE_MEDIUM, or SIZE_LARGE.", 448 | ) 449 | # pylint: enable=line-too-long 450 | 451 | def _set_underline(self, val: Optional[Literal[0, 1]]) -> None: 452 | assert val is None or (0 <= val <= 1) 453 | if val is None: 454 | # Turn off underline. 455 | self.send_command("\x1B-\x00") # ESC + '-' + 0 456 | elif val == UNDERLINE_THIN: 457 | self.send_command("\x1B-\x01") # ESC + '-' + 1 458 | elif val == UNDERLINE_THICK: 459 | self.send_command("\x1B-\x02") # ESC + '-' + 2 460 | 461 | # pylint: disable=line-too-long 462 | # Write-only property, can't assume we can read state from the printer 463 | # since there is no command for it and hooking up RX is discouraged 464 | # (5V will damage many boards). 465 | underline = property( 466 | None, 467 | _set_underline, 468 | None, 469 | "Set the underline state of the text, must be None (off), UNDERLINE_THIN, or UNDERLINE_THICK.", 470 | ) 471 | # pylint: enable=line-too-long 472 | 473 | def _set_inverse(self, inverse: bool) -> None: 474 | # Set the inverse printing state to enabled disabled with the specified 475 | # boolean value. This requires printer firmare 2.68+ 476 | if inverse: 477 | self.send_command("\x1DB\x01") # ESC + 'B' + 1 478 | else: 479 | self.send_command("\x1DB\x00") # ESC + 'B' + 0 480 | 481 | # pylint: disable=line-too-long 482 | # Write-only property, can't assume we can read inverse state from the 483 | # printer since there is no command for it and hooking up RX is discouraged 484 | # (5V will damage many boards). 485 | inverse = property( 486 | None, 487 | _set_inverse, 488 | None, 489 | "Set the inverse printing mode boolean to enable or disable inverse printing.", 490 | ) 491 | # pylint: enable=line-too-long 492 | 493 | def _set_up_down_mode(self, up_down_mode: bool) -> None: 494 | if up_down_mode: 495 | self.send_command("\x1B{\x01") 496 | 497 | else: 498 | self.send_command("\x1B{\x00") 499 | 500 | up_down_mode = property( 501 | None, _set_up_down_mode, None, "Turns on/off upside-down printing mode" 502 | ) 503 | # The above Should work in 2.68 so its here and not in 2.168 module 504 | 505 | upside_down = _PrintModeBit(_UPDOWN_MASK) # Don't work in 2.168 hence the above 506 | 507 | double_height = _PrintModeBit(_DOUBLE_HEIGHT_MASK) 508 | 509 | double_width = _PrintModeBit(_DOUBLE_WIDTH_MASK) 510 | 511 | strike = _PrintModeBit(_STRIKE_MASK) 512 | 513 | bold = _PrintModeBit(_BOLD_MASK) 514 | 515 | def feed(self, lines: int) -> None: 516 | """Advance paper by specified number of blank lines.""" 517 | assert 0 <= lines <= 255 518 | self.send_command(f"\x1Bd{chr(lines)}") 519 | self._set_timeout(self._dot_feed_s * self._char_height) 520 | self._column = 0 521 | 522 | def feed_rows(self, rows: int) -> None: 523 | """Advance paper by specified number of pixel rows.""" 524 | assert 0 <= rows <= 255 525 | self.send_command(f"\x1BJ{chr(rows)}") 526 | self._set_timeout(rows * self._dot_feed_s) 527 | self._column = 0 528 | 529 | def flush(self) -> None: 530 | """Flush data pending in the printer.""" 531 | self.send_command("\f") 532 | 533 | def offline(self) -> None: 534 | """Put the printer into an offline state. No other commands can be 535 | sent until an online call is made. 536 | """ 537 | self.send_command("\x1B=\x00") # ESC + '=' + 0 538 | 539 | def online(self) -> None: 540 | """Put the printer into an online state after previously put offline.""" 541 | self.send_command("\x1B=\x01") # ESC + '=' + 1 542 | 543 | def has_paper(self) -> bool: 544 | """Return a boolean indicating if the printer has paper. You MUST have 545 | the serial RX line hooked up for this to work. NOTE: be VERY CAREFUL 546 | to ensure your board can handle a 5V serial input before hooking up 547 | the RX line! 548 | """ 549 | # This only works with firmware 2.64+: 550 | self.send_command("\x1Bv\x00") # ESC + 'v' + 0 551 | status = self._uart.read(1) 552 | if status is None: 553 | return False 554 | return not status[0] & 0b00000100 555 | 556 | def _set_line_height(self, height: int) -> None: 557 | """Set the line height in pixels. This is the total amount of space 558 | between lines, including the height of text. The smallest value is 24 559 | and the largest is 255. 560 | """ 561 | assert 24 <= height <= 255 562 | self._line_spacing = height - 24 563 | self.send_command(f"\x1B3{chr(height)}") # ESC + '3' + height 564 | 565 | def _set_barcode_height(self, height: int) -> None: 566 | """Set the barcode height in pixels. Must be a value 1 - 255.""" 567 | assert 1 <= height <= 255 568 | self._barcode_height = height 569 | self.send_command(f"\x1Dh{chr(height)}") # ASCII GS + 'h' + height 570 | 571 | def _set_charset(self, charset: int = 0) -> None: 572 | """Alters the character set for ASCII characters 0x23-0x7E. See 573 | datasheet for details on character set values (0-15). Note this is only 574 | supported on more recent firmware printers! 575 | """ 576 | assert 0 <= charset <= 15 577 | self.send_command(f"\x1BR{chr(charset)}") # ESC + 'R' + charset 578 | 579 | def _set_code_page(self, code_page: int = 0) -> None: 580 | """Select alternate code page for upper ASCII symbols 0x80-0xFF. See 581 | datasheet for code page values (0 - 47). Note this is only supported 582 | on more recent firmware printers! 583 | """ 584 | assert 0 <= code_page <= 47 585 | self.send_command(f"\x1Bt{chr(code_page)}") # ESC + 't' + code page 586 | 587 | def tab(self) -> None: 588 | """Print a tab (i.e. move to next 4 character block). Note this is 589 | only supported on more recent firmware printers!""" 590 | self.send_command("\t") 591 | # Increment to the next position that's every 4 spaces. 592 | # I.e. increment by 4 and go to the floor/first position of the block. 593 | self._column = (self._column + 4) & 0b11111100 594 | -------------------------------------------------------------------------------- /adafruit_thermal_printer/thermal_printer_2168.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Tony DiCola for Adafruit Industries 2 | # SPDX-FileCopyrightText: 2020 Grzegorz Nowicki for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | `adafruit_thermal_printer.thermal_printer_2168.ThermalPrinter` 8 | ============================================================== 9 | 10 | Thermal printer control module built to work with small serial thermal 11 | receipt printers. Note that these printers have many different firmware 12 | versions and care must be taken to select the appropriate module inside this 13 | package for your firmware printer: 14 | 15 | * thermal_printer_2168 = Printers with firmware version 2.168+. 16 | * thermal_printer = The latest printers with firmware version 2.68 up to 2.168 17 | * thermal_printer_264 = Printers with firmware version 2.64 up to 2.68. 18 | * thermal_printer_legacy = Printers with firmware version before 2.64. 19 | 20 | * Author(s): Tony DiCola, Grzegorz Nowicki 21 | """ 22 | 23 | 24 | from adafruit_thermal_printer import thermal_printer 25 | 26 | try: 27 | import typing # pylint: disable=unused-import 28 | from busio import UART 29 | except ImportError: 30 | pass 31 | 32 | 33 | # pylint: disable=too-many-arguments 34 | class ThermalPrinter(thermal_printer.ThermalPrinter): 35 | """Thermal printer for printers with firmware version from 2.168""" 36 | 37 | # Barcode types. These vary based on the firmware version so are made 38 | # as class-level variables that users can reference (i.e. 39 | # ThermalPrinter.UPC_A, etc) and write code that is independent of the 40 | # printer firmware version. 41 | UPC_A = 65 42 | UPC_E = 66 43 | EAN13 = 67 44 | EAN8 = 68 45 | CODE39 = 69 46 | ITF = 70 47 | CODABAR = 71 48 | CODE93 = 72 49 | CODE128 = 73 50 | 51 | def __init__( 52 | self, 53 | uart: UART, 54 | byte_delay_s: float = 0.00057346, 55 | dot_feed_s: float = 0.0021, 56 | dot_print_s: float = 0.03, 57 | auto_warm_up: bool = True, 58 | ) -> None: 59 | """Thermal printer class. Requires a serial UART connection with at 60 | least the TX pin connected. Take care connecting RX as the printer 61 | will output a 5V signal which can damage boards! If RX is unconnected 62 | the only loss in functionality is the has_paper function, all other 63 | printer functions will continue to work. The byte_delay_s, dot_feed_s, 64 | and dot_print_s values are delays which are used to prevent overloading 65 | the printer with data. Use the default delays unless you fully 66 | understand the workings of the printer and how delays, baud rate, 67 | number of dots, heat time, etc. relate to each other. 68 | """ 69 | super().__init__( 70 | uart, 71 | byte_delay_s=byte_delay_s, 72 | dot_feed_s=dot_feed_s, 73 | dot_print_s=dot_print_s, 74 | auto_warm_up=auto_warm_up, 75 | ) 76 | 77 | def warm_up(self, heat_time: int = 120) -> None: 78 | """Apparently there are no parameters for setting darkness in 2.168 79 | (at least commands from 2.68 dont work), So it is little 80 | compatibility method to reuse older code. 81 | """ 82 | self._set_timeout(0.5) # Half second delay for printer to initialize. 83 | self.reset() 84 | -------------------------------------------------------------------------------- /adafruit_thermal_printer/thermal_printer_264.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_thermal_printer.thermal_printer_264.ThermalPrinter` 7 | ============================================================== 8 | 9 | Thermal printer control module built to work with small serial thermal 10 | receipt printers. Note that these printers have many different firmware 11 | versions and care must be taken to select the appropriate module inside this 12 | package for your firmware printer: 13 | 14 | * thermal_printer_2168 = Printers with firmware version 2.168+. 15 | * thermal_printer = The latest printers with firmware version 2.68 up to 2.168 16 | * thermal_printer_264 = Printers with firmware version 2.64 up to 2.68. 17 | * thermal_printer_legacy = Printers with firmware version before 2.64. 18 | 19 | * Author(s): Tony DiCola 20 | """ 21 | from micropython import const 22 | 23 | from adafruit_thermal_printer import thermal_printer 24 | 25 | try: 26 | import typing # pylint: disable=unused-import 27 | from busio import UART 28 | except ImportError: 29 | pass 30 | 31 | __version__ = "0.0.0+auto.0" 32 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer.git" 33 | 34 | 35 | # Internally used constants. 36 | _INVERSE_MASK = const(1 << 1) # Not in 2.6.8 firmware 37 | 38 | 39 | # Legacy behavior class for printers with firmware 2.64 up to 2.68. 40 | # See the comments in thermal_printer.py to understand how this class overrides 41 | # methods which change for older firmware printers! 42 | class ThermalPrinter(thermal_printer.ThermalPrinter): 43 | """Thermal printer for printers with firmware version 2.64 up to (but 44 | NOT including) 2.68. 45 | """ 46 | 47 | # Barcode types. These vary based on the firmware version so are made 48 | # as class-level variables that users can reference (i.e. 49 | # ThermalPrinter.UPC_A, etc) and write code that is independent of the 50 | # printer firmware version. 51 | UPC_A = 65 52 | UPC_E = 66 53 | EAN13 = 67 54 | EAN8 = 68 55 | CODE39 = 69 56 | ITF = 70 57 | CODABAR = 71 58 | CODE93 = 72 59 | CODE128 = 73 60 | 61 | def __init__( 62 | self, 63 | uart: UART, 64 | byte_delay_s: float = 0.00057346, 65 | dot_feed_s: float = 0.0021, 66 | dot_print_s: float = 0.03, 67 | ) -> None: 68 | """Thermal printer class. Requires a serial UART connection with at 69 | least the TX pin connected. Take care connecting RX as the printer 70 | will output a 5V signal which can damage boards! If RX is unconnected 71 | the only loss in functionality is the has_paper function, all other 72 | printer functions will continue to work. The byte_delay_s, dot_feed_s, 73 | and dot_print_s values are delays which are used to prevent overloading 74 | the printer with data. Use the default delays unless you fully 75 | understand the workings of the printer and how delays, baud rate, 76 | number of dots, heat time, etc. relate to each other. 77 | """ 78 | super().__init__( 79 | uart, 80 | byte_delay_s=byte_delay_s, 81 | dot_feed_s=dot_feed_s, 82 | dot_print_s=dot_print_s, 83 | ) 84 | 85 | # Inverse on older printers (pre 2.68) uses a print mode bit instead of 86 | # specific commands. 87 | inverse = thermal_printer.ThermalPrinter._PrintModeBit(_INVERSE_MASK) 88 | -------------------------------------------------------------------------------- /adafruit_thermal_printer/thermal_printer_legacy.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_thermal_printer.thermal_printer_legacy.ThermalPrinter` 7 | ================================================================= 8 | 9 | Thermal printer control module built to work with small serial thermal 10 | receipt printers. Note that these printers have many different firmware 11 | versions and care must be taken to select the appropriate module inside this 12 | package for your firmware printer: 13 | 14 | * thermal_printer_2168 = Printers with firmware version 2.168+. 15 | * thermal_printer = The latest printers with firmware version 2.68 up to 2.168 16 | * thermal_printer_264 = Printers with firmware version 2.64 up to 2.68. 17 | * thermal_printer_legacy = Printers with firmware version before 2.64. 18 | 19 | * Author(s): Tony DiCola 20 | """ 21 | from micropython import const 22 | 23 | from adafruit_thermal_printer import thermal_printer 24 | 25 | try: 26 | import typing # pylint: disable=unused-import 27 | from busio import UART 28 | except ImportError: 29 | pass 30 | 31 | __version__ = "0.0.0+auto.0" 32 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer.git" 33 | 34 | 35 | # Internally used constants. 36 | _INVERSE_MASK = const(1 << 1) # Not in 2.6.8 firmware 37 | 38 | 39 | # Legacy behavior class for printers with firmware before 2.64. 40 | # See the comments in thermal_printer.py to understand how this class overrides 41 | # methods which change for older firmware printers! 42 | class ThermalPrinter(thermal_printer.ThermalPrinter): 43 | """Thermal printer for printers with firmware version before 2.64.""" 44 | 45 | # Barcode types. These vary based on the firmware version so are made 46 | # as class-level variables that users can reference (i.e. 47 | # ThermalPrinter.UPC_A, etc) and write code that is independent of the 48 | # printer firmware version. 49 | UPC_A = 0 50 | UPC_E = 1 51 | EAN13 = 2 52 | EAN8 = 3 53 | CODE39 = 4 54 | I25 = 5 55 | CODEBAR = 6 56 | CODE93 = 7 57 | CODE128 = 8 58 | CODE11 = 9 59 | MSI = 10 60 | 61 | def __init__( 62 | self, 63 | uart: UART, 64 | byte_delay_s: float = 0.00057346, 65 | dot_feed_s: float = 0.0021, 66 | dot_print_s: float = 0.03, 67 | ) -> None: 68 | """Thermal printer class. Requires a serial UART connection with at 69 | least the TX pin connected. Take care connecting RX as the printer 70 | will output a 5V signal which can damage boards! If RX is unconnected 71 | the only loss in functionality is the has_paper function, all other 72 | printer functions will continue to work. The byte_delay_s, dot_feed_s, 73 | and dot_print_s values are delays which are used to prevent overloading 74 | the printer with data. Use the default delays unless you fully 75 | understand the workings of the printer and how delays, baud rate, 76 | number of dots, heat time, etc. relate to each other. 77 | """ 78 | super().__init__( 79 | uart, 80 | byte_delay_s=byte_delay_s, 81 | dot_feed_s=dot_feed_s, 82 | dot_print_s=dot_print_s, 83 | ) 84 | 85 | def print_barcode(self, text: str, barcode_type: int) -> None: 86 | """Print a barcode with the specified text/number (the meaning 87 | varies based on the type of barcode) and type. Type is a value from 88 | the datasheet or class-level variables like UPC_A, etc. for 89 | convenience. Note the type value changes depending on the firmware 90 | version so use class-level values where possible! 91 | """ 92 | assert 0 <= barcode_type <= 255 93 | assert 0 <= len(text) <= 255 94 | self.feed(1) # Recent firmware can't print barcode w/o feed first??? 95 | self.send_command("\x1DH\x02") # Print label below barcode 96 | self.send_command("\x1Dw\x03") # Barcode width 3 (0.375/1.0mm thin/thick) 97 | self.send_command(f"\x1Dk{chr(barcode_type)}") # Barcode type 98 | # Pre-2.64 firmware prints the text and then a null character to end. 99 | # Instead of the length of text as a prefix. 100 | self.send_command(text) 101 | self.send_command("\x00") 102 | self._set_timeout((self._barcode_height + 40) * self._dot_print_s) 103 | self._column = 0 104 | 105 | def reset(self) -> None: 106 | """Reset the printer.""" 107 | # Issue a reset command to the printer. (ESC + @) 108 | self.send_command("\x1B@") 109 | # Reset internal state: 110 | self._column = 0 111 | self._max_column = 32 112 | self._char_height = 24 113 | self._line_spacing = 6 114 | self._barcode_height = 50 115 | # Skip tab configuration on older printers. 116 | 117 | def feed(self, lines: int) -> None: 118 | """Advance paper by specified number of blank lines.""" 119 | # Just send line feeds for older printers. 120 | for _ in range(lines): 121 | self._write_char("\n") 122 | 123 | def has_paper(self) -> bool: 124 | """Return a boolean indicating if the printer has paper. You MUST have 125 | the serial RX line hooked up for this to work. 126 | 127 | .. note:: 128 | 129 | be VERY CAREFUL to ensure your board can handle a 5V serial 130 | input before hooking up the RX line! 131 | 132 | """ 133 | # The paper check command is different for older firmware: 134 | self.send_command("\x1Br\x00") # ESC + 'r' + 0 135 | status = self._uart.read(1) 136 | if status is None: 137 | return False 138 | return not status[0] & 0b00000100 139 | 140 | # Inverse on older printers (pre 2.68) uses a print mode bit instead of 141 | # specific commands. 142 | inverse = thermal_printer.ThermalPrinter._PrintModeBit(_INVERSE_MASK) 143 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Thermal_Printer/81e7ff54d7eebf08e3d93e3e2e6f729e76445918/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/favicon.ico.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries 2 | 3 | SPDX-License-Identifier: CC-BY-4.0 4 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | .. automodule:: adafruit_thermal_printer.thermal_printer 5 | :members: 6 | 7 | .. automodule:: adafruit_thermal_printer.thermal_printer_264 8 | :members: 9 | 10 | .. automodule:: adafruit_thermal_printer.thermal_printer_legacy 11 | :members: 12 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 4 | # 5 | # SPDX-License-Identifier: MIT 6 | 7 | import os 8 | import sys 9 | import datetime 10 | 11 | sys.path.insert(0, os.path.abspath("..")) 12 | 13 | # -- General configuration ------------------------------------------------ 14 | 15 | # Add any Sphinx extension module names here, as strings. They can be 16 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 17 | # ones. 18 | extensions = [ 19 | "sphinx.ext.autodoc", 20 | "sphinx.ext.intersphinx", 21 | "sphinx.ext.viewcode", 22 | ] 23 | 24 | # Uncomment the below if you use native CircuitPython modules such as 25 | # digitalio, micropython and busio. List the modules you use. Without it, the 26 | # autodoc module docs will fail to generate with a warning. 27 | # autodoc_mock_imports = ["micropython"]#, "adafruit_thermal_printer"] 28 | 29 | intersphinx_mapping = { 30 | "python": ("https://docs.python.org/3", None), 31 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 32 | } 33 | 34 | # Add any paths that contain templates here, relative to this directory. 35 | templates_path = ["_templates"] 36 | 37 | source_suffix = ".rst" 38 | 39 | # The master toctree document. 40 | master_doc = "index" 41 | 42 | # General information about the project. 43 | project = "Adafruit Thermal Printer Library" 44 | creation_year = "2017" 45 | current_year = str(datetime.datetime.now().year) 46 | year_duration = ( 47 | current_year 48 | if current_year == creation_year 49 | else creation_year + " - " + current_year 50 | ) 51 | copyright = year_duration + " Tony DiCola" 52 | author = "Tony DiCola" 53 | 54 | # The version info for the project you're documenting, acts as replacement for 55 | # |version| and |release|, also used in various other places throughout the 56 | # built documents. 57 | # 58 | # The short X.Y version. 59 | version = "1.0" 60 | # The full version, including alpha/beta/rc tags. 61 | release = "1.0" 62 | 63 | # The language for content autogenerated by Sphinx. Refer to documentation 64 | # for a list of supported languages. 65 | # 66 | # This is also used if you do content translation via gettext catalogs. 67 | # Usually you set "language" from the command line for these cases. 68 | language = "en" 69 | 70 | # List of patterns, relative to source directory, that match files and 71 | # directories to ignore when looking for source files. 72 | # This patterns also effect to html_static_path and html_extra_path 73 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 74 | 75 | # The reST default role (used for this markup: `text`) to use for all 76 | # documents. 77 | # 78 | default_role = "any" 79 | 80 | # If true, '()' will be appended to :func: etc. cross-reference text. 81 | # 82 | add_function_parentheses = True 83 | 84 | # The name of the Pygments (syntax highlighting) style to use. 85 | pygments_style = "sphinx" 86 | 87 | # If true, `todo` and `todoList` produce output, else they produce nothing. 88 | todo_include_todos = False 89 | 90 | # If this is True, todo emits a warning for each TODO entries. The default is False. 91 | todo_emit_warnings = True 92 | 93 | 94 | # -- Options for HTML output ---------------------------------------------- 95 | 96 | # The theme to use for HTML and HTML Help pages. See the documentation for 97 | # a list of builtin themes. 98 | # 99 | on_rtd = os.environ.get("READTHEDOCS", None) == "True" 100 | 101 | if not on_rtd: # only import and set the theme if we're building docs locally 102 | try: 103 | import sphinx_rtd_theme 104 | 105 | html_theme = "sphinx_rtd_theme" 106 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] 107 | except: 108 | html_theme = "default" 109 | html_theme_path = ["."] 110 | else: 111 | html_theme_path = ["."] 112 | 113 | # Add any paths that contain custom static files (such as style sheets) here, 114 | # relative to this directory. They are copied after the builtin static files, 115 | # so a file named "default.css" will overwrite the builtin "default.css". 116 | html_static_path = ["_static"] 117 | 118 | # The name of an image file (relative to this directory) to use as a favicon of 119 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 120 | # pixels large. 121 | # 122 | html_favicon = "_static/favicon.ico" 123 | 124 | # Output file base name for HTML help builder. 125 | htmlhelp_basename = "AdafruitThermalPrinterLibrarydoc" 126 | 127 | # -- Options for LaTeX output --------------------------------------------- 128 | 129 | latex_elements = { 130 | # The paper size ('letterpaper' or 'a4paper'). 131 | # 132 | # 'papersize': 'letterpaper', 133 | # The font size ('10pt', '11pt' or '12pt'). 134 | # 135 | # 'pointsize': '10pt', 136 | # Additional stuff for the LaTeX preamble. 137 | # 138 | # 'preamble': '', 139 | # Latex figure (float) alignment 140 | # 141 | # 'figure_align': 'htbp', 142 | } 143 | 144 | # Grouping the document tree into LaTeX files. List of tuples 145 | # (source start file, target name, title, 146 | # author, documentclass [howto, manual, or own class]). 147 | latex_documents = [ 148 | ( 149 | master_doc, 150 | "AdafruitThermalPrinterLibrary.tex", 151 | "Adafruit Thermal Printer Library Documentation", 152 | author, 153 | "manual", 154 | ), 155 | ] 156 | 157 | # -- Options for manual page output --------------------------------------- 158 | 159 | # One entry per manual page. List of tuples 160 | # (source start file, name, description, authors, manual section). 161 | man_pages = [ 162 | ( 163 | master_doc, 164 | "AdafruitThermalPrinterlibrary", 165 | "Adafruit Thermal Printer Library Documentation", 166 | [author], 167 | 1, 168 | ) 169 | ] 170 | 171 | # -- Options for Texinfo output ------------------------------------------- 172 | 173 | # Grouping the document tree into Texinfo files. List of tuples 174 | # (source start file, target name, title, author, 175 | # dir menu entry, description, category) 176 | texinfo_documents = [ 177 | ( 178 | master_doc, 179 | "AdafruitThermalPrinterLibrary", 180 | "Adafruit Thermal Printer Library Documentation", 181 | author, 182 | "AdafruitThermalPrinterLibrary", 183 | "One line description of project.", 184 | "Miscellaneous", 185 | ), 186 | ] 187 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/thermal_printer_simpletest.py 7 | :caption: examples/thermal_printer_simpletest.py 8 | :linenos: 9 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | .. toctree:: 27 | :caption: Related Products 28 | 29 | Mini Thermal Receipt Printer 30 | 31 | .. toctree:: 32 | :caption: Other Links 33 | 34 | Download from GitHub 35 | Download Library Bundle 36 | CircuitPython Reference Documentation 37 | CircuitPython Support Forum 38 | Discord Chat 39 | Adafruit Learning System 40 | Adafruit Blog 41 | Adafruit Store 42 | 43 | Indices and tables 44 | ================== 45 | 46 | * :ref:`genindex` 47 | * :ref:`modindex` 48 | * :ref:`search` 49 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | sphinx>=4.0.0 6 | -------------------------------------------------------------------------------- /examples/thermal_printer_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Simple demo of printer functionality. 5 | # Author: Tony DiCola 6 | import board 7 | import busio 8 | 9 | import adafruit_thermal_printer 10 | 11 | # Pick which version thermal printer class to use depending on the version of 12 | # your printer. Hold the button on the printer as it's powered on and it will 13 | # print a test page that displays the firmware version, like 2.64, 2.68, etc. 14 | # Use this version in the get_printer_class function below. 15 | ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69) 16 | 17 | # Define RX and TX pins for the board's serial port connected to the printer. 18 | # Only the TX pin needs to be configued, and note to take care NOT to connect 19 | # the RX pin if your board doesn't support 5V inputs. If RX is left unconnected 20 | # the only loss in functionality is checking if the printer has paper--all other 21 | # functions of the printer will work. 22 | RX = board.RX 23 | TX = board.TX 24 | 25 | # Create a serial connection for the printer. You must use the same baud rate 26 | # as your printer is configured (print a test page by holding the button 27 | # during power-up and it will show the baud rate). Most printers use 19200. 28 | uart = busio.UART(TX, RX, baudrate=19200) 29 | 30 | # For a computer, use the pyserial library for uart access. 31 | # import serial 32 | # uart = serial.Serial("/dev/serial0", baudrate=19200, timeout=3000) 33 | 34 | # Create the printer instance. 35 | printer = ThermalPrinter(uart, auto_warm_up=False) 36 | 37 | # Initialize the printer. Note this will take a few seconds for the printer 38 | # to warm up and be ready to accept commands (hence calling it explicitly vs. 39 | # automatically in the initializer with the default auto_warm_up=True). 40 | printer.warm_up() 41 | 42 | # Check if the printer has paper. This only works if the RX line is connected 43 | # on your board (but BE CAREFUL as mentioned above this RX line is 5V!) 44 | if printer.has_paper(): 45 | print("Printer has paper!") 46 | else: 47 | print("Printer might be out of paper, or RX is disconnected!") 48 | 49 | # Print a test page: 50 | printer.test_page() 51 | 52 | # Move the paper forward two lines: 53 | printer.feed(2) 54 | 55 | # Print a line of text: 56 | printer.print("Hello world!") 57 | 58 | # Print a bold line of text: 59 | printer.bold = True 60 | printer.print("Bold hello world!") 61 | printer.bold = False 62 | 63 | # Print a normal/thin underline line of text: 64 | printer.underline = adafruit_thermal_printer.UNDERLINE_THIN 65 | printer.print("Thin underline!") 66 | 67 | # Print a thick underline line of text: 68 | printer.underline = adafruit_thermal_printer.UNDERLINE_THICK 69 | printer.print("Thick underline!") 70 | 71 | # Disable underlines. 72 | printer.underline = None 73 | 74 | # Print an inverted line. 75 | printer.inverse = True 76 | printer.print("Inverse hello world!") 77 | printer.inverse = False 78 | 79 | # Print an upside down line. 80 | printer.upside_down = True 81 | printer.print("Upside down hello!") 82 | printer.upside_down = False 83 | 84 | # Print a double height line. 85 | printer.double_height = True 86 | printer.print("Double height!") 87 | printer.double_height = False 88 | 89 | # Print a double width line. 90 | printer.double_width = True 91 | printer.print("Double width!") 92 | printer.double_width = False 93 | 94 | # Print a strike-through line. 95 | printer.strike = True 96 | printer.print("Strike-through hello!") 97 | printer.strike = False 98 | 99 | # Print medium size text. 100 | printer.size = adafruit_thermal_printer.SIZE_MEDIUM 101 | printer.print("Medium size text!") 102 | 103 | # Print large size text. 104 | printer.size = adafruit_thermal_printer.SIZE_LARGE 105 | printer.print("Large size text!") 106 | 107 | # Back to normal / small size text. 108 | printer.size = adafruit_thermal_printer.SIZE_SMALL 109 | 110 | # Print center justified text. 111 | printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER 112 | printer.print("Center justified!") 113 | 114 | # Print right justified text. 115 | printer.justify = adafruit_thermal_printer.JUSTIFY_RIGHT 116 | printer.print("Right justified!") 117 | 118 | # Back to left justified / normal text. 119 | printer.justify = adafruit_thermal_printer.JUSTIFY_LEFT 120 | 121 | # Print a UPC barcode. 122 | printer.print("UPCA barcode:") 123 | printer.print_barcode("123456789012", printer.UPC_A) 124 | 125 | # Feed a few lines to see everything. 126 | printer.feed(2) 127 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-thermal-printer" 14 | description = "CircuitPython library for controlling thermal printers." 15 | version = "0.0.0+auto.0" 16 | readme = "README.rst" 17 | authors = [ 18 | {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} 19 | ] 20 | urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer"} 21 | keywords = [ 22 | "adafruit", 23 | "thermal", 24 | "printer", 25 | "hardware", 26 | "micropython", 27 | "circuitpython", 28 | ] 29 | license = {text = "MIT"} 30 | classifiers = [ 31 | "Intended Audience :: Developers", 32 | "Topic :: Software Development :: Libraries", 33 | "Topic :: Software Development :: Embedded Systems", 34 | "Topic :: System :: Hardware", 35 | "License :: OSI Approved :: MIT License", 36 | "Programming Language :: Python :: 3", 37 | ] 38 | dynamic = ["dependencies", "optional-dependencies"] 39 | 40 | [tool.setuptools] 41 | packages = ["adafruit_thermal_printer"] 42 | 43 | [tool.setuptools.dynamic] 44 | dependencies = {file = ["requirements.txt"]} 45 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 46 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | pyserial 7 | adafruit-circuitpython-typing 8 | typing-extensions~=4.0 9 | --------------------------------------------------------------------------------